Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Revert "remove .build.ps1 and various cleanup"
This reverts commit 0378f8d.
  • Loading branch information
bergmeister committed Jun 3, 2018
commit fd0350f060d51138b4ab50ce4285b174a984d621
233 changes: 233 additions & 0 deletions .build.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,233 @@
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
7 changes: 2 additions & 5 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
// Place your settings in this file to overwrite default and user settings.
{
"editor.tabSize": 4,
"powershell.codeFormatting.preset": "Allman",
"[powershell]": {
"files.trimTrailingWhitespace": true
}
}
"powershell.codeFormatting.preset": "Allman"
}
6 changes: 3 additions & 3 deletions build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
param(

[Parameter(ParameterSetName='Build')]
[ValidateSet('PSV3 Debug','PSV3 Release', 'Debug','Release')]
[ValidateSet('PSV3 Debug','PSV3 Release','Debug','Release')]
[string] $Configuration = 'Debug',

[Parameter(ParameterSetName='Build')]
Expand Down Expand Up @@ -77,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 ($null -eq (Get-Module platyPS -Verbose:$verbosity))
if ((Get-Module platyPS -Verbose:$verbosity) -eq $null)
{
Import-Module platyPS -Verbose:$verbosity
}
Expand All @@ -90,7 +90,7 @@ if ($BuildDocs)

# Appveyor errors out due to $profile being null. Hence...
$moduleRootPath = "$HOME/Documents/WindowsPowerShell/Modules"
if ($null -eq $profile)
if ($profile -ne $null)
{
$moduleRootPath = Join-Path (Split-Path $profile) 'Modules'
}
Expand Down
8 changes: 7 additions & 1 deletion buildCoreClr.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
[string]$Configuration = "Debug"
)

if ($Configuration -match "PSv" -and $Framework -eq "netstandard2.0")
if ($Configuration -match "PSv3" -and $Framework -eq "netstandard2.0")
{
throw ("{0} configuration is not applicable to {1} framework" -f $Configuration,$Framework)
}
Expand Down Expand Up @@ -45,6 +45,12 @@ 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"
Push-Location Rules\
dotnet build Rules.csproj --framework $Framework --configuration $Configuration
Expand Down
4 changes: 2 additions & 2 deletions tools/appveyor.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function Invoke-AppVeyorBuild {
[Parameter(Mandatory)]
[ValidateSet('FullCLR', 'NetStandard')]
$BuildType,

[Parameter(Mandatory)]
[ValidateSet('Release', 'PSv3Release', 'PSv4Release')]
$BuildConfiguration,
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions tools/releaseBuild/vstsbuild.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down