[glib/wip/xclaesse/ci-windows-docker] ci: Add Windows Dockerfile



commit 03cb8291934d5597889baa56cacfbd08d94c673a
Author: Xavier Claessens <xavier claessens collabora com>
Date:   Mon Jan 13 17:04:20 2020 -0500

    ci: Add Windows Dockerfile
    
    This is copied from GStreamer project, which was in turn copied from a
    GLib patch I did earlier.

 .gitlab-ci.yml                           | 18 ++++++++++++++++--
 .gitlab-ci/test-msvc.bat                 | 24 ------------------------
 .gitlab-ci/windows/Dockerfile            | 16 ++++++++++++++++
 .gitlab-ci/windows/cache-subprojects.ps1 | 12 ++++++++++++
 .gitlab-ci/windows/install_choco.ps1     |  2 ++
 .gitlab-ci/windows/install_toolchain.ps1 | 19 +++++++++++++++++++
 6 files changed, 65 insertions(+), 26 deletions(-)
---
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 0a4d1f58d..b82bd96bd 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -14,6 +14,7 @@ variables:
   DEBIAN_IMAGE: "registry.gitlab.gnome.org/gnome/glib/debian-stable:v6"
   ANDROID_IMAGE: "registry.gitlab.gnome.org/gnome/glib/android-ndk:v2"
   MINGW_IMAGE: "registry.gitlab.gnome.org/gnome/glib/mingw:v2"
+  WINDOWS_IMAGE: "registry.gitlab.gnome.org/gnome/glib/windows:v2"
   MESON_TEST_TIMEOUT_MULTIPLIER: 2
   G_MESSAGES_DEBUG: all
   MESON_COMMON_OPTIONS: "--buildtype debug --fatal-meson-warnings --wrap-mode=nodownload"
@@ -273,11 +274,24 @@ msys2-mingw32:
 
 vs2017-x64:
   extends: .only-default
+  image: $WINDOWS_IMAGE
   stage: build
   tags:
-    - win32
+    - windows
   script:
-    - .gitlab-ci/test-msvc.bat
+    # Make sure powershell exists on errors
+    # 
https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_preference_variables?view=powershell-6
+    - $ErrorActionPreference = "Stop"
+    - cp -r C:/subprojects/* subprojects/
+    # For some reason, options are separated by newline instead of space, so we
+    # have to replace them first.
+    - $env:MESON_COMMON_OPTIONS = $env:MESON_COMMON_OPTIONS.replace("`n"," ")
+    # Gitlab executes PowerShell in docker, but VsDevCmd.bat is a batch script.
+    # Environment variables substitutions is done by PowerShell before calling
+    # cmd.exe, that's why we use $env:FOO instead of %FOO%
+    - cmd.exe /C "C:\BuildTools\Common7\Tools\VsDevCmd.bat -host_arch=amd64 -arch=$env:ARCH &&
+        meson build $env:MESON_COMMON_OPTIONS &&
+        ninja -C build"
   artifacts:
     reports:
       junit: "_build/%CI_JOB_NAME%-report.xml"
diff --git a/.gitlab-ci/windows/Dockerfile b/.gitlab-ci/windows/Dockerfile
new file mode 100644
index 000000000..8e7d0b767
--- /dev/null
+++ b/.gitlab-ci/windows/Dockerfile
@@ -0,0 +1,16 @@
+# escape=`
+
+FROM 'mcr.microsoft.com/windows/servercore:1809'
+
+# Make sure any failure in PowerShell scripts is fatal
+SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop';"]
+ENV ErrorActionPreference='Stop'
+
+COPY install_choco.ps1 C:\
+RUN C:\install_choco.ps1
+
+COPY install_toolchain.ps1 C:\
+RUN C:\install_toolchain.ps1
+
+COPY cache-subprojects.ps1 C:\
+RUN C:\cache-subprojects.ps1
diff --git a/.gitlab-ci/windows/cache-subprojects.ps1 b/.gitlab-ci/windows/cache-subprojects.ps1
new file mode 100644
index 000000000..42f00ee50
--- /dev/null
+++ b/.gitlab-ci/windows/cache-subprojects.ps1
@@ -0,0 +1,12 @@
+[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12;
+
+# FIXME: Python fails to validate github.com SSL certificate, unless we first
+# run a dummy download to force refreshing Windows' CA database.
+# See: https://bugs.python.org/issue36137
+(New-Object System.Net.WebClient).DownloadString("https://github.com";) >$null
+
+git clone https://gitlab.gnome.org/GNOME/glib.git
+meson subprojects download --sourcedir glib
+Remove-Item -Force 'glib/subprojects/*.wrap'
+Move-Item glib/subprojects C:\subprojects
+Remove-Item -Recurse -Force glib
diff --git a/.gitlab-ci/windows/install_choco.ps1 b/.gitlab-ci/windows/install_choco.ps1
new file mode 100644
index 000000000..7bd7fa18e
--- /dev/null
+++ b/.gitlab-ci/windows/install_choco.ps1
@@ -0,0 +1,2 @@
+iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
+choco install -y git git-lfs python3 7zip
diff --git a/.gitlab-ci/windows/install_toolchain.ps1 b/.gitlab-ci/windows/install_toolchain.ps1
new file mode 100644
index 000000000..0b3ce597b
--- /dev/null
+++ b/.gitlab-ci/windows/install_toolchain.ps1
@@ -0,0 +1,19 @@
+[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12;
+
+$msvc_2017_url = 'https://aka.ms/vs/15/release/vs_buildtools.exe'
+$msys_url = 'https://ayera.dl.sourceforge.net/project/msys2/Base/x86_64/msys2-base-x86_64-20180531.tar.xz'
+
+Write-Host "Installing VisualStudio"
+Invoke-WebRequest -Uri $msvc_2017_url -OutFile C:\vs_buildtools.exe
+Start-Process C:\vs_buildtools.exe -ArgumentList '--quiet --wait --norestart --nocache --installPath 
C:\BuildTools --add Microsoft.VisualStudio.Workload.VCTools --includeRecommended' -Wait
+Remove-Item C:\vs_buildtools.exe -Force
+
+Write-Host "Installing MSYS2"
+Invoke-WebRequest -Uri $msys_url -OutFile C:\msys2-x86_64.tar.xz
+7z e C:\msys2-x86_64.tar.xz -Wait
+7z x C:\msys2-x86_64.tar -o"C:\\"
+Remove-Item C:\msys2-x86_64.tar.xz -Force
+Remove-Item C:\msys2-x86_64.tar -Force
+
+Write-Host "Installing Meson"
+pip install meson==0.49.2


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]