From 7700a2f8d04f925c124d0ded874425c88e1d582d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=BChnel?= Date: Wed, 27 Nov 2019 15:41:51 +0000 Subject: [PATCH] converted batch to ps1 --- scripts/common.ps1 | 51 +++++++++++++++++++++++++++++++++++++++ scripts/run_buildkite.bat | 27 --------------------- scripts/run_buildkite.ps1 | 27 +++++++++++++++++++++ scripts/run_cmake.bat | 33 ------------------------- scripts/run_cmake.ps1 | 34 ++++++++++++++++++++++++++ scripts/run_ninja.bat | 24 ------------------ scripts/run_ninja.ps1 | 26 ++++++++++++++++++++ 7 files changed, 138 insertions(+), 84 deletions(-) create mode 100644 scripts/common.ps1 delete mode 100644 scripts/run_buildkite.bat create mode 100644 scripts/run_buildkite.ps1 delete mode 100644 scripts/run_cmake.bat create mode 100644 scripts/run_cmake.ps1 delete mode 100644 scripts/run_ninja.bat create mode 100644 scripts/run_ninja.ps1 diff --git a/scripts/common.ps1 b/scripts/common.ps1 new file mode 100644 index 0000000..29187c4 --- /dev/null +++ b/scripts/common.ps1 @@ -0,0 +1,51 @@ +# Copyright 2019 Google LLC +# +# Licensed under the the Apache License v2.0 with LLVM Exceptions (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://llvm.org/LICENSE.txt +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# common header file for all .ps1 scripts + +# stop script on errors +Set-StrictMode -Version Latest +$ErrorActionPreference = "Stop" +$PSDefaultParameterValues['*:ErrorAction']='Stop' + + +# Invokes a Cmd.exe shell script and updates the environment. +# from: https://stackoverflow.com/questions/41399692/running-a-build-script-after-calling-vcvarsall-bat-from-powershell +function Invoke-CmdScript { + param( + [String] $scriptName + ) + $cmdLine = """$scriptName"" $args & set" + & $Env:SystemRoot\system32\cmd.exe /c $cmdLine | + select-string '^([^=]*)=(.*)$' | foreach-object { + $varName = $_.Matches[0].Groups[1].Value + $varValue = $_.Matches[0].Groups[2].Value + set-item Env:$varName $varValue + } + } + + +# call an executable and check the error code +# from: https://stackoverflow.com/questions/9948517/how-to-stop-a-powershell-script-on-the-first-error +function Invoke-Call { + param ( + [scriptblock]$ScriptBlock, + [string]$ErrorAction = $ErrorActionPreference + ) + & @ScriptBlock + if (($lastexitcode -ne 0) -and $ErrorAction -eq "Stop") { + Write-Error "Command $ScriptBlock exited with $lastexitcode." + exit $lastexitcode + } +} diff --git a/scripts/run_buildkite.bat b/scripts/run_buildkite.bat deleted file mode 100644 index 68470f4..0000000 --- a/scripts/run_buildkite.bat +++ /dev/null @@ -1,27 +0,0 @@ -rem Copyright 2019 Google LLC -rem -rem Licensed under the the Apache License v2.0 with LLVM Exceptions (the "License"); -rem you may not use this file except in compliance with the License. -rem You may obtain a copy of the License at -rem -rem https://llvm.org/LICENSE.txt -rem -rem Unless required by applicable law or agreed to in writing, software -rem distributed under the License is distributed on an "AS IS" BASIS, -rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -rem See the License for the specific language governing permissions and -rem limitations under the License. - -echo --- CMake -call %~dp0\run_cmake.bat -if %errorlevel% neq 0 exit /b %errorlevel% - -echo --- ninja all -call %~dp0\run_ninja.bat all -if %errorlevel% neq 0 exit /b %errorlevel% - -echo --- ninja check-all -call %~dp0\run_ninja.bat check-all -if %errorlevel% neq 0 exit /b %errorlevel% - -echo --- done \ No newline at end of file diff --git a/scripts/run_buildkite.ps1 b/scripts/run_buildkite.ps1 new file mode 100644 index 0000000..e462f0e --- /dev/null +++ b/scripts/run_buildkite.ps1 @@ -0,0 +1,27 @@ +# Copyright 2019 Google LLC +# +# Licensed under the the Apache License v2.0 with LLVM Exceptions (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://llvm.org/LICENSE.txt +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +New-Variable -Name SCRIPT_DIR -Value (Get-Item $PSScriptRoot).FullName +. ${SCRIPT_DIR}\common.ps1 + +Write-Output "--- CMake" +& "${SCRIPT_DIR}\run_cmake.ps1" + +Write-Output "--- ninja all" +& "${SCRIPT_DIR}\run_ninja.ps1" all + +Write-Output "--- ninja check-all" +& "${SCRIPT_DIR}\run_ninja.ps1" check-all + +Write-Output --- done \ No newline at end of file diff --git a/scripts/run_cmake.bat b/scripts/run_cmake.bat deleted file mode 100644 index bb13328..0000000 --- a/scripts/run_cmake.bat +++ /dev/null @@ -1,33 +0,0 @@ -@rem Copyright 2019 Google LLC -@rem -@rem Licensed under the the Apache License v2.0 with LLVM Exceptions (the "License"); -@rem you may not use this file except in compliance with the License. -@rem You may obtain a copy of the License at -@rem -@rem https://llvm.org/LICENSE.txt -@rem -@rem Unless required by applicable law or agreed to in writing, software -@rem distributed under the License is distributed on an "AS IS" BASIS, -@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -@rem See the License for the specific language governing permissions and -@rem limitations under the License. - -PUSHD - -md build -cd build - -call "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\Common7\Tools\VsDevCmd.bat" -arch=amd64 -host_arch=amd64 - -cmake.exe ..\llvm -G Ninja -DCMAKE_BUILD_TYPE=Release ^ - -D LLVM_ENABLE_PROJECTS="clang;clang-tools-extra;libcxx;libcxxabi;lld" ^ - -D LLVM_ENABLE_ASSERTIONS=ON ^ - -DLLVM_LIT_ARGS="-v --xunit-xml-output test-results.xml" ^ - -D LLVM_ENABLE_DIA_SDK=OFF - -if %errorlevel% neq 0 exit /b %errorlevel% - -rem LLVM_ENABLE_DIA_SDK=OFF is a workaround to make the tests pass. -rem see https://bugs.llvm.org/show_bug.cgi?id=44151 - -POPD \ No newline at end of file diff --git a/scripts/run_cmake.ps1 b/scripts/run_cmake.ps1 new file mode 100644 index 0000000..c493147 --- /dev/null +++ b/scripts/run_cmake.ps1 @@ -0,0 +1,34 @@ +# Copyright 2019 Google LLC +# +# Licensed under the the Apache License v2.0 with LLVM Exceptions (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://llvm.org/LICENSE.txt +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +New-Variable -Name SCRIPT_DIR -Value (Get-Item $PSScriptRoot).FullName +. ${SCRIPT_DIR}\common.ps1 + +New-Item -ItemType Directory -Force -Path build | Out-Null +Push-Location build + +Invoke-CmdScript "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\Common7\Tools\VsDevCmd.bat" -arch=amd64 -host_arch=amd64 + +Invoke-Call -ScriptBlock { + cmake.exe ..\llvm -G Ninja -DCMAKE_BUILD_TYPE=Release ` + -D LLVM_ENABLE_PROJECTS="clang;clang-tools-extra;libcxx;libcxxabi;lld" ` + -D LLVM_ENABLE_ASSERTIONS=ON ` + -DLLVM_LIT_ARGS="-v --xunit-xml-output test-results.xml" ` + -D LLVM_ENABLE_DIA_SDK=OFF +} -ErrorAction Stop + +# LLVM_ENABLE_DIA_SDK=OFF is a workaround to make the tests pass. +# see https://bugs.llvm.org/show_bug.cgi?id=44151 + +Pop-Location \ No newline at end of file diff --git a/scripts/run_ninja.bat b/scripts/run_ninja.bat deleted file mode 100644 index 30da4f8..0000000 --- a/scripts/run_ninja.bat +++ /dev/null @@ -1,24 +0,0 @@ -@rem Copyright 2019 Google LLC -@rem -@rem Licensed under the the Apache License v2.0 with LLVM Exceptions (the "License"); -@rem you may not use this file except in compliance with the License. -@rem You may obtain a copy of the License at -@rem -@rem https://llvm.org/LICENSE.txt -@rem -@rem Unless required by applicable law or agreed to in writing, software -@rem distributed under the License is distributed on an "AS IS" BASIS, -@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -@rem See the License for the specific language governing permissions and -@rem limitations under the License. - -PUSHD - -cd build - -call "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\Common7\Tools\VsDevCmd.bat" -arch=amd64 -host_arch=amd64 - -ninja %1 -if %errorlevel% neq 0 exit /b %errorlevel% - -POPD \ No newline at end of file diff --git a/scripts/run_ninja.ps1 b/scripts/run_ninja.ps1 new file mode 100644 index 0000000..f8a6d30 --- /dev/null +++ b/scripts/run_ninja.ps1 @@ -0,0 +1,26 @@ +# Copyright 2019 Google LLC +# +# Licensed under the the Apache License v2.0 with LLVM Exceptions (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://llvm.org/LICENSE.txt +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +param( + [Parameter(Mandatory=$true)][string]$target +) + +New-Variable -Name SCRIPT_DIR -Value (Get-Item $PSScriptRoot).FullName +. ${SCRIPT_DIR}\common.ps1 + +Push-Location build + +Invoke-Call -ScriptBlock {ninja $target} -ErrorAction Stop + +Pop-Location