From e4c2cc8d2b6c17aa45e0e36b66d99ba1f70dc358 Mon Sep 17 00:00:00 2001 From: Tyler Leonhardt Date: Thu, 8 Feb 2018 15:40:56 -0800 Subject: [PATCH 1/5] WIP: first build.ps1 --- build.ps1 | 96 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 build.ps1 diff --git a/build.ps1 b/build.ps1 new file mode 100644 index 000000000..d121fe50d --- /dev/null +++ b/build.ps1 @@ -0,0 +1,96 @@ +#!/usr/bin/env pwsh +param( + [Parameter()] + [switch] + $Clean, + + [Parameter()] + [switch] + $BootstrapBuildEnv +) + +$NeededTools = @{ + OpenSsl = "openssl for macOS" + DotNet451TargetingPack = ".NET 4.5.1 Targeting Pack" + PowerShellGet = "PowerShellGet latest" + InvokeBuild = "InvokeBuild latest" +} + +if ((-not $PSVersionTable["OS"]) -or $PSVersionTable["OS"].Contains("Windows")) { + $OS = "Windows" +} elseif ($PSVersionTable["OS"].Contains("Darwin")) { + $OS = "macOS" +} else { + $OS = "Linux" +} + + +function needsOpenSsl () { + if ($OS -eq "macOS") { + try { + $opensslVersion = (openssl version) + } catch { + return $true + } + } + return $false +} + +function needsDotNet451TargetingPack () { + # how could we check for this? + return $false +} + +function needsPowerShellGet () { + if (Get-Module -ListAvailable -Name PowerShellGet) { + return $false + } + return $true +} + +function needsInvokeBuild () { + if (Get-Module -ListAvailable -Name InvokeBuild) { + return $false + } + return $true +} + +function getMissingTools () { + $missingTools = @() + + if (needsOpenSsl) { + $missingTools += $NeededTools.OpenSsl + } + if (needsDotNet451TargetingPack) { + $missingTools += $NeededTools.DotNet451TargetingPack + } + if (needsPowerShellGet) { + $missingTools += $NeededTools.PowerShellGet + } + if (needsInvokeBuild) { + $missingTools += $NeededTools.InvokeBuild + } + + return $missingTools +} + +function hasMissingTools () { + return ((getMissingTools).Count -gt 0) +} + +if ($BootstrapBuildEnv) { + $string = "Here is what your environment is missing:`n" + $missingTools = getMissingTools + if (($missingTools).Count -eq 0) { + $string += "* nothing!`n`n Run this script without a flag to build or a -Clean to clean." + } else { + $missingTools | ForEach-Object {$string += "* $_`n"} + $string += "`nAll instructions for installing these tools can be found on PowerShell Editor Services' Github:`n" ` + + "https://github.com/powershell/PowerShellEditorServices#development" + } + Write-Host "`n$string`n" +} elseif ($Clean) { + Invoke-Build Clean +} else { + Invoke-Build Build +} \ No newline at end of file From d7cce948936c55a1e4f9518472c5a6b176fc8f46 Mon Sep 17 00:00:00 2001 From: Tyler Leonhardt Date: Thu, 8 Feb 2018 15:45:27 -0800 Subject: [PATCH 2/5] check for missing tools --- build.ps1 | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/build.ps1 b/build.ps1 index d121fe50d..b6887bc9b 100644 --- a/build.ps1 +++ b/build.ps1 @@ -90,7 +90,15 @@ if ($BootstrapBuildEnv) { } Write-Host "`n$string`n" } elseif ($Clean) { - Invoke-Build Clean + if(hasMissingTools) { + Write-Host "You are missing needed tools. Run './build.ps1 -BootstrapBuildEnv' to see what they are." + } else { + Invoke-Build Clean + } } else { - Invoke-Build Build + if(hasMissingTools) { + Write-Host "You are missing needed tools. Run './build.ps1 -BootstrapBuildEnv' to see what they are." + } else { + Invoke-Build Build + } } \ No newline at end of file From bac6880ca6049939e7f2447529c31d3a66954716 Mon Sep 17 00:00:00 2001 From: Tyler Leonhardt Date: Fri, 9 Feb 2018 07:48:43 -0800 Subject: [PATCH 3/5] add test for targeting pack --- build.ps1 | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/build.ps1 b/build.ps1 index b6887bc9b..948fc2c49 100644 --- a/build.ps1 +++ b/build.ps1 @@ -37,7 +37,14 @@ function needsOpenSsl () { } function needsDotNet451TargetingPack () { - # how could we check for this? + if($BootstrapBuildEnv -and ($OS -eq "Windows")) { + $hasNet451TargetingPack = Get-CimInstance Win32_Product | Where-Object Name -match '\.NET Framework 4\.5\.1 Multi-Targeting Pack' + if(-not $hasNet451TargetingPack) { + return $true + } + } elseif($OS -eq "Windows") { + Write-Host "[Bootstrap] Did not check if the .NET 4.5.1 Targeting Pack is present. To check, run 'build.ps1 -BootstrapBuildEnv'" + } return $false } From 756efc269f94c833630408a4ae00dda5d9e0afb9 Mon Sep 17 00:00:00 2001 From: Tyler Leonhardt Date: Fri, 9 Feb 2018 10:17:18 -0800 Subject: [PATCH 4/5] remove .NET targeting pack --- build.ps1 | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/build.ps1 b/build.ps1 index 948fc2c49..86b4c0216 100644 --- a/build.ps1 +++ b/build.ps1 @@ -11,7 +11,6 @@ param( $NeededTools = @{ OpenSsl = "openssl for macOS" - DotNet451TargetingPack = ".NET 4.5.1 Targeting Pack" PowerShellGet = "PowerShellGet latest" InvokeBuild = "InvokeBuild latest" } @@ -36,18 +35,6 @@ function needsOpenSsl () { return $false } -function needsDotNet451TargetingPack () { - if($BootstrapBuildEnv -and ($OS -eq "Windows")) { - $hasNet451TargetingPack = Get-CimInstance Win32_Product | Where-Object Name -match '\.NET Framework 4\.5\.1 Multi-Targeting Pack' - if(-not $hasNet451TargetingPack) { - return $true - } - } elseif($OS -eq "Windows") { - Write-Host "[Bootstrap] Did not check if the .NET 4.5.1 Targeting Pack is present. To check, run 'build.ps1 -BootstrapBuildEnv'" - } - return $false -} - function needsPowerShellGet () { if (Get-Module -ListAvailable -Name PowerShellGet) { return $false @@ -68,9 +55,6 @@ function getMissingTools () { if (needsOpenSsl) { $missingTools += $NeededTools.OpenSsl } - if (needsDotNet451TargetingPack) { - $missingTools += $NeededTools.DotNet451TargetingPack - } if (needsPowerShellGet) { $missingTools += $NeededTools.PowerShellGet } From 57d02288de12138854534e42c46fab02f388533b Mon Sep 17 00:00:00 2001 From: Tyler Leonhardt Date: Fri, 9 Feb 2018 11:55:04 -0800 Subject: [PATCH 5/5] change Clean logic and added Test --- build.ps1 | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/build.ps1 b/build.ps1 index 86b4c0216..ab2340845 100644 --- a/build.ps1 +++ b/build.ps1 @@ -1,12 +1,16 @@ #!/usr/bin/env pwsh param( + [Parameter()] + [switch] + $Bootstrap, + [Parameter()] [switch] $Clean, [Parameter()] [switch] - $BootstrapBuildEnv + $Test ) $NeededTools = @{ @@ -69,7 +73,7 @@ function hasMissingTools () { return ((getMissingTools).Count -gt 0) } -if ($BootstrapBuildEnv) { +if ($Bootstrap) { $string = "Here is what your environment is missing:`n" $missingTools = getMissingTools if (($missingTools).Count -eq 0) { @@ -80,16 +84,16 @@ if ($BootstrapBuildEnv) { + "https://github.com/powershell/PowerShellEditorServices#development" } Write-Host "`n$string`n" -} elseif ($Clean) { - if(hasMissingTools) { - Write-Host "You are missing needed tools. Run './build.ps1 -BootstrapBuildEnv' to see what they are." - } else { +} elseif(hasMissingTools) { + Write-Host "You are missing needed tools. Run './build.ps1 -Bootstrap' to see what they are." +} else { + if($Clean) { Invoke-Build Clean } -} else { - if(hasMissingTools) { - Write-Host "You are missing needed tools. Run './build.ps1 -BootstrapBuildEnv' to see what they are." - } else { - Invoke-Build Build + + Invoke-Build Build + + if($Test) { + Invoke-Build Test } } \ No newline at end of file