1
0
Fork 0

converted batch to ps1

This commit is contained in:
Christian Kühnel 2019-11-27 15:41:51 +00:00
parent 29bcd2dc53
commit 7700a2f8d0
7 changed files with 138 additions and 84 deletions

51
scripts/common.ps1 Normal file
View file

@ -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
}
}

View file

@ -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

27
scripts/run_buildkite.ps1 Normal file
View file

@ -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

View file

@ -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

34
scripts/run_cmake.ps1 Normal file
View file

@ -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

View file

@ -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

26
scripts/run_ninja.ps1 Normal file
View file

@ -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