From 15c6593db2e28b4c2d2d72aaa58c65dcb12cfa9b Mon Sep 17 00:00:00 2001 From: Dan Moseley Date: Fri, 16 Nov 2018 07:14:11 -0800 Subject: Eliminate CMAKE dependency when not required (#21040) --- src/pal/tools/gen-buildsys-win.bat | 4 +-- src/pal/tools/probe-win.ps1 | 70 -------------------------------------- src/pal/tools/set-cmake-path.ps1 | 70 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 72 insertions(+), 72 deletions(-) delete mode 100644 src/pal/tools/probe-win.ps1 create mode 100644 src/pal/tools/set-cmake-path.ps1 (limited to 'src/pal/tools') diff --git a/src/pal/tools/gen-buildsys-win.bat b/src/pal/tools/gen-buildsys-win.bat index 221d32269b..f542e994e7 100644 --- a/src/pal/tools/gen-buildsys-win.bat +++ b/src/pal/tools/gen-buildsys-win.bat @@ -36,8 +36,8 @@ goto loop if defined CMakePath goto DoGen -:: Eval the output from probe-win1.ps1 -for /f "delims=" %%a in ('powershell -NoProfile -ExecutionPolicy ByPass "& "%basePath%\probe-win.ps1""') do %%a +:: Eval the output from set-cmake-path.ps1 +for /f "delims=" %%a in ('powershell -NoProfile -ExecutionPolicy ByPass "& "%basePath%\set-cmake-path.ps1""') do %%a :DoGen "%CMakePath%" "-DCMAKE_USER_MAKE_RULES_OVERRIDE=%basePath%\windows-compiler-override.txt" "-DCMAKE_INSTALL_PREFIX:PATH=$ENV{__CMakeBinDir}" "-DCLR_CMAKE_HOST_ARCH=%__Arch%" %__ExtraCmakeParams% -G "%__CmakeGenerator%" %__SourceDir% diff --git a/src/pal/tools/probe-win.ps1 b/src/pal/tools/probe-win.ps1 deleted file mode 100644 index 5fc499a8c6..0000000000 --- a/src/pal/tools/probe-win.ps1 +++ /dev/null @@ -1,70 +0,0 @@ -# This file probes for the prerequisites for the build system, and outputs commands for eval'ing -# from the cmd scripts to set variables (and exit on error) - -function GetCMakeVersions -{ - $items = @() - $items += @(Get-ChildItem hklm:\SOFTWARE\Wow6432Node\Kitware -ErrorAction SilentlyContinue) - $items += @(Get-ChildItem hklm:\SOFTWARE\Kitware -ErrorAction SilentlyContinue) - return $items | where { $_.PSChildName.StartsWith("CMake") } -} - -function GetCMakeInfo($regKey) -{ - try { - $version = [System.Version] $regKey.PSChildName.Split(' ')[1] - } - catch { - return $null - } - $itemProperty = Get-ItemProperty $regKey.PSPath; - if (Get-Member -inputobject $itemProperty -name "InstallDir" -Membertype Properties) { - $cmakeDir = $itemProperty.InstallDir - } - else { - $cmakeDir = $itemProperty.'(default)' - } - $cmakePath = [System.IO.Path]::Combine($cmakeDir, "bin\cmake.exe") - if (![System.IO.File]::Exists($cmakePath)) { - return $null - } - return @{'version' = $version; 'path' = $cmakePath} -} - -function LocateCMake -{ - $errorMsg = "CMake is a pre-requisite to build this repository but it was not found on the path. Please install CMake from http://www.cmake.org/download/ and ensure it is on your path." - $inPathPath = (get-command cmake.exe -ErrorAction SilentlyContinue) - if ($inPathPath -ne $null) { - # Resolve the first version of CMake if multiple commands are found - if ($inPathPath.Length -gt 1) { - return $inPathPath[0].Path - } - return $inPathPath.Path - } - # Let us hope that CMake keep using their current version scheme - $validVersions = @() - foreach ($regKey in GetCMakeVersions) { - $info = GetCMakeInfo($regKey) - if ($info -ne $null) { - $validVersions += @($info) - } - } - $newestCMakePath = ($validVersions | - Sort-Object -property @{Expression={$_.version}; Ascending=$false} | - select -first 1).path - if ($newestCMakePath -eq $null) { - Throw $errorMsg - } - return $newestCMakePath -} - -try { - $cmakePath = LocateCMake - [System.Console]::WriteLine("set CMakePath=" + $cmakePath) - -} -catch { - [System.Console]::Error.WriteLine($_.Exception.Message) - [System.Console]::WriteLine("exit /b 1") -} diff --git a/src/pal/tools/set-cmake-path.ps1 b/src/pal/tools/set-cmake-path.ps1 new file mode 100644 index 0000000000..5fc499a8c6 --- /dev/null +++ b/src/pal/tools/set-cmake-path.ps1 @@ -0,0 +1,70 @@ +# This file probes for the prerequisites for the build system, and outputs commands for eval'ing +# from the cmd scripts to set variables (and exit on error) + +function GetCMakeVersions +{ + $items = @() + $items += @(Get-ChildItem hklm:\SOFTWARE\Wow6432Node\Kitware -ErrorAction SilentlyContinue) + $items += @(Get-ChildItem hklm:\SOFTWARE\Kitware -ErrorAction SilentlyContinue) + return $items | where { $_.PSChildName.StartsWith("CMake") } +} + +function GetCMakeInfo($regKey) +{ + try { + $version = [System.Version] $regKey.PSChildName.Split(' ')[1] + } + catch { + return $null + } + $itemProperty = Get-ItemProperty $regKey.PSPath; + if (Get-Member -inputobject $itemProperty -name "InstallDir" -Membertype Properties) { + $cmakeDir = $itemProperty.InstallDir + } + else { + $cmakeDir = $itemProperty.'(default)' + } + $cmakePath = [System.IO.Path]::Combine($cmakeDir, "bin\cmake.exe") + if (![System.IO.File]::Exists($cmakePath)) { + return $null + } + return @{'version' = $version; 'path' = $cmakePath} +} + +function LocateCMake +{ + $errorMsg = "CMake is a pre-requisite to build this repository but it was not found on the path. Please install CMake from http://www.cmake.org/download/ and ensure it is on your path." + $inPathPath = (get-command cmake.exe -ErrorAction SilentlyContinue) + if ($inPathPath -ne $null) { + # Resolve the first version of CMake if multiple commands are found + if ($inPathPath.Length -gt 1) { + return $inPathPath[0].Path + } + return $inPathPath.Path + } + # Let us hope that CMake keep using their current version scheme + $validVersions = @() + foreach ($regKey in GetCMakeVersions) { + $info = GetCMakeInfo($regKey) + if ($info -ne $null) { + $validVersions += @($info) + } + } + $newestCMakePath = ($validVersions | + Sort-Object -property @{Expression={$_.version}; Ascending=$false} | + select -first 1).path + if ($newestCMakePath -eq $null) { + Throw $errorMsg + } + return $newestCMakePath +} + +try { + $cmakePath = LocateCMake + [System.Console]::WriteLine("set CMakePath=" + $cmakePath) + +} +catch { + [System.Console]::Error.WriteLine($_.Exception.Message) + [System.Console]::WriteLine("exit /b 1") +} -- cgit v1.2.3