From d490def51b0056fa5d6121ba8593b5c0e78687f9 Mon Sep 17 00:00:00 2001 From: Karol Kaczmarek Date: Thu, 21 Jul 2016 11:07:45 -0700 Subject: [PATCH 1/7] Fixing mc.exe detection --- build.psm1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.psm1 b/build.psm1 index dc356337c..85e66f5ef 100644 --- a/build.psm1 +++ b/build.psm1 @@ -119,9 +119,9 @@ function Start-PSBuild { Use-MSBuild #mc.exe is Message Compiler for native resources - $mcexe = Get-ChildItem "${env:ProgramFiles(x86)}\Microsoft SDKs\Windows\" -Recurse -Filter 'mc.exe' | ? {$_.FullName -match 'x64'} | select -First 1 | % {$_.FullName} + $mcexe = Get-ChildItem "${env:ProgramFiles(x86)}\Windows Kits\10\" -Recurse -Filter 'mc.exe' | ? {$_.FullName -match 'x64'} | select -First 1 | % {$_.FullName} if (-not $mcexe) { - throw 'mc.exe not found. Install Microsoft Windows SDK.' + throw 'mc.exe not found. Install Microsoft Windows 10 SDK from https://developer.microsoft.com/en-US/windows/downloads/windows-10-sdk' } $vcVarsPath = (Get-Item(Join-Path -Path "$env:VS140COMNTOOLS" -ChildPath '../../vc')).FullName From 6a989e86a970abb5a4e1397b12433305fe855860 Mon Sep 17 00:00:00 2001 From: Karol Kaczmarek Date: Thu, 21 Jul 2016 15:33:16 -0700 Subject: [PATCH 2/7] Installing chocolatey and updating machine path --- build.psm1 | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/build.psm1 b/build.psm1 index 85e66f5ef..c8f753434 100644 --- a/build.psm1 +++ b/build.psm1 @@ -589,6 +589,31 @@ function Start-PSBootstrap { $installScript = "dotnet-install.ps1" Invoke-WebRequest -Uri $obtainUrl/$installScript -OutFile $installScript & ./$installScript -c $Channel -v $Version + + # Install chocolatey + $machinePath = [Environment]::GetEnvironmentVariable('Path', 'MACHINE') + $chocolateyPath = "$env:AllUsersProfile\chocolatey\bin" + if(Get-Command "choco" -ErrorAction SilentlyContinue) + { + log "Chocolatey is already installed. Skipping installation." + } + else + { + log "Chocolatey not present. Installing chocolatey." + Invoke-Expression ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1')) + + if (-not ($machinePath.ToLower().Contains($chocolateyPath.ToLower()))) + { + log "Adding $chocolateyPath to Path environment variable" + $env:Path += ";$chocolateyPath" + $machinePath += ";$chocolateyPath" + [Environment]::SetEnvironmentVariable('Path', $machinePath, 'MACHINE') + } + else + { + log "$chocolateyPath already present in Path environment variable" + } + } } elseif ($IsWindows) { Write-Warning "Start-PSBootstrap cannot be run in Core PowerShell on Windows (need Invoke-WebRequest!)" } From 38fc724a0b9cc24cbdfec9037323e72b894e502c Mon Sep 17 00:00:00 2001 From: Karol Kaczmarek Date: Thu, 21 Jul 2016 15:47:28 -0700 Subject: [PATCH 3/7] Installing cmake --- build.psm1 | 43 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 37 insertions(+), 6 deletions(-) diff --git a/build.psm1 b/build.psm1 index c8f753434..96092ce9d 100644 --- a/build.psm1 +++ b/build.psm1 @@ -114,14 +114,14 @@ function Start-PSBuild { $precheck = precheck 'dotnet' "Build dependency 'dotnet' not found in PATH. Run Start-PSBootstrap. Also see: https://dotnet.github.io/getting-started/" if ($FullCLR) { # cmake is needed to build powershell.exe - $precheck = $precheck -and (precheck 'cmake' 'cmake not found. You can install it from https://chocolatey.org/packages/cmake.portable') + $precheck = $precheck -and (precheck 'cmake' 'cmake not found. Run Start-PSBootstrap. You can also install it from https://chocolatey.org/packages/cmake.portable') Use-MSBuild #mc.exe is Message Compiler for native resources $mcexe = Get-ChildItem "${env:ProgramFiles(x86)}\Windows Kits\10\" -Recurse -Filter 'mc.exe' | ? {$_.FullName -match 'x64'} | select -First 1 | % {$_.FullName} if (-not $mcexe) { - throw 'mc.exe not found. Install Microsoft Windows 10 SDK from https://developer.microsoft.com/en-US/windows/downloads/windows-10-sdk' + throw 'mc.exe not found. Run Start-PSBootstrap or install Microsoft Windows 10 SDK from https://developer.microsoft.com/en-US/windows/downloads/windows-10-sdk' } $vcVarsPath = (Get-Item(Join-Path -Path "$env:VS140COMNTOOLS" -ChildPath '../../vc')).FullName @@ -590,14 +590,16 @@ function Start-PSBootstrap { Invoke-WebRequest -Uri $obtainUrl/$installScript -OutFile $installScript & ./$installScript -c $Channel -v $Version - # Install chocolatey $machinePath = [Environment]::GetEnvironmentVariable('Path', 'MACHINE') + $newMachineEnvironmentPath = $machinePath + + # Install chocolatey $chocolateyPath = "$env:AllUsersProfile\chocolatey\bin" if(Get-Command "choco" -ErrorAction SilentlyContinue) { log "Chocolatey is already installed. Skipping installation." } - else + else { log "Chocolatey not present. Installing chocolatey." Invoke-Expression ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1')) @@ -606,14 +608,43 @@ function Start-PSBootstrap { { log "Adding $chocolateyPath to Path environment variable" $env:Path += ";$chocolateyPath" - $machinePath += ";$chocolateyPath" - [Environment]::SetEnvironmentVariable('Path', $machinePath, 'MACHINE') + $newMachineEnvironmentPath += ";$chocolateyPath" } else { log "$chocolateyPath already present in Path environment variable" } } + + # Install cmake + $cmakePath = "${env:ProgramFiles(x86)}\CMake\bin" + if(Get-Command "cmake" -ErrorAction SilentlyContinue) + { + log "Cmake is already installed. Skipping installation." + } + else + { + log "Cmake not present. Installing cmake." + choco install cmake.portable -y --version 3.6.0 + + if (-not ($machinePath.ToLower().Contains($cmakePath.ToLower()))) + { + log "Adding $cmakePath to Path environment variable" + $env:Path += ";$cmakePath" + $newMachineEnvironmentPath = "$cmakePath;$newMachineEnvironmentPath" + } + else + { + log "$cmakePath already present in Path environment variable" + } + } + + # Update machine environment path + if ($newMachineEnvironmentPath -ne $machinePath) + { + [Environment]::SetEnvironmentVariable('Path', $newMachineEnvironmentPath, 'MACHINE') + } + } elseif ($IsWindows) { Write-Warning "Start-PSBootstrap cannot be run in Core PowerShell on Windows (need Invoke-WebRequest!)" } From 1c480ded726614c5986409bc69c4c16d2d5e8214 Mon Sep 17 00:00:00 2001 From: Karol Kaczmarek Date: Thu, 21 Jul 2016 15:53:36 -0700 Subject: [PATCH 4/7] Removing incorrect warning about supportability and using precheck --- build.psm1 | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/build.psm1 b/build.psm1 index 96092ce9d..7fc4ce8ad 100644 --- a/build.psm1 +++ b/build.psm1 @@ -548,8 +548,6 @@ function Start-PSBootstrap { brew install $Deps # OpenSSL libraries must be updated brew link --force openssl - } else { - Write-Warning "This script only supports Ubuntu 14.04, CentOS 7, and OS X, you must install dependencies manually!" } # Install [fpm](https://github.com/jordansissel/fpm) @@ -595,7 +593,8 @@ function Start-PSBootstrap { # Install chocolatey $chocolateyPath = "$env:AllUsersProfile\chocolatey\bin" - if(Get-Command "choco" -ErrorAction SilentlyContinue) + + if(precheck 'choco' $null) { log "Chocolatey is already installed. Skipping installation." } @@ -618,7 +617,7 @@ function Start-PSBootstrap { # Install cmake $cmakePath = "${env:ProgramFiles(x86)}\CMake\bin" - if(Get-Command "cmake" -ErrorAction SilentlyContinue) + if(precheck 'cmake' $null) { log "Cmake is already installed. Skipping installation." } @@ -1370,7 +1369,10 @@ function script:log([string]$message) { function script:precheck([string]$command, [string]$missedMessage) { $c = Get-Command $command -ErrorAction SilentlyContinue if (-not $c) { - Write-Warning $missedMessage + if ($missedMessage -ne $null) + { + Write-Warning $missedMessage + } return $false } else { return $true From 83d5d95956e257779724e227b24a787330d96bb7 Mon Sep 17 00:00:00 2001 From: Karol Kaczmarek Date: Thu, 21 Jul 2016 16:10:57 -0700 Subject: [PATCH 5/7] Installing Windows 10 SDK --- build.psm1 | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/build.psm1 b/build.psm1 index 7fc4ce8ad..cd9175591 100644 --- a/build.psm1 +++ b/build.psm1 @@ -638,6 +638,20 @@ function Start-PSBootstrap { } } + # Install Windows 10 SDK + $sdkPath = "${env:ProgramFiles(x86)}\Microsoft SDKs\Windows\v10.0A" + $packageName = "windows-sdk-10.0" + + if (-not (Test-Path -Path $sdkPath -PathType Container)) + { + log "Windows 10 SDK not present. Installing $packageName." + choco install windows-sdk-10.0 -y + } + else + { + log "Windows 10 SDK present. Skipping installation." + } + # Update machine environment path if ($newMachineEnvironmentPath -ne $machinePath) { From 536085ea58728791299e8e50f7582dd249035cf2 Mon Sep 17 00:00:00 2001 From: Karol Kaczmarek Date: Fri, 22 Jul 2016 14:31:32 -0700 Subject: [PATCH 6/7] Not installing choco when prerequisites present and confirming before updating env variable --- appveyor.yml | 2 +- build.psm1 | 31 +++++++++++++++++++++++-------- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index a63c3cd45..08394635b 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -17,7 +17,7 @@ install: - ps: Set-Content c:\users\appveyor\.ssh\id_rsa $fileContent - git config --global url.git@github.com:.insteadOf https://github.com/ - git submodule update --init - - ps: Import-Module .\build.psm1; Start-PSBootstrap + - ps: Import-Module .\build.psm1; Start-PSBootstrap -Force build_script: - ps: | diff --git a/build.psm1 b/build.psm1 index cd9175591..605958964 100644 --- a/build.psm1 +++ b/build.psm1 @@ -504,11 +504,15 @@ function Start-PSxUnit { function Start-PSBootstrap { - [CmdletBinding()]param( + [CmdletBinding( + SupportsShouldProcess=$true, + ConfirmImpact="High")] + param( [ValidateSet("dev", "beta", "preview")] [string]$Channel = "rel-1.0.0", [string]$Version = "latest", - [switch]$Package + [switch]$Package, + [switch]$Force ) log "Installing Open PowerShell build dependencies" @@ -591,6 +595,10 @@ function Start-PSBootstrap { $machinePath = [Environment]::GetEnvironmentVariable('Path', 'MACHINE') $newMachineEnvironmentPath = $machinePath + $cmakePresent = precheck 'cmake' $null + $sdkPath = "${env:ProgramFiles(x86)}\Microsoft SDKs\Windows\v10.0A" + $sdkPresent = Test-Path -Path $sdkPath -PathType Container + # Install chocolatey $chocolateyPath = "$env:AllUsersProfile\chocolatey\bin" @@ -598,7 +606,7 @@ function Start-PSBootstrap { { log "Chocolatey is already installed. Skipping installation." } - else + elseif(($cmakePresent -eq $false) -or ($sdkPresent -eq $false)) { log "Chocolatey not present. Installing chocolatey." Invoke-Expression ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1')) @@ -614,10 +622,14 @@ function Start-PSBootstrap { log "$chocolateyPath already present in Path environment variable" } } + else + { + log "Skipping installation of chocolatey, cause both cmake and Win 10 SDK are present." + } # Install cmake $cmakePath = "${env:ProgramFiles(x86)}\CMake\bin" - if(precheck 'cmake' $null) + if($cmakePresent) { log "Cmake is already installed. Skipping installation." } @@ -639,10 +651,9 @@ function Start-PSBootstrap { } # Install Windows 10 SDK - $sdkPath = "${env:ProgramFiles(x86)}\Microsoft SDKs\Windows\v10.0A" $packageName = "windows-sdk-10.0" - if (-not (Test-Path -Path $sdkPath -PathType Container)) + if (-not $sdkPresent) { log "Windows 10 SDK not present. Installing $packageName." choco install windows-sdk-10.0 -y @@ -652,10 +663,14 @@ function Start-PSBootstrap { log "Windows 10 SDK present. Skipping installation." } - # Update machine environment path + # Update path machine environment variable if ($newMachineEnvironmentPath -ne $machinePath) { - [Environment]::SetEnvironmentVariable('Path', $newMachineEnvironmentPath, 'MACHINE') + log "Updating Path machine environment variable" + if ($Force -or $PSCmdlet.ShouldProcess("Update Path machine environment variable")) + { + [Environment]::SetEnvironmentVariable('Path', $newMachineEnvironmentPath, 'MACHINE') + } } } elseif ($IsWindows) { From 05485c7a253310c4b0778e06a729d99b59e55a83 Mon Sep 17 00:00:00 2001 From: Karol Kaczmarek Date: Fri, 22 Jul 2016 16:42:19 -0700 Subject: [PATCH 7/7] Confirming before installing choco and improving prompt message --- build.psm1 | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/build.psm1 b/build.psm1 index 605958964..9524ab272 100644 --- a/build.psm1 +++ b/build.psm1 @@ -602,24 +602,32 @@ function Start-PSBootstrap { # Install chocolatey $chocolateyPath = "$env:AllUsersProfile\chocolatey\bin" - if(precheck 'choco' $null) + if(precheck 'choco' $null) { log "Chocolatey is already installed. Skipping installation." } elseif(($cmakePresent -eq $false) -or ($sdkPresent -eq $false)) { log "Chocolatey not present. Installing chocolatey." - Invoke-Expression ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1')) - - if (-not ($machinePath.ToLower().Contains($chocolateyPath.ToLower()))) + if ($Force -or $PSCmdlet.ShouldProcess("Install chocolatey via https://chocolatey.org/install.ps1")) { - log "Adding $chocolateyPath to Path environment variable" - $env:Path += ";$chocolateyPath" - $newMachineEnvironmentPath += ";$chocolateyPath" + Invoke-Expression ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1')) + + if (-not ($machinePath.ToLower().Contains($chocolateyPath.ToLower()))) + { + log "Adding $chocolateyPath to Path environment variable" + $env:Path += ";$chocolateyPath" + $newMachineEnvironmentPath += ";$chocolateyPath" + } + else + { + log "$chocolateyPath already present in Path environment variable" + } } else { - log "$chocolateyPath already present in Path environment variable" + Write-Error "Chocolatey is required to install missing dependencies. Please install it from https://chocolatey.org/ manually. Alternatively, install cmake and Windows 10 SDK." + return $null } } else @@ -667,7 +675,7 @@ function Start-PSBootstrap { if ($newMachineEnvironmentPath -ne $machinePath) { log "Updating Path machine environment variable" - if ($Force -or $PSCmdlet.ShouldProcess("Update Path machine environment variable")) + if ($Force -or $PSCmdlet.ShouldProcess("Update Path machine environment variable to $newMachineEnvironmentPath")) { [Environment]::SetEnvironmentVariable('Path', $newMachineEnvironmentPath, 'MACHINE') }