diff --git a/.build.ps1 b/.build.ps1 deleted file mode 100644 index 81821d0e8..000000000 --- a/.build.ps1 +++ /dev/null @@ -1,233 +0,0 @@ -param( - [ValidateSet("net451", "netstandard2.0")] - [string]$Framework = "net451", - - [ValidateSet("Debug", "Release", "PSv3Debug", "PSv3Release", "PSv4Release")] - [string]$Configuration = "Debug" -) - -# todo remove aliases -# todo make each project have its own build script - -$outPath = "$BuildRoot/out" -$modulePath = "$outPath/PSScriptAnalyzer" - -$buildData = @{} -if ($BuildTask -eq "release") { - $buildData = @{ - Frameworks = @{ - "net451" = @{ - Configuration = @('Release', "PSV3Release", "PSv4Release") - } - "netstandard2.0" = @{ - Configuration = @('Release') - } - } - } -} -else { - $buildData.Add("Frameworks", @{}) - $buildData["Frameworks"].Add($Framework, @{}) - $buildData["Frameworks"][$Framework].Add("Configuration", $Configuration) -} - -function CreateIfNotExists([string] $folderPath) { - if (-not (Test-Path $folderPath)) { - New-Item -Path $folderPath -ItemType Directory -Verbose:$verbosity - } -} - -function Get-BuildInputs($project) { - Push-Location $buildRoot/$project - Get-ChildItem -Filter *.cs - Get-ChildItem -Directory -Exclude obj, bin | Get-ChildItem -Filter *.cs -Recurse - Pop-Location -} - -function Get-BuildOutputs($project) { - $bin = "$buildRoot/$project/bin/$Configuration/$Framework" - $obj = "$buildRoot/$project/obj/$Configuration/$Framework" - if (Test-Path $bin) { - Get-ChildItem $bin -Recurse - } - if (Test-Path $obj) { - Get-ChildItem $obj -Recurse - } -} - -function Get-BuildTaskParams($project) { - $taskParams = @{ - Data = $buildData - Jobs = { - $d = $($Task.Data) - foreach ($frmwrk in $d.Frameworks.Keys) { - foreach ($config in $d.Frameworks[$frmwrk].Configuration) { - dotnet build --framework $frmwrk --configuration $config - } - } - } - } - - $outputs = (Get-BuildOutputs $project) - if ($null -ne $outputs) { - $inputs = (Get-BuildInputs $project) - $taskParams.Add("Outputs", $outputs) - $taskParams.Add("Inputs", $inputs) - } - - $taskParams -} - -function Get-CleanTaskParams($project) { - @{ - Jobs = { - if (Test-Path obj) { - Remove-Item obj -Force -Recurse - } - - if (Test-Path bin) { - Remove-Item bin -Force -Recurse - } - } - } -} - -function Get-TestTaskParam($project) { - @{ - Jobs = { - Invoke-Pester - } - } -} - -function Add-ProjectTask([string]$project, [string]$taskName, [hashtable]$taskParams, [string]$pathPrefix = $buildRoot) { - $jobs = [scriptblock]::Create(@" -pushd $pathPrefix/$project -$($taskParams.Jobs) -popd -"@) - $taskParams.Jobs = $jobs - $taskParams.Name = "$project/$taskName" - task @taskParams -} - -$projects = @("engine", "rules") -$projects | ForEach-Object { - Add-ProjectTask $_ build (Get-BuildTaskParams $_) - Add-ProjectTask $_ clean (Get-CleanTaskParams $_) - Add-ProjectTask $_ test (Get-TestTaskParam $_) "$BuildRoot/tests" -} - -task build "engine/build", "rules/build" -task clean "engine/clean", "rules/clean" -task test "engine/test", "rules/test" - -task createModule { - Function CopyToDestinationDir($itemsToCopy, $destination) { - CreateIfNotExists($destination) - foreach ($file in $itemsToCopy) { - Copy-Item -Path $file -Destination (Join-Path $destination (Split-Path $file -Leaf)) -Force - } - } - - $solutionDir = $BuildRoot - - $itemsToCopyCommon = @("$solutionDir\Engine\PSScriptAnalyzer.psd1", - "$solutionDir\Engine\PSScriptAnalyzer.psm1", - "$solutionDir\Engine\ScriptAnalyzer.format.ps1xml", - "$solutionDir\Engine\ScriptAnalyzer.types.ps1xml") - - $destinationDir = "$solutionDir\out\PSScriptAnalyzer" - $destinationDirBinaries = $destinationDir - - foreach ($Framework in $buildData.Frameworks.Keys) { - foreach ($Configuration in $buildData.Frameworks[$Framework].Configuration) { - $itemsToCopyBinaries = @("$solutionDir\Engine\bin\$Configuration\$Framework\Microsoft.Windows.PowerShell.ScriptAnalyzer.dll", - "$solutionDir\Rules\bin\$Configuration\$Framework\Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules.dll") - - if ($Framework -eq "netstandard2.0") { - $destinationDirBinaries = "$destinationDir\coreclr" - } - elseif ($Configuration -match 'PSv3') { - $destinationDirBinaries = "$destinationDir\PSv3" - } - else { - $destinationDirBinaries = $destinationDir - } - - CopyToDestinationDir $itemsToCopyBinaries $destinationDirBinaries - - # copy newtonsoft dll if net451 framework - if ($Framework -eq "net451") { - copy-item -path "$solutionDir\Rules\bin\$Configuration\$Framework\Newtonsoft.Json.dll" -Destination $destinationDirBinaries - } - } - } - - CopyToDestinationDir $itemsToCopyCommon $destinationDir - - # Copy Settings File - Copy-Item -Path "$solutionDir\Engine\Settings" -Destination $destinationDir -Force -Recurse -} - -task cleanModule -if (Test-Path $outPath) { - Remove-Item -Path out/ -Recurse -Force -} - - -$docsPath = Join-Path $BuildRoot 'docs' -$outputDocsPath = Join-Path $modulePath 'en-US' -$bdInputs = (Get-ChildItem $docsPath -File -Recurse) -$bdOutputs = @( - "$outputDocsPath/about_PSScriptAnalyzer.help.txt", - "$outputDocsPath/Microsoft.Windows.PowerShell.ScriptAnalyzer.dll-Help.xml" -) - -task buildDocs -Inputs $bdInputs -Outputs $bdOutputs { - # todo move common variables to script scope - $markdownDocsPath = Join-Path $docsPath 'markdown' - CreateIfNotExists($outputDocsPath) - - # Build documentation using platyPS - if ($null -eq (Get-Module platyPS -ListAvailable -Verbose:$verbosity | Where-Object { $_.Version -ge 0.9 })) { - throw "Cannot find platyPS of version greater or equal to 0.9. Please install it from https://www.powershellgallery.com/packages/platyPS/ using e.g. the following command: Install-Module platyPS" - } - Import-Module platyPS - if (-not (Test-Path $markdownDocsPath -Verbose:$verbosity)) { - throw "Cannot find markdown documentation folder." - } - New-ExternalHelp -Path $markdownDocsPath -OutputPath $outputDocsPath -Force -} - -task cleanDocs -if (Test-Path $outputDocsPath) { - Remove-Item -Path $outputDocsPath -Recurse -Force -} - -task newSession { - Start-Process "powershell" -ArgumentList @('-noexit', "-command import-module $modulePath -verbose") -} - -$localPSModulePath = $env:PSMODULEPATH -split ";" | Where-Object {$_.StartsWith($HOME)} -$pssaDestModulePath = '' -if ($null -ne $localPSModulePath -and $localPSModulePath.Count -eq 1) { - $pssaDestModulePath = Join-Path $localPSModulePath 'PSScriptAnalyzer' -} - -function Test-PSSADestModulePath { - ($pssaDestModulePath -ne '') -and (Test-Path $pssaDestModulePath) -} - -task uninstall -if {Test-PSSADestModulePath} { - Remove-Item -Force -Recurse $pssaDestModulePath -} - -task install -if {Test-Path $modulePath} uninstall, { - Copy-Item ` - -Recurse ` - -Path $modulePath ` - -Destination $pssaDestModulePath -} - -# TODO fix building psv3 -task release cleanModule, clean, build, createModule, buildDocs -task . build, createModule, newSession diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 000000000..0f6388008 --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,8 @@ +{ + // See http://go.microsoft.com/fwlink/?LinkId=827846 + // for the documentation about the extensions.json format + "recommendations": [ + "ms-vscode.PowerShell", + "ms-vscode.csharp" + ] +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index a97addede..668011096 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,5 +1,8 @@ // Place your settings in this file to overwrite default and user settings. { "editor.tabSize": 4, - "powershell.codeFormatting.preset": "Allman" -} + "powershell.codeFormatting.preset": "Allman", + "[powershell]": { + "files.trimTrailingWhitespace": true + } +} \ No newline at end of file diff --git a/Utils/RuleMaker.psm1 b/Utils/RuleMaker.psm1 index b46d89bf0..c3cad6622 100644 --- a/Utils/RuleMaker.psm1 +++ b/Utils/RuleMaker.psm1 @@ -33,7 +33,7 @@ Function Get-SolutionRoot Function Get-RuleProjectRoot { $slnRoot = Get-SolutionRoot - if ($slnRoot -eq $null) + if ($null -eq $slnRoot) { return $null } @@ -43,7 +43,7 @@ Function Get-RuleProjectRoot Function Get-RuleProjectFile { $prjRoot = Get-RuleProjectRoot - if ($prjRoot -eq $null) + if ($null -eq $prjRoot) { return $null } diff --git a/appveyor.yml b/appveyor.yml index 37beddc7e..850d5b413 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -16,7 +16,6 @@ environment: # cache Nuget packages and dotnet CLI cache cache: - '%USERPROFILE%\.nuget\packages -> appveyor.yml' - - '%LocalAppData%\Microsoft\dotnet -> appveyor.yml' install: - ps: if ($env:PowerShellEdition -eq 'WindowsPowerShell') { Import-Module .\tools\appveyor.psm1; Invoke-AppveyorInstall } diff --git a/build.cmd b/build.cmd deleted file mode 100644 index 8b73e3e3e..000000000 --- a/build.cmd +++ /dev/null @@ -1,27 +0,0 @@ -@echo off -setlocal -if "%VS140COMNTOOLS%"=="" GOTO VS12TOOLS -call "%VS140COMNTOOLS%\VsDevCmd.bat" -GOTO BUILD - -:VS12TOOLS -if "%VS120COMNTOOLS%"=="" GOTO NOTOOLS -call "%VS120COMNTOOLS%\VsDevCmd.bat" - -:BUILD -set solutionPath=%1 -set configuration=%2 -set target=%3 -if "%target%" == "clean" GOTO CLEAN -msbuild %solutionPath% /p:Configuration=%configuration% /l:FileLogger,Microsoft.Build.Engine;logfile=PSScriptAnalyzer_Build.log;append=true -GOTO END - -:CLEAN -msbuild .\PSScriptAnalyzer.sln /p:Configuration=%configuration% /t:clean /l:FileLogger,Microsoft.Build.Engine;logfile=PSScriptAnalyzer_Build.log;append=true -GOTO END - -:NOTOOLS -echo The Visual Studio 2013/2015 tools are not installed - -:END -endlocal \ No newline at end of file diff --git a/build.ps1 b/build.ps1 index 46aa3a9c6..89dcbcf11 100644 --- a/build.ps1 +++ b/build.ps1 @@ -1,3 +1,4 @@ +# This function might be a partially out of date and only the -BuildDoc switch is guaranteed to work since it is used and needed for the build process. [CmdletBinding()] param( @@ -5,12 +6,6 @@ param( [ValidateSet('PSV3 Debug','PSV3 Release','Debug','Release')] [string] $Configuration = 'Debug', - [Parameter(ParameterSetName='Build')] - [switch] $BuildSolution = $false, - - [Parameter(ParameterSetName='Build')] - [switch] $CleanSolution = $false, - [Parameter(ParameterSetName='Build')] [switch] $BuildDocs = $false, @@ -63,27 +58,11 @@ if (-not (Test-Path $solutionPath)) throw $errMsg } -$buildCmd = Join-Path $projectRoot "build.cmd" -if (-not (Test-Path $buildCmd)) -{ - throw "cannot find build.cmd" -} - if ($CleanOutput) { Remove-Item -Recurse $outPath\* -Force -Verbose:$verbosity } -if ($CleanSolution) -{ - & $buildCmd $solutionPath $Configuration 'clean' -} - -if ($BuildSolution) -{ - & $buildCmd $solutionPath $Configuration -} - if ($BuildDocs) { $docsPath = Join-Path $projectRoot 'docs' @@ -98,7 +77,7 @@ if ($BuildDocs) { "Cannot find required minimum version $requiredVersionOfplatyPS of platyPS. Please install it from https://www.powershellgallery.com/packages/platyPS/ using e.g. the following command: Install-Module platyPS" } - if ((Get-Module platyPS -Verbose:$verbosity) -eq $null) + if ($null -eq (Get-Module platyPS -Verbose:$verbosity)) { Import-Module platyPS -Verbose:$verbosity } @@ -111,7 +90,7 @@ if ($BuildDocs) # Appveyor errors out due to $profile being null. Hence... $moduleRootPath = "$HOME/Documents/WindowsPowerShell/Modules" -if ($profile -ne $null) +if ($null -ne $profile) { $moduleRootPath = Join-Path (Split-Path $profile) 'Modules' } diff --git a/buildCoreClr.ps1 b/buildCoreClr.ps1 index b8878299e..4a72331ef 100644 --- a/buildCoreClr.ps1 +++ b/buildCoreClr.ps1 @@ -10,7 +10,7 @@ [string]$Configuration = "Debug" ) -if ($Configuration -match "PSv3" -and $Framework -eq "netstandard2.0") +if ($Configuration -match "PSv" -and $Framework -eq "netstandard2.0") { throw ("{0} configuration is not applicable to {1} framework" -f $Configuration,$Framework) } @@ -45,13 +45,8 @@ elseif ($Configuration -match 'PSv4') { if ($build) { - - Write-Progress "Building Engine" - Push-Location Engine\ - dotnet build Engine.csproj --framework $Framework --configuration $Configuration - Pop-Location - Write-Progress "Building for framework $Framework, configuration $Configuration" + # The Rules project has a dependency on the Engine therefore just building the Rules project is enough Push-Location Rules\ dotnet build Rules.csproj --framework $Framework --configuration $Configuration Pop-Location diff --git a/tools/appveyor.psm1 b/tools/appveyor.psm1 index 0625dea33..08cd4b31c 100644 --- a/tools/appveyor.psm1 +++ b/tools/appveyor.psm1 @@ -42,7 +42,7 @@ function Invoke-AppVeyorBuild { [Parameter(Mandatory)] [ValidateSet('FullCLR', 'NetStandard')] $BuildType, - + [Parameter(Mandatory)] [ValidateSet('Release', 'PSv3Release', 'PSv4Release')] $BuildConfiguration, @@ -51,7 +51,7 @@ function Invoke-AppVeyorBuild { [ValidateScript( {Test-Path $_})] $CheckoutPath ) - + $PSVersionTable Write-Verbose "Pester version: $((Get-Command Invoke-Pester).Version)" -Verbose Write-Verbose ".NET SDK version: $(dotnet --version)" -Verbose diff --git a/tools/releaseBuild/vstsbuild.ps1 b/tools/releaseBuild/vstsbuild.ps1 index f7fa8b49b..2afd3fd23 100644 --- a/tools/releaseBuild/vstsbuild.ps1 +++ b/tools/releaseBuild/vstsbuild.ps1 @@ -58,9 +58,9 @@ End { ReleaseTag = $ReleaseTag } $buildArgs = @{ - RepoPath = $resolvedRepoRoot - BuildJsonPath = './tools/releaseBuild/build.json' - Parameters = $buildParameters + RepoPath = $resolvedRepoRoot + BuildJsonPath = './tools/releaseBuild/build.json' + Parameters = $buildParameters AdditionalFiles = $AdditionalFiles Name = "win7-x64" }