Commit d8e85d57ad0e681a78a7d2a98f6ba425143a41f6

Patrick Steinhardt 2019-06-27T15:01:24

azure: fix building in MinGW via Bash Azure Pipelines supports bash tasks on Windows hosts due to it always having Git for Windows included. To support this, the Git for Window directory is added to the PATH environment to make the bash shell available for execution. Unfortunately, this breaks CMake with the MinGW generator, as it has sanity checks to verify that no bash executable is in the PATH. So we can either remove Git for Windows from the path, but then we're unable to execute bash jobs. Or we can add it to the path, but then we're unable to execute CMake with the MinGW generator. Let's re-model how we set the PATH environment. Instead of setting up PATH for the complete build job, we now set a variable "BUILD_PATH" for the job. This variable is only being used when executing CMake so that it encounters a sanitizied PATH environment without GfW's bash shell.

diff --git a/azure-pipelines.yml b/azure-pipelines.yml
index 397e377..7f491e0 100644
--- a/azure-pipelines.yml
+++ b/azure-pipelines.yml
@@ -99,8 +99,8 @@ jobs:
   - template: azure-pipelines/powershell.yml
     parameters:
       environmentVariables:
+        BUILD_PATH: $(Agent.TempDirectory)\mingw64\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Program Files (x86)\CMake\bin
         CMAKE_OPTIONS: -G"MinGW Makefiles" -DDEPRECATE_HARD=ON
-        PATH: $(Agent.TempDirectory)\mingw64\bin;C:\ProgramData\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\CMake\bin
 
 - job: windows_mingw_x86
   displayName: 'Windows (x86; MinGW)'
@@ -115,8 +115,8 @@ jobs:
   - template: azure-pipelines/powershell.yml
     parameters:
       environmentVariables:
+        BUILD_PATH: $(Agent.TempDirectory)\mingw32\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Program Files (x86)\CMake\bin
         CMAKE_OPTIONS: -G"MinGW Makefiles" -DDEPRECATE_HARD=ON
-        PATH: $(Agent.TempDirectory)\mingw32\bin;C:\ProgramData\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\CMake\bin
 
 - job: documentation
   displayName: 'Generate Documentation'
diff --git a/azure-pipelines/build.sh b/azure-pipelines/build.sh
index 7ffa610..319666b 100755
--- a/azure-pipelines/build.sh
+++ b/azure-pipelines/build.sh
@@ -9,7 +9,9 @@ set -e
 
 SOURCE_DIR=${SOURCE_DIR:-$( cd "$( dirname "${BASH_SOURCE[0]}" )" && dirname $( pwd ) )}
 BUILD_DIR=$(pwd)
+BUILD_PATH=${BUILD_PATH:=$PATH}
 CC=${CC:-cc}
+CMAKE=$(which cmake)
 
 indent() { sed "s/^/    /"; }
 
@@ -31,7 +33,7 @@ echo "Kernel version:"
 uname -a 2>&1 | indent
 
 echo "CMake version:"
-cmake --version 2>&1 | indent
+env PATH="$BUILD_PATH" "$CMAKE" --version 2>&1 | indent
 echo "Compiler version:"
 $CC --version 2>&1 | indent
 echo ""
@@ -41,11 +43,11 @@ echo "## Configuring build environment"
 echo "##############################################################################"
 
 echo cmake ${SOURCE_DIR} -DENABLE_WERROR=ON -DBUILD_EXAMPLES=ON -DBUILD_FUZZERS=ON -DUSE_STANDALONE_FUZZERS=ON ${CMAKE_OPTIONS}
-cmake ${SOURCE_DIR} -DENABLE_WERROR=ON -DBUILD_EXAMPLES=ON -DBUILD_FUZZERS=ON -DUSE_STANDALONE_FUZZERS=ON ${CMAKE_OPTIONS}
+env PATH="$BUILD_PATH" "$CMAKE" ${SOURCE_DIR} -DENABLE_WERROR=ON -DBUILD_EXAMPLES=ON -DBUILD_FUZZERS=ON -DUSE_STANDALONE_FUZZERS=ON ${CMAKE_OPTIONS}
 
 echo ""
 echo "##############################################################################"
 echo "## Building libgit2"
 echo "##############################################################################"
 
-cmake --build .
+env PATH="$BUILD_PATH" "$CMAKE" --build .
diff --git a/azure-pipelines/nightly.yml b/azure-pipelines/nightly.yml
index 8b2868f..78e93f6 100644
--- a/azure-pipelines/nightly.yml
+++ b/azure-pipelines/nightly.yml
@@ -102,8 +102,8 @@ jobs:
   - template: powershell.yml
     parameters:
       environmentVariables:
+        BUILD_PATH: $(Agent.TempDirectory)\mingw64\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Program Files (x86)\CMake\bin
         CMAKE_OPTIONS: -G"MinGW Makefiles" -DDEPRECATE_HARD=ON
-        PATH: $(Agent.TempDirectory)\mingw64\bin;C:\ProgramData\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\CMake\bin
         RUN_INVASIVE_TESTS: true
 
 - job: windows_mingw_x86
@@ -119,8 +119,8 @@ jobs:
   - template: powershell.yml
     parameters:
       environmentVariables:
+        BUILD_PATH: $(Agent.TempDirectory)\mingw32\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Program Files (x86)\CMake\bin
         CMAKE_OPTIONS: -G"MinGW Makefiles" -DDEPRECATE_HARD=ON
-        PATH: $(Agent.TempDirectory)\mingw32\bin;C:\ProgramData\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\CMake\bin
         RUN_INVASIVE_TESTS: true
 
 - job: linux_x86_bionic_gcc_openssl