From 49a49939827dde731f513d334e53e1f56be44b5f Mon Sep 17 00:00:00 2001
From: Justin Pryzby <pryzbyj@telsasoft.com>
Date: Thu, 28 Jul 2022 10:57:26 -0500
Subject: [PATCH 2/2] f!

ci-os-only: mingw
---
 .cirrus.yml                     | 31 +++++++++++++++++++++++--------
 config/prep_buildtree           | 20 ++++++++------------
 src/tools/ci/cores_backtrace.sh | 17 +++++++++++++++--
 3 files changed, 46 insertions(+), 22 deletions(-)

diff --git a/.cirrus.yml b/.cirrus.yml
index 472661c0936..b51a625d210 100644
--- a/.cirrus.yml
+++ b/.cirrus.yml
@@ -34,6 +34,7 @@ on_failure: &on_failure
       - "**/*.log"
       - "**/*.diffs"
       - "**/regress_log_*"
+      - "**/*.stackdump"
     type: text/plain
 
 task:
@@ -349,8 +350,6 @@ WINDOWS_ENVIRONMENT_BASE: &WINDOWS_ENVIRONMENT_BASE
       # Avoids port conflicts between concurrent tap test runs
       PG_TEST_USE_UNIX_SOCKETS: 1
 
-    only_if: $CIRRUS_CHANGE_MESSAGE !=~ '.*\nci-os-only:.*' || $CIRRUS_CHANGE_MESSAGE =~ '.*\nci-os-only:[^\n]*windows.*'
-
     sysinfo_script: |
       chcp
       systeminfo
@@ -361,6 +360,8 @@ task:
   << : *WINDOWS_ENVIRONMENT_BASE
   name: Windows - Server 2019, VS 2019
 
+  only_if: $CIRRUS_CHANGE_MESSAGE !=~ '.*\nci-os-only:.*' || $CIRRUS_CHANGE_MESSAGE =~ '.*\nci-os-only:[^\n]*windows.*'
+
   env:
     # Our windows infrastructure doesn't have test concurrency above the level
     # of a single vcregress test target. Due to that, it's useful to run prove
@@ -484,6 +485,8 @@ task:
 task:
   << : *WINDOWS_ENVIRONMENT_BASE
   name: Windows - Server 2019, MinGW64
+  #XXX only_if: $CIRRUS_CHANGE_MESSAGE =~ '.*\nci-os-only:[^\n]*mingw.*'
+
   windows_container:
     image: $CONTAINER_REPO/windows_ci_mingw64:latest
     cpu: $CPUS
@@ -495,6 +498,10 @@ task:
   ccache_cache:
     folder: ${CCACHE_DIR}
 
+  setup_additional_packages_script: |
+    REM choco install -y --no-progress ...
+    REM C:\msys64\usr\bin\pacman.exe -S --noconfirm busybox
+
   mingw_info_script:
     - C:\msys64\usr\bin\dash.exe -lc "where gcc"
     - C:\msys64\usr\bin\dash.exe -lc "gcc --version"
@@ -502,20 +509,25 @@ task:
     - C:\msys64\usr\bin\dash.exe -lc "perl --version"
 
   configure_script:
+    # Try to configure with the cache file, and retry without if it fails, in case the flags changed.
     - C:\msys64\usr\bin\dash.exe -lc "mkdir %BUILD_DIR% &&
-      cd %BUILD_DIR% &&
+      cd %BUILD_DIR% && for i in 1 2; do
       %CIRRUS_WORKING_DIR%/configure
+        --cache-file=${CCACHE_DIR}/configure.cache
         --enable-cassert
+        --enable-debug
         --enable-tap-tests
         --with-icu
         --with-libxml
         --with-libxslt
         --with-lz4
-        --enable-debug
         CC='ccache gcc'
         CXX='ccache g++'
         CFLAGS='-Og -ggdb -pipe'
-        CXXFLAGS='-Og -ggdb'"
+        CXXFLAGS='-Og -ggdb' && break;
+        rm -v ${CCACHE_DIR}/configure.cache;
+        done
+        "
 
   build_script:
     C:\msys64\usr\bin\dash.exe -lc "cd %BUILD_DIR% && make -s world-bin -j${CPUS}"
@@ -523,10 +535,13 @@ task:
   upload_caches: ccache
 
   tests_script:
-  - set "NoDefaultCurrentDirectoryInExePath=0"
-  - C:\msys64\usr\bin\dash.exe -lc "cd %BUILD_DIR% && make -s ${CHECK} ${CHECKFLAGS} -j${CPUS} TMPDIR=%BUILD_DIR%/tmp_install"
+    - set "NoDefaultCurrentDirectoryInExePath=0"
+    - C:\msys64\usr\bin\dash.exe -lc "cd %BUILD_DIR% && make -s ${CHECK} ${CHECKFLAGS} -j${CPUS} TMPDIR=%BUILD_DIR%/tmp_install"
 
-  on_failure: *on_failure
+  on_failure:
+    <<: *on_failure
+    cores_script:
+      - C:\tools\cygwin\bin\dash.exe --login -c "cd '%cd%' && src/tools/ci/cores_backtrace.sh msys ."
 
 task:
   name: CompilerWarnings
diff --git a/config/prep_buildtree b/config/prep_buildtree
index a0eabd3dee2..97bf65967f1 100644
--- a/config/prep_buildtree
+++ b/config/prep_buildtree
@@ -26,20 +26,16 @@ buildtree=`cd ${2:-'.'} && pwd`
 # If we did, it would interfere with installation of prebuilt docs from
 # the source tree, if a VPATH build is done from a distribution tarball.
 # See bug #5595.
-for item in `find "$sourcetree" -type d \( \( -name CVS -prune \) -o \( -name .git -prune \) -o -print \) | grep -v "$sourcetree/doc/src/sgml/\+"`; do
-    subdir=`expr "$item" : "$sourcetree\(.*\)"`
-    if test ! -d "$buildtree/$subdir"; then
-        mkdir -p "$buildtree/$subdir" || exit 1
-    fi
-done
+( cd "$sourcetree" && find . -type d \( \( -name CVS -prune \) -o \( -name .git -prune \) -o -print \) |grep -v "doc/src/sgml/\+" ) |
+	( cd "$buildtree" && xargs mkdir -p )
 
 for item in `find "$sourcetree" -name Makefile -print -o -name GNUmakefile -print | grep -v "$sourcetree/doc/src/sgml/images/"`; do
-    filename=`expr "$item" : "$sourcetree\(.*\)"`
-    if test ! -f "${item}.in"; then
-        if cmp "$item" "$buildtree/$filename" >/dev/null 2>&1; then : ; else
-            ln -fs "$item" "$buildtree/$filename" || exit 1
-        fi
-    fi
+    [ -e "$item.in" ] && echo "skipping: $item" &&
+        continue
+
+    filename=${item#$sourcetree}
+    cmp "$item" "$buildtree/$filename" >/dev/null 2>&1 ||
+        ln -fs "$item" "$buildtree/$filename"
 done
 
 exit 0
diff --git a/src/tools/ci/cores_backtrace.sh b/src/tools/ci/cores_backtrace.sh
index 28d3cecfc67..93e90f284e6 100755
--- a/src/tools/ci/cores_backtrace.sh
+++ b/src/tools/ci/cores_backtrace.sh
@@ -10,11 +10,24 @@ directory=$2
 
 case $os in
     freebsd|linux|macos)
-    ;;
+        ;;
+
+    msys)
+        # XXX Evidently I don't know how to write two arguments here without pathname expansion later, other than eval.
+        #findargs='-name "*.stackdump"'
+        for corefile in $(find "$directory" -type f -name "*.stackdump") ; do
+            binary=`basename "$corefile" .stackdump`
+            echo;echo;
+            echo "dumping ${corefile} for ${binary}"
+            awk '/^0/{print $2}' $corefile |addr2line -f -i -e ./src/backend/postgres.exe
+        done
+        exit 0
+        ;;
+
     *)
         echo "unsupported operating system ${os}"
         exit 1
-    ;;
+        ;;
 esac
 
 first=1
-- 
2.17.1

