From 39908c2b7eb2cf87f63ef2275764f585055a6cb4 Mon Sep 17 00:00:00 2001 From: Vladimir Safonkin Date: Thu, 26 Mar 2020 18:48:18 +0300 Subject: [PATCH] Add msys2 installation and validation --- images/win/Windows2016-Azure.json | 14 ++++ images/win/Windows2019-Azure.json | 14 ++++ .../win/scripts/Installers/Install-Msys2.ps1 | 76 +++++++++++++++++++ .../win/scripts/Installers/Validate-Msys2.ps1 | 73 ++++++++++++++++++ 4 files changed, 177 insertions(+) create mode 100644 images/win/scripts/Installers/Install-Msys2.ps1 create mode 100644 images/win/scripts/Installers/Validate-Msys2.ps1 diff --git a/images/win/Windows2016-Azure.json b/images/win/Windows2016-Azure.json index e0bf37f50370..dc563c7e1a89 100644 --- a/images/win/Windows2016-Azure.json +++ b/images/win/Windows2016-Azure.json @@ -491,6 +491,14 @@ "{{ template_dir }}/scripts/Installers/Install-AzureModules.ps1" ] }, + { + "type": "powershell", + "elevated_user": "SYSTEM", + "elevated_password": "", + "scripts":[ + "{{ template_dir }}/scripts/Installers/Install-Msys2.ps1" + ] + }, { "type": "powershell", "scripts":[ @@ -612,6 +620,12 @@ "{{ template_dir }}/scripts/Installers/Validate-AzureDevOpsCli.ps1" ] }, + { + "type": "powershell", + "scripts":[ + "{{ template_dir }}/scripts/Installers/Validate-Msys2.ps1" + ] + }, { "type": "powershell", "environment_vars":[ diff --git a/images/win/Windows2019-Azure.json b/images/win/Windows2019-Azure.json index c93f79e75642..022bb5ce8204 100644 --- a/images/win/Windows2019-Azure.json +++ b/images/win/Windows2019-Azure.json @@ -472,6 +472,14 @@ "{{ template_dir }}/scripts/Installers/Install-AzureModules.ps1" ] }, + { + "type": "powershell", + "elevated_user": "SYSTEM", + "elevated_password": "", + "scripts":[ + "{{ template_dir }}/scripts/Installers/Install-Msys2.ps1" + ] + }, { "type": "powershell", "scripts":[ @@ -599,6 +607,12 @@ "{{ template_dir }}/scripts/Installers/Validate-AzureDevOpsCli.ps1" ] }, + { + "type": "powershell", + "scripts":[ + "{{ template_dir }}/scripts/Installers/Validate-Msys2.ps1" + ] + }, { "type": "powershell", "environment_vars":[ diff --git a/images/win/scripts/Installers/Install-Msys2.ps1 b/images/win/scripts/Installers/Install-Msys2.ps1 new file mode 100644 index 000000000000..49f75e430a1f --- /dev/null +++ b/images/win/scripts/Installers/Install-Msys2.ps1 @@ -0,0 +1,76 @@ +################################################################################ +## File: Install-Msys2.ps1 +## Desc: Install Msys2 and 64-bit gcc, cmake, & llvm (32-bit commented out) +################################################################################ + +# References +# https://github.com/msys2/MINGW-packages/blob/master/azure-pipelines.yml +# https://packages.msys2.org/group/ + +$origPath = $env:PATH +$gitPath = "$env:ProgramFiles\Git" + +# get info from https://sourceforge.net/projects/msys2/files/Base/x86_64/ +$msys2Uri = "http://repo.msys2.org/distrib/x86_64/msys2-base-x86_64-20190524.tar.xz" +$msys2File = "$env:TEMP\msys2.tar.xz" + +# Download the latest msys2 x86_64 +Write-Host "Starting msys2 download" +(New-Object System.Net.WebClient).DownloadFile($msys2Uri, $msys2File) +Write-Host "Finished download" + +$msys2FileU = "/$msys2File".replace(':', '') + +$tar = "$gitPath\usr\bin\tar.exe" + +# extract tar.xz to C:\ +Write-Host "Starting msys2 extraction" +&$tar -Jxf $msys2FileU -C /c/ +Remove-Item $msys2File +Write-Host "Finished extraction" + +# Add msys2 bin tools folders to PATH temporary +$env:PATH = "C:\msys64\mingw64\bin;C:\msys64\usr\bin;$origPath" + +Write-Host "bash pacman-key --init" +bash.exe -c "pacman-key --init 2>&1" + +Write-Host "bash pacman-key --populate msys2" +bash.exe -c "pacman-key --populate msys2 2>&1" + +Write-Host "pacman --noconfirm -Syyuu" +pacman.exe -Syyuu --noconfirm +pacman.exe -Syuu --noconfirm + +Write-Host "Install msys2 packages" +pacman.exe -S --noconfirm --needed --noprogressbar base-devel compression + +# mingw package list +$tools = "___clang ___cmake ___llvm ___toolchain ___ragel" + +# install mingw64 packages +Write-Host "Install mingw64 packages" +$pre = "mingw-w64-x86_64-" +pacman.exe -S --noconfirm --needed --noprogressbar $tools.replace('___', $pre).split(' ') + +# install mingw32 packages +Write-Host "Install mingw32 packages" +$pre = "mingw-w64-i686-" +pacman.exe -S --noconfirm --needed --noprogressbar $tools.replace('___', $pre).split(' ') + +# clean all packages to decrease image size +Write-Host "Clean packages" +pacman.exe -Scc --noconfirm + +Write-Host "Installed mingw64 packages" +pacman.exe -Qs --noconfirm mingw-w64-x86_64- + +Write-Host "Installed mingw32 packages" +pacman.exe -Qs --noconfirm mingw-w64-i686- + +Write-Host "Installed msys2 packages" +pacman.exe -Qs --noconfirm + +Write-Host "MSYS2 installation completed" + +exit 0 \ No newline at end of file diff --git a/images/win/scripts/Installers/Validate-Msys2.ps1 b/images/win/scripts/Installers/Validate-Msys2.ps1 new file mode 100644 index 000000000000..e7d2142a8d0c --- /dev/null +++ b/images/win/scripts/Installers/Validate-Msys2.ps1 @@ -0,0 +1,73 @@ +################################################################################ +## File: Validate-Msys2.ps1 +## Desc: Validate Msys2 +################################################################################ + +$msys2BinDir = "C:\msys64\usr\bin" +$msys2mingwDir = "C:\msys64\mingw64\bin" + +$installedTools = @( + "bash", + "tar", + "make" +) + +$installedMinGWTools = @( + "gcc", + "cmake" +) + +Write-Host "Check installed tools in msys2/usr/bin directory" +$installedTools | ForEach-Object { + $toolName = $_ + try { + Invoke-Expression "$msys2BinDir\$_ --version" + } catch { + Write-Host "$toolName was not installed in MSYS2 bin directory" + Write-Error $_ + exit 1 + } +} + +Write-Host "Check installed tools in msys2/mingw/bin directory" +$installedMinGWTools | ForEach-Object { + $toolName = $_ + try { + Invoke-Expression "$msys2mingwDir\$_ --version" + } catch { + Write-Error "$toolName was not installed in MSYS2 mingw bin directory" + Write-Error $_ + exit 1 + } +} + +# Adding description of the software to Markdown + +function Get-ToolVersion { + param( + [string] $ToolPath, + [int] $VersionLineNumber + ) + + $toolRawVersion = Invoke-Expression "$ToolPath --version" + $toolRawVersion.Split([System.Environment]::NewLine)[$VersionLineNumber] -match "\d+\.\d+(\.\d+)?" | Out-Null + $toolVersion = $matches[0] + return $toolVersion +} + +$SoftwareName = "MSYS2" +$pacmanVersion = Get-ToolVersion -ToolPath "$msys2BinDir/pacman" -VersionLineNumber 1 +$bashVersion = Get-ToolVersion -ToolPath "$msys2BinDir/bash" -VersionLineNumber 0 +$gccVersion = Get-ToolVersion -ToolPath "$msys2mingwDir/gcc" -VersionLineNumber 0 +$tarVersion = Get-ToolVersion -ToolPath "$msys2BinDir/tar" -VersionLineNumber 0 + +$Description = @" +_Tool versions_ +_pacman:_ $pacmanVersion
+_bash:_ $bashVersion
+_gcc:_ $gccVersion
+_tar:_ $tarVersion
+MSYS2 location: C:\msys64 +"@ + +Add-SoftwareDetailsToMarkdown -SoftwareName $SoftwareName -DescriptionMarkdown $Description