From c5be17651cdbe0c60833b2953bae828acb1a0e60 Mon Sep 17 00:00:00 2001 From: Andy Ayers Date: Fri, 15 Apr 2016 14:03:46 -0700 Subject: [PATCH] Detect if powershell version is suitable for restoring build tools Powershell v3 or higher is required to decompress the build tools bundle. Windows 7 typically has v2 installed. Detect earlier versions and fail with a pointer to the build prerequisites and a download link for an updated version. Also propagate failures out of init-tools.cmd. The last step of this is unchecked since the build tool init script can return nonzero status even on success. See #3510. --- Documentation/building/windows-instructions.md | 3 +++ build.cmd | 24 +++++++++++++++++++++--- init-tools.cmd | 15 +++++++++++---- 3 files changed, 35 insertions(+), 7 deletions(-) diff --git a/Documentation/building/windows-instructions.md b/Documentation/building/windows-instructions.md index 6ac3933..ac85d0c 100644 --- a/Documentation/building/windows-instructions.md +++ b/Documentation/building/windows-instructions.md @@ -36,6 +36,9 @@ PowerShell ---------- PowerShell is used in the build system. Ensure that it is accessible via the PATH environment variable. Typically this is %SYSTEMROOT%\System32\WindowsPowerShell\v1.0\. +Powershell version must be 3.0 or higher. This should be the case for Windows 8 and later builds. +- Windows 7 SP1 can install Powershell version 4 [here](https://www.microsoft.com/en-us/download/details.aspx?id=40855). + Git Setup --------- diff --git a/build.cmd b/build.cmd index 6461ff3..aa1201b 100644 --- a/build.cmd +++ b/build.cmd @@ -217,7 +217,15 @@ echo %__MsgPrefix%Checking prerequisites :: Validate that PowerShell is accessibile. for %%X in (powershell.exe) do (set __PSDir=%%~$PATH:X) -if not defined __PSDir goto NoPS +if not defined __PSDir goto :NoPS + +:: Validate Powershell version +set PS_VERSION_LOG=%~dp0ps-version.log +powershell -NoProfile -ExecutionPolicy unrestricted -Command "$PSVersionTable.PSVersion.Major" > %PS_VERSION_LOG% +set /P PS_VERSION=< %PS_VERSION_LOG% +if %PS_VERSION% LEQ 2 ( + goto :OldPS +) :: Eval the output from probe-win1.ps1 for /f "delims=" %%a in ('powershell -NoProfile -ExecutionPolicy RemoteSigned "& ""%__SourceDir%\pal\tools\probe-win.ps1"""') do %%a @@ -260,6 +268,10 @@ REM === Restore Build Tools REM === REM ========================================================================================= call %__ThisScriptPath%init-tools.cmd +if errorlevel 1 ( + echo ERROR: Could not restore build tools. + exit /b 1 +) REM ========================================================================================= REM === @@ -655,14 +667,20 @@ echo -- builds x64 and x86 architectures, Checked and Release build types exit /b 1 :NoPS -echo PowerShell is a prerequisite to build this repository, but it is not accessible. +echo PowerShell v3.0 or later is a prerequisite to build this repository, but it is not accessible. echo Ensure that it is defined in the PATH environment variable. echo Typically it should be %%SYSTEMROOT%%\System32\WindowsPowerShell\v1.0\. exit /b 1 +:OldPS +echo PowerShell v3.0 or later is a prerequisite to build this repository. +echo See: https://github.com/dotnet/coreclr/blob/master/Documentation/building/windows-instructions.md +echo Download via https://www.microsoft.com/en-us/download/details.aspx?id=40855 +exit /b 1 + :NoVS echo Visual Studio 2015+ ^(Community is free^) is a prerequisite to build this repository. -echo See: https://github.com/dotnet/coreclr/blob/master/Documentation/project-docs/developer-guide.md#prerequisites +echo See: https://github.com/dotnet/coreclr/blob/master/Documentation/building/windows-instructions.md exit /b 1 :NoDIA diff --git a/init-tools.cmd b/init-tools.cmd index 387ede7..f95f56e 100644 --- a/init-tools.cmd +++ b/init-tools.cmd @@ -13,6 +13,7 @@ set PROJECT_JSON_PATH=%TOOLRUNTIME_DIR%\%BUILDTOOLS_VERSION% set PROJECT_JSON_FILE=%PROJECT_JSON_PATH%\project.json set PROJECT_JSON_CONTENTS={ "dependencies": { "Microsoft.DotNet.BuildTools": "%BUILDTOOLS_VERSION%" , "Microsoft.DotNet.BuildTools.Coreclr": "1.0.4-prerelease"}, "frameworks": { "dnxcore50": { } } } set BUILD_TOOLS_SEMAPHORE=%PROJECT_JSON_PATH%\init-tools.completed +set TOOLS_INIT_RETURN_CODE=0 :: if force option is specified then clean the tool runtime and build tools package directory to force it to get recreated if [%1]==[force] ( @@ -23,7 +24,7 @@ if [%1]==[force] ( :: If sempahore exists do nothing if exist "%BUILD_TOOLS_SEMAPHORE%" ( echo Tools are already initialized. - goto :EOF + goto :DONE ) if exist "%TOOLRUNTIME_DIR%" rmdir /S /Q "%TOOLRUNTIME_DIR%" @@ -50,7 +51,8 @@ echo Installing '%DOTNET_REMOTE_PATH%' to '%DOTNET_LOCAL_PATH%' >> %INIT_TOOLS_L powershell -NoProfile -ExecutionPolicy unrestricted -Command "(New-Object Net.WebClient).DownloadFile('%DOTNET_REMOTE_PATH%', '%DOTNET_LOCAL_PATH%'); Add-Type -Assembly 'System.IO.Compression.FileSystem' -ErrorVariable AddTypeErrors; if ($AddTypeErrors.Count -eq 0) { [System.IO.Compression.ZipFile]::ExtractToDirectory('%DOTNET_LOCAL_PATH%', '%DOTNET_PATH%') } else { (New-Object -com shell.application).namespace('%DOTNET_PATH%').CopyHere((new-object -com shell.application).namespace('%DOTNET_LOCAL_PATH%').Items(),16) }" >> %INIT_TOOLS_LOG% if NOT exist "%DOTNET_LOCAL_PATH%" ( echo ERROR: Could not install dotnet cli correctly. See '%INIT_TOOLS_LOG%' for more details. - goto :EOF + set TOOLS_INIT_RETURN_CODE=1 + goto :DONE ) :afterdotnetrestore @@ -61,7 +63,8 @@ echo Running: "%DOTNET_CMD%" restore "%PROJECT_JSON_FILE%" --packages %PACKAGES_ call "%DOTNET_CMD%" restore "%PROJECT_JSON_FILE%" --packages %PACKAGES_DIR% --source "%BUILDTOOLS_SOURCE%" >> %INIT_TOOLS_LOG% if NOT exist "%BUILD_TOOLS_PATH%init-tools.cmd" ( echo ERROR: Could not restore build tools correctly. See '%INIT_TOOLS_LOG%' for more details. - goto :EOF + set TOOLS_INIT_RETURN_CODE=1 + goto :DONE ) :afterbuildtoolsrestore @@ -72,4 +75,8 @@ call "%BUILD_TOOLS_PATH%init-tools.cmd" "%~dp0" "%DOTNET_CMD%" "%TOOLRUNTIME_DIR :: Create sempahore file echo Done initializing tools. -echo Init-Tools.cmd completed for BuildTools Version: %BUILDTOOLS_VERSION% > "%BUILD_TOOLS_SEMAPHORE%" \ No newline at end of file +echo Init-Tools.cmd completed for BuildTools Version: %BUILDTOOLS_VERSION% > "%BUILD_TOOLS_SEMAPHORE%" + +:DONE + +exit /b %TOOLS_INIT_RETURN_CODE% -- 2.7.4