Skip to content

Commit

Permalink
Unify Windows provisioning scripts & improve error handling
Browse files Browse the repository at this point in the history
While Coin should also see exit codes != 0 as error, we should
stick to one way of handling script errors. As Power Shell cmdlets
signal an error by throwing an exception we should do the same
(and that approach also works in Coin).

Additionally extracting 7zip files was unified across scripts by
using the existing helper function instead of reinventing the wheel
again and again.

A similar helper function was introduced for starting an external
application (and handling its errors).

Also echo and other "cmd" commands were replaced by their PowerShell
equivalents to have a unified approach across our Windows provisioning
scripts.

Change-Id: I70129ce38692f1396c33c13b33a2918485fa5271
Reviewed-by: Frederik Gladhorn <frederik.gladhorn@qt.io>
  • Loading branch information
owolff authored and liangqi committed Feb 26, 2018
1 parent 08c88de commit cb6709c
Show file tree
Hide file tree
Showing 55 changed files with 363 additions and 383 deletions.
38 changes: 17 additions & 21 deletions coin/provisioning/common/windows/03-conan.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,12 @@

$scriptsPath = "C:\Python27\Scripts"

& "$scriptsPath\pip.exe" install --upgrade conan==0.24.0
Run-Executable "$scriptsPath\pip.exe" "install --upgrade conan==0.24.0"

# Use Qt Project repository by default
& "$scriptsPath\conan.exe" remote add qtproject https://api.bintray.com/conan/qtproject/conan --insert
Run-Executable "$scriptsPath\conan.exe" "remote add qtproject https://api.bintray.com/conan/qtproject/conan --insert"

[Environment]::SetEnvironmentVariable("CI_CONAN_BUILDINFO_DIR", "C:\Utils\conanbuildinfos", "Machine")

function Start-Process-Logged
{
Write-Host "Start-Process", $args
Start-Process @args
}
Set-EnvironmentVariable "CI_CONAN_BUILDINFO_DIR" "C:\Utils\conanbuildinfos"

function Run-Conan-Install
{
Expand Down Expand Up @@ -43,18 +37,20 @@ function Run-Conan-Install
$outpwd = "C:\Utils\conanbuildinfos\$($BuildinfoDir)\$($_.BaseName)"
New-Item $outpwd -Type directory -Force

$process = Start-Process-Logged `
"$scriptsPath\conan.exe" `
-WorkingDirectory $outpwd `
-ArgumentList "install -f $conanfile --no-imports --verify $manifestsDir", `
'-s', ('compiler="' + $Compiler + '"'), `
"-s os=Windows -s arch=$Arch -s compiler.version=$CompilerVersion $extraArgs" `
-NoNewWindow -Wait -Verbose `
-PassThru # Return process object

if ($process.ExitCode -ne 0) {
Write-Host "conan exited with code $($process.ExitCode)"
Exit(1)
for ($i = 1; $i -le 5; $i++) {
try {
Push-Location $outpwd
Run-Executable "$scriptsPath\conan.exe" "install -f $conanfile --no-imports --verify $manifestsDir", `
'-s', ('compiler="' + $Compiler + '"'), `
"-s os=Windows -s arch=$Arch -s compiler.version=$CompilerVersion $extraArgs" `
break;
} catch {
if ($i -eq 5) {
throw "Could not install conan content"
}
} finally {
Pop-Location
}
}

Copy-Item -Path $conanfile -Destination "$outpwd\conanfile.txt"
Expand Down
4 changes: 2 additions & 2 deletions coin/provisioning/common/windows/3dstudio_3rdparty.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ $url = "http://ci-files01-hki.intra.qt.io/input/3rdparty/Qt3DStudio-3rdparty-win
Download $url $url $zip
Verify-Checksum $zip "08D740D2EFB4CBCDE7D012908B89AA48DE5CD4E1"
Extract-Zip $zip C:\Utils\Qt3DStudio3rdparty
Remove-Item $zip
Remove-Item -Path $zip

[Environment]::SetEnvironmentVariable("QT3DSTUDIO_3RDPARTY_DIR", "C:/Utils/Qt3DStudio3rdparty", "Machine")
Set-EnvironmentVariable "QT3DSTUDIO_3RDPARTY_DIR" "C:/Utils/Qt3DStudio3rdparty"
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
## $QT_END_LICENSE$
##
#############################################################################
. "$PSScriptRoot\helpers.ps1"

# This script allows the Windows Remote Desktop Access

reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server" /v fDenyTSConnections /t REG_DWORD /d 0 /f
Run-Executable "reg.exe" "add `"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server`" /v fDenyTSConnections /t REG_DWORD /d 0 /f"
20 changes: 10 additions & 10 deletions coin/provisioning/common/windows/android-openssl.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -47,23 +47,23 @@ $destination = "C:\Utils\openssl-android-master"
Download https://www.openssl.org/source/openssl-$version.tar.gz \\ci-files01-hki.intra.qt.io\provisioning\openssl\openssl-$version.tar.gz $zip
Verify-Checksum $zip $sha1

C:\Utils\sevenzip\7z.exe x $zip -oC:\Utils
C:\Utils\sevenzip\7z.exe x C:\Utils\openssl-$version.tar -oC:\Utils
Extract-7Zip $zip C:\Utils
Extract-7Zip C:\Utils\openssl-$version.tar C:\Utils
Rename-Item C:\Utils\openssl-$version $destination
Remove-Item $zip
Remove-Item -Path $zip
Remove-Item C:\Utils\openssl-$version.tar

set CC=C:\utils\android-ndk-r10e\toolchains\arm-linux-androideabi-4.9\prebuilt\windows\bin\arm-linux-androideabi-gcc
set AR=C:\utils\android-ndk-r10e\toolchains\arm-linux-androideabi-4.9\prebuilt\windows\bin\arm-linux-androideabi-ar
set ANDROID_DEV=C:\utils\android-ndk-r10e\platforms\android-18\arch-arm\usr
Set-EnvironmentVariable "CC" "C:\utils\android-ndk-r10e\toolchains\arm-linux-androideabi-4.9\prebuilt\windows\bin\arm-linux-androideabi-gcc"
Set-EnvironmentVariable "AR" "C:\utils\android-ndk-r10e\toolchains\arm-linux-androideabi-4.9\prebuilt\windows\bin\arm-linux-androideabi-ar"
Set-EnvironmentVariable "ANDROID_DEV" "C:\utils\android-ndk-r10e\platforms\android-18\arch-arm\usr"

# Make sure configure for openssl has a "make" and "perl" available
$env:PATH = $env:PATH + ";C:\msys\1.0\bin;C:\strawberry\perl\bin"

echo "Configuring OpenSSL $version for Android..."
pushd $destination
C:\msys\1.0\bin\bash.exe -c "c:/strawberry/perl/bin/perl Configure shared android"
popd
Write-Host "Configuring OpenSSL $version for Android..."
Push-Location $destination
Run-Executable "C:\msys\1.0\bin\bash.exe" "-c `"c:/strawberry/perl/bin/perl Configure shared android`""
Pop-Location

# Following command is needed when using version 1.1.0. With version 1.1.0 msys is not needed.
# C:\mingw530\bin\mingw32-make.exe include\openssl\opensslconf.h
28 changes: 15 additions & 13 deletions coin/provisioning/common/windows/android.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -70,29 +70,31 @@ function Install($1, $2, $3, $4) {
}

function SdkUpdate ($1, $2) {
echo "Running Android SDK update for $1..."
Write-Host "Running Android SDK update for $1..."
cmd /c "echo y |$1\tools\android update sdk --no-ui --all --filter $2"
}

echo "Installing Android ndk $nkdVersion"
Write-Host "Installing Android ndk $nkdVersion"
Install $ndkCachedUrl $ndkZip $ndkChecksum $ndkOfficialUrl
echo "Set environment variable ANDROID_NDK_HOME=$ndkFolder"
[Environment]::SetEnvironmentVariable("ANDROID_NDK_HOME", $ndkFolder, "Machine")
echo "Set environment variable ANDROID_NDK_ROOT=$ndkFolder"
[Environment]::SetEnvironmentVariable("ANDROID_NDK_ROOT", $ndkFolder, "Machine")
Set-EnvironmentVariable "ANDROID_NDK_HOME" $ndkFolder
Set-EnvironmentVariable "ANDROID_NDK_ROOT" $ndkFolder

#echo "Installing Android sdk $sdkVersion"
#Write-Host "Installing Android sdk $sdkVersion"
Install $sdkCachedUrl $sdkZip $sdkChecksum $sdkOfficialUrl
echo "Set environment variable ANDROID_SDK_HOME=$sdkFolder"
[Environment]::SetEnvironmentVariable("ANDROID_SDK_HOME", $sdkFolder, "Machine")
echo "Set environment variable ANDROID_API_VERSION $sdkApiLevel"
[Environment]::SetEnvironmentVariable("ANDROID_API_VERSION", $sdkApiLevel, "Machine")
Set-EnvironmentVariable "ANDROID_SDK_HOME" $sdkFolder
Set-EnvironmentVariable "ANDROID_API_VERSION" $sdkApiLevel

# SDK update
SdkUpdate $sdkFolder $sdkApiLevel
SdkUpdate $sdkFolder tools
SdkUpdate $sdkFolder platform-tools
SdkUpdate $sdkFolder build-tools-$sdkBuildToolsVersion

# kill adb. This process prevent's provisioning to continue
taskkill /im adb.exe /f
# kill adb. This process prevents provisioning to continue
$p = Get-Process -Name "adb.exe" -ErrorAction:SilentlyContinue
if ($p -ne $null) {
Write-Host "Stopping adb.exe"
Stop-Process -Force $p
} else {
Write-Host "adb.exe not running"
}
4 changes: 2 additions & 2 deletions coin/provisioning/common/windows/cmake.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ $zip = "c:\users\qt\downloads\cmake-" + $version + "-win32-x86.zip"
$officialurl = "https://cmake.org/files/v" + $majorminorversion + "/cmake-" + $version + "-win32-x86.zip"
$cachedurl = "\\ci-files01-hki.intra.qt.io\provisioning\cmake\cmake-" + $version + "-win32-x86.zip"

echo "Removing old cmake"
Write-Host "Removing old cmake"
Remove-Item "C:\CMake" -Force -Recurse -ErrorAction SilentlyContinue

Download $officialurl $cachedurl $zip
Expand All @@ -52,5 +52,5 @@ Rename-Item $defaultinstallfolder C:\CMake

Add-Path "C:\CMake\bin"

echo "CMake = $version" >> ~\versions.txt
Write-Output "CMake = $version" >> ~\versions.txt

4 changes: 3 additions & 1 deletion coin/provisioning/common/windows/disable-ntp.ps1
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
. "$PSScriptRoot\helpers.ps1"

# Disable the NTP from syncing
w32tm /config /syncfromflags:NO
Run-Executable "w32tm.exe" "/config /syncfromflags:NO"
9 changes: 5 additions & 4 deletions coin/provisioning/common/windows/disable-sleep.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@
## $QT_END_LICENSE$
##
#############################################################################
. "$PSScriptRoot\helpers.ps1"

# This script prevents Windows from going to sleep

powercfg -change -monitor-timeout-ac 0
powercfg -change -standby-timeout-ac 0
powercfg -change -disk-timeout-ac 0
powercfg -change -hibernate-timeout-ac 0
Run-Executable "powercfg.exe" "-change -monitor-timeout-ac 0"
Run-Executable "powercfg.exe" "-change -standby-timeout-ac 0"
Run-Executable "powercfg.exe" "-change -disk-timeout-ac 0"
Run-Executable "powercfg.exe" "-change -hibernate-timeout-ac 0"
3 changes: 2 additions & 1 deletion coin/provisioning/common/windows/disable-uac.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
## $QT_END_LICENSE$
##
#############################################################################
. "$PSScriptRoot\helpers.ps1"

# This script disables the Windows UAC

C:\Windows\System32\cmd.exe /k %windir%\System32\reg.exe ADD HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System /v EnableLUA /t REG_DWORD /d 0 /f
Run-Executable "reg.exe" "ADD HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System /v EnableLUA /t REG_DWORD /d 0 /f"
5 changes: 4 additions & 1 deletion coin/provisioning/common/windows/disable-windefender.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@
#
# If disabled manually, windows will automatically enable it after
# some period of time. Disabling it speeds up the builds.
REG ADD "HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows Defender" /V DisableAntiSpyware /T REG_dWORD /D 1 /F

. "$PSScriptRoot\helpers.ps1"

Run-Executable "reg.exe" "ADD `"HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows Defender`" /V DisableAntiSpyware /T REG_dWORD /D 1 /F"
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ if ($service.Status -eq "Stopped") {
Write-Host "Windows Update service already stopped."
} else {
Write-Host "Stopping Windows Update service."
stop-service wuauserv
Stop-Service -Name "wuauserv" -Force
}

$startup = Get-WmiObject Win32_Service | Where-Object {$_.Name -eq "wuauserv"} | Select -ExpandProperty "StartMode"
Expand Down
8 changes: 4 additions & 4 deletions coin/provisioning/common/windows/dxsdk.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ $exe = "C:\Windows\Temp\$package"

Download $officialUrl $cachedUrl $exe

echo "Installing DirectX SDK"
cmd /c "$exe /u"
Write-Host "Installing DirectX SDK"
Run-Executable $exe "/u"

Remove-Item $exe
Remove-Item -Path $exe

echo "DirectX SDK = 9.29.1962 (Jun 10)" >> ~\versions.txt
Write-Output "DirectX SDK = 9.29.1962 (Jun 10)" >> ~\versions.txt
12 changes: 5 additions & 7 deletions coin/provisioning/common/windows/fbx_windows.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,16 @@ $sha1 = "3690400625672bef6369bcf90dcde4d78b493b24"
#$targetFile = "C:\Windows\Temp\$packageName"
$targetFolder = "C:\Program Files\"

#echo "Downloading '$installerName'"
#Write-Host "Downloading '$installerName'"
#Download $officialUrl $cacheUrl $targetFile
#Verify-Checksum $targetFile $sha1

echo "Extracting '$cacheUrl'"
#Extract-7Zip $cacheUrl $targetFolder
Start-Process -FilePath "C:\Utils\sevenzip\7z.exe" -ArgumentList "x -y `"$cacheUrl`" -o`"$targetFolder`"" -Wait
Write-Host "Extracting '$cacheUrl'"
Extract-7Zip $cacheUrl $targetFolder

#Remove-Item -Recurse -Force "$packageName"

echo "Adding environment variables."
[Environment]::SetEnvironmentVariable("FBXSDK", "$targetFolder\Autodesk\FBX\FBX SDK\2016.1.2", [EnvironmentVariableTarget]::Machine)
Set-EnvironmentVariable "FBXSDK" "$targetFolder\Autodesk\FBX\FBX SDK\2016.1.2"

echo "FBX SDK = $version" >> ~\versions.txt
Write-Output "FBX SDK = $version" >> ~\versions.txt

Loading

0 comments on commit cb6709c

Please sign in to comment.