Skip to content
Snippets Groups Projects
Commit da29895a authored by Andreas Traczyk's avatar Andreas Traczyk
Browse files

misc: refactor windows build dependency powershell script

- Rename the script to better reflect its purpose
- Don't install the chocolatey package manager if already installed
- Don't install packages if already installed
- Clean up error management

Gitlab: #581
Change-Id: I0e6fdeacfd465ae3810cfcfd7af21755e4f3ec1e
parent 6744192f
No related branches found
No related tags found
No related merge requests found
......@@ -204,7 +204,7 @@ def run_dependencies(args):
if args.distribution == WIN32_DISTRIBUTION_NAME:
run_powersell_cmd(
'Set-ExecutionPolicy Unrestricted; .\\scripts\\build-package-windows.ps1')
'Set-ExecutionPolicy Unrestricted; .\\scripts\\install-deps-windows.ps1')
elif args.distribution in APT_BASED_DISTROS:
execute_script(
......
# Install Choco
<#
This script should install dependencies required for building the Jami
Qt client on windows.
Set-ExecutionPolicy Bypass -Scope Process -Force
iex ((New-Object System.Net.WebClient).DownloadString("https://chocolatey.org/install.ps1"))
if( $LASTEXITCODE -eq 0 ) {
write-host "Choco Installation Succeeded" -ForegroundColor Green
} else {
write-host "Choco Installation Failed" -ForegroundColor Red
exit $LASTEXITCODE
}
Required components not installed:
- Visual Studio
- build toolchains
- SDKs
- WiX + WiX Visual Studio extension
- Qt + Qt Visual Studio extension
#>
# Install 7zip, unzip, wget --version 1.19.4, cmake, git --version 2.10.2
# pandoc, strawberryperl, msys2
# Note that: msys2 installes at C:/tools/msys64
write-host "Installing jami-qt build dependencies for windows…" -ForegroundColor Green
Function choco_pack_install($packages) {
Set-ExecutionPolicy Bypass -Scope Process -Force
Foreach ($i in $packages){
if($i -eq 'wget'){
iex ("choco install -fy --allow-downgrade '$i' --version 1.19.4 --acceptlicense")
} elseif ($i -eq 'git.install') {
iex ("choco install -fy --allow-downgrade '$i' --version 2.10.2 --acceptlicense")
} else {
iex ("choco install -fy '$i' --acceptlicense")
}
if( $LASTEXITCODE -ne 0 ) {
write-host "Choco Packages Installation Failed" -ForegroundColor Red
exit 1
$global:installed_packages = $null
Function choco_check_package([String] $package, [String] $version = "") {
# Query a package listing once
if ($null -eq $global:installed_packages) {
write-host "Getting installed package list from Chocolatey…" -ForegroundColor DarkCyan
$global:installed_packages = choco list -lo
}
# Check installed packages
$result = $global:installed_packages | Where-object {
$_.ToLower().StartsWith($package.ToLower())
}
if ($null -eq $result) {
# We don't have the package
write-host $package "not found." -ForegroundColor Yellow
return $false
}
if ("" -eq $version) {
# We have the package and don't care what version it is
write-host $package "found." -ForegroundColor Cyan
return $true
}
# We now check the results for a package of the specified version
$parts = $result.Split(' ')
Foreach ($part in $parts) {
if ($part -eq $version) {
# We have the package of the specified version
write-host $package $version "found." -ForegroundColor Cyan
return $true
}
}
write-host "Choco Packages Installation Succeeded" -ForegroundColor Green
}
$packages = [System.Collections.Generic.List[System.Object]]('wget', 'git.install', '7zip', 'unzip', 'cmake', 'pandoc', 'strawberryperl', 'msys2')
if(Test-Path -Path "C:\Program Files\CMake\bin"){
# file with path $path does exist
$null = $packages.Remove('cmake')
write-host "Cmake installed" -ForegroundColor Green
# We don't have the package of the specified version
write-host $package $version "not found." -ForegroundColor Yellow
return $false
}
if(Test-Path -Path "C:\Strawberry"){
$null = $packages.Remove('strawberryperl')
write-host "Strawberry Perl installed" -ForegroundColor Green
Function install_chocolatey {
# Install Chocolatey if not installed already
if (!(Test-Path "$($env:ProgramData)\chocolatey\choco.exe")) {
Invoke-Expression ((New-Object System.Net.WebClient).DownloadString("https://chocolatey.org/install.ps1"))
if ( $LASTEXITCODE -eq 0 ) {
write-host "Chocolatey installation succeeded" -ForegroundColor Green
}
else {
write-host "Chocolatey installation failed" -ForegroundColor Red
exit $LASTEXITCODE
}
}
else {
write-host "Chocolatey already installed" -ForegroundColor DarkGreen
}
}
if(!(Test-Path -Path "C:\msys64")){
$Env:Path += ";C:\tools\msys64\usr\bin"
$msys2_path = "C:\tools\msys64\usr\bin"
if((Test-Path -Path "C:\tools\msys64")){
$null = $packages.Remove('msys2')
write-host "MSYS2 64 installed" -ForegroundColor Green
Function choco_install_package([String] $package, [String] $version = "") {
$package_installed = choco_check_package $package $version
if ($true -eq $package_installed) {
return
}
if ("" -ne $version) {
write-host "Installing" $package "@" $version
choco install -fy --allow-downgrade $package --version $version --acceptlicense
}
else {
write-host "Installing" $package
choco install -fy --allow-downgrade $package --acceptlicense
}
if ( $LASTEXITCODE -ne 0 ) {
write-host "Choco Packages Installation Failed" -ForegroundColor Red
exit 1
}
} else {
$null = $packages.Remove('msys2')
write-host "MSYS2 64 installed" -ForegroundColor Green
$Env:Path += ";C:\msys64\usr\bin"
$msys2_path = "C:\msys64\usr\bin"
}
choco_pack_install($packages)
# Web installed msys2_64 bit to install make, gcc, perl, diffutils
Function pacman_pack_install($packages) {
Foreach ($i in $packages){
iex ("pacman -S '$i' --noconfirm")
if( $LASTEXITCODE -ne 0 ) {
write-host "Pacman Packages Installation Failed" -ForegroundColor Red
exit 1
}
Function install_choco_packages($packages) {
Foreach ($i in $packages) {
choco_install_package $i.pkg $i.ver
}
write-host "Pacman Packages Installation Succeeded" -ForegroundColor Green
write-host "Choco Packages Installation Succeeded" -ForegroundColor Green
}
$packages = [System.Collections.Generic.List[System.Object]]('make', 'gcc', 'perl', 'diffutils')
pacman_pack_install($packages)
# Web Download VSNASM, VSYASM
Function download_file_to_temp($download_name, $url, $output_name) {
write-host "Downloading $download_name" -ForegroundColor Yellow
write-host "Downloading $download_name" -ForegroundColor DarkCyan
$output = $env:TEMP + "\$output_name"
(New-Object System.Net.WebClient).DownloadFile($url, $output)
if( $LASTEXITCODE -eq 0 ) {
if ( $LASTEXITCODE -eq 0 ) {
write-host "Download $download_name Succeeded" -ForegroundColor Green
} else {
}
else {
write-host "Download $download_name Failed" -ForegroundColor Red
exit $LASTEXITCODE
}
}
download_file_to_temp 'VSNASM' "https://github.com/ShiftMediaProject/VSNASM/releases/download/0.5/VSNASM.zip" 'VSNASM.zip'
download_file_to_temp 'VSYASM' "https://github.com/ShiftMediaProject/VSYASM/releases/download/0.4/VSYASM.zip" 'VSYASM.zip'
# Unzip VSNASM.zip, VSYASM.zip
Function unzip_file_from_temp($unzip_name, $zip_file_name, $unzip_file_output_name) {
write-host "Unzip $unzip_name" -ForegroundColor Yellow
write-host "Unzipping $unzip_name" -ForegroundColor DarkCyan
$zip_path = $env:TEMP + "\$zip_file_name"
$unzip_path = $env:TEMP + "\$unzip_file_output_name"
iex("unzip -o $zip_path -d $unzip_path")
if( $LASTEXITCODE -eq 0 ) {
Invoke-Expression("unzip -o $zip_path -d '$unzip_path'") | Out-Null
if ( $LASTEXITCODE -eq 0 ) {
write-host "Unzip $unzip_name Succeeded" -ForegroundColor Green
} else {
}
else {
write-host "Unzip $unzip_name Failed" -ForegroundColor Red
exit $LASTEXITCODE
}
}
unzip_file_from_temp 'VSNASM' 'VSNASM.zip' 'VSNASM_UNZIP'
unzip_file_from_temp 'VSYASM' 'VSYASM.zip' 'VSYASM_UNZIP'
# Generate nasm(VS), yasm.exe (VS)
Function run_batch($batch_cmd, $task_desp) {
write-host $task_desp -ForegroundColor Yellow
Start-Process "cmd.exe" $batch_cmd -Wait -NoNewWindow
if( $LASTEXITCODE -eq 0 ) {
write-host "$task_desp Succeeded" -ForegroundColor Green
} else {
write-host "$task_desp Failed" -ForegroundColor Red
Function run_batch($batch_cmd, $task_name) {
write-host $task_name -ForegroundColor DarkCyan
Start-Process "cmd.exe" $batch_cmd -Wait -NoNewWindow | Out-Null
if ( $LASTEXITCODE -eq 0 ) {
write-host "$task_name Succeeded" -ForegroundColor Green
}
else {
write-host "$task_name Failed" -ForegroundColor Red
exit $LASTEXITCODE
}
}
$batch_path = "/c set ISINSTANCE=1 && " + $env:TEMP + "\VSNASM_UNZIP\install_script.bat"
run_batch $batch_path "Generate nasm(VS)"
$batch_path = "/c set ISINSTANCE=1 &&" + $env:TEMP + "\VSYASM_UNZIP\install_script.bat"
run_batch $batch_path "Generate yasm(VS)"
Function move_file_from_temp_to_msys64($file_name, $task_name) {
write-host $task_name -ForegroundColor DarkCyan
$file_path = $env:TEMP + "\$file_name"
Move-item -Path $file_path -Destination $msys2_path -Force
if ($LASTEXITCODE -eq 0) {
write-host "$task_name Succeeded" -ForegroundColor Green
}
else {
write-host "$task_name Failed" -ForegroundColor Red
exit $LASTEXITCODE
}
}
# Web Download gas-preprocessor.pl, yasm.exe (win64)
Function install_msys2_packages($packages) {
Foreach ($i in $packages) {
Invoke-Expression ("pacman -Q '$i'") | out-null
if ($LASTEXITCODE -eq 0) {
write-host $i "already installed" -ForegroundColor Cyan
continue
}
Invoke-Expression ("pacman -S '$i' --noconfirm")
if ($LASTEXITCODE -ne 0) {
write-host "Pacman Packages Installation Failed" -ForegroundColor Red
exit 1
}
}
write-host "Pacman Packages Installation Succeeded" -ForegroundColor Green
}
download_file_to_temp 'yasm.exe (win64)' "http://www.tortall.net/projects/yasm/releases/yasm-1.3.0-win64.exe" 'yasm.exe'
download_file_to_temp 'gas-preprocessor.pl' "https://github.com/FFmpeg/gas-preprocessor/blob/master/gas-preprocessor.pl" 'gas-preprocessor.pl'
# Web installed msys2_64 bit to install make, gcc, perl, diffutils
$msys_packages = @("make", "gcc", "perl", "diffutils")
# Install 7zip, unzip, wget --version 1.19.4, cmake, git --version 2.10.2, pandoc, strawberryperl, msys2
$choco_packages = @(
[pscustomobject]@{pkg = "wget"; ver = "1.19.4" }
[pscustomobject]@{pkg = "git.install"; ver = "2.10.2" }
[pscustomobject]@{pkg = "7zip"; ver = "" }
[pscustomobject]@{pkg = "unzip"; ver = "" }
[pscustomobject]@{pkg = "cmake"; ver = "" }
[pscustomobject]@{pkg = "pandoc"; ver = "" }
[pscustomobject]@{pkg = "strawberryperl"; ver = "" }
[pscustomobject]@{pkg = "msys2"; ver = "" }
)
install_chocolatey
# Check for an existing msys2 install
# Note that choco installs msys2 in C:/tools/
if (!(Test-Path -Path "C:\msys64")) {
$Env:Path += ";C:\tools\msys64\usr\bin"
$msys2_path = "C:\tools\msys64\usr\bin"
if ((Test-Path -Path "C:\tools\msys64")) {
write-host "MSYS2 64 already installed" -ForegroundColor Green
}
else {
$choco_packages.Add([pscustomobject]@{pkg = "msys2"; ver = "" })
}
}
else {
write-host "MSYS2 64 already installed" -ForegroundColor Green
$Env:Path += ";C:\msys64\usr\bin"
$msys2_path = "C:\msys64\usr\bin"
}
# Move gas-preprocessor.pl, yasm.exe into msys64
install_choco_packages $choco_packages
install_msys2_packages $msys_packages
Function move_file_from_temp_to_msys64($file_name, $task_desp) {
# Install VSNASM
download_file_to_temp 'VSNASM' "https://github.com/ShiftMediaProject/VSNASM/releases/download/0.5/VSNASM.zip" 'VSNASM.zip'
unzip_file_from_temp 'VSNASM' 'VSNASM.zip' 'VSNASM_UNZIP'
$batch_path = "/c set ISINSTANCE=1 &&" + $env:TEMP + "\VSNASM_UNZIP\install_script.bat"
run_batch $batch_path "Install VSNASM"
write-host $task_desp -ForegroundColor Yellow
$file_path = $env:TEMP + "\$file_name"
Move-item -Path $file_path -Destination $msys2_path -Force
# Install VSYASM
download_file_to_temp 'VSYASM' "https://github.com/ShiftMediaProject/VSYASM/releases/download/0.4/VSYASM.zip" 'VSYASM.zip'
unzip_file_from_temp 'VSYASM' 'VSYASM.zip' 'VSYASM_UNZIP'
$batch_path = "/c set ISINSTANCE=1 &&" + $env:TEMP + "\VSYASM_UNZIP\install_script.bat"
run_batch $batch_path "Install VSYASM"
if( $LASTEXITCODE -eq 0 ) {
write-host "$task_desp Succeeded" -ForegroundColor Green
} else {
write-host "$task_desp Failed" -ForegroundColor Red
exit $LASTEXITCODE
}
}
# Install yasm.exe (win64)
download_file_to_temp 'yasm.exe (win64)' "http://www.tortall.net/projects/yasm/releases/yasm-1.3.0-win64.exe" 'yasm.exe'
move_file_from_temp_to_msys64 'yasm.exe' 'Move yasm.exe (win64) to msys64 folder'
# Install gas-preprocessor.pl
download_file_to_temp 'gas-preprocessor.pl' "https://github.com/FFmpeg/gas-preprocessor/blob/master/gas-preprocessor.pl" 'gas-preprocessor.pl'
move_file_from_temp_to_msys64 'gas-preprocessor.pl' 'Move gas-preprocessor.pl to msys64 folder'
move_file_from_temp_to_msys64 'yasm.exe' 'Move yasm.exe (win64) to msys64 folder'
write-host "Dependencies Built Finished" -ForegroundColor Green
\ No newline at end of file
write-host "Done" -ForegroundColor Green
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment