Clear hadrian cache if hadrian executable changed wip/test-hadrian-caching
authorBen Gamari <ben@smart-cactus.org>
Thu, 21 Feb 2019 02:05:44 +0000 (21:05 -0500)
committerBen Gamari <ben@smart-cactus.org>
Thu, 21 Feb 2019 02:05:44 +0000 (21:05 -0500)
.gitlab-ci.yml
.gitlab/clear-hadrian-cache.sh [new file with mode: 0644]

index 9a0d93f..306966d 100644 (file)
@@ -60,10 +60,14 @@ ghc-linters:
     - if [[ -d ./cabal-cache ]]; then cp -R ./.cabal-cache ~/.cabal-cache; fi
     - ./boot
     - ./configure $CONFIGURE_ARGS
+
+    # Clear cache if Hadrian itself has changed
+    - bash .gitlab/clear-hadrian-cache.sh
+
     - hadrian/build.cabal.sh -j`mk/detect-cpu-count.sh` --shared=_cache
     - hadrian/build.cabal.sh -j`mk/detect-cpu-count.sh` docs-haddock
-      # Make sure that caching works properly: _build should be recreated from
-      # the _cache if deleted
+    # Make sure that caching works properly: _build should be recreated from
+    # the _cache if deleted
     - |
       rm -R ./_build
       hadrian/build.cabal.sh -j`mk/detect-cpu-count.sh` --shared=_cache
@@ -71,6 +75,7 @@ ghc-linters:
     key: hadrian
     paths:
       - _cache
+      - hadrian.sha256
       - cabal-cache
 
 validate-x86_64-linux-deb8-hadrian:
diff --git a/.gitlab/clear-hadrian-cache.sh b/.gitlab/clear-hadrian-cache.sh
new file mode 100644 (file)
index 0000000..77f36d8
--- /dev/null
@@ -0,0 +1,19 @@
+#!/usr/bin/bash
+
+set -e
+
+# Build hadrian
+cd hadrian
+cabal new-build hadrian
+cd ..
+hadrian=$(find hadrian/dist-newstyle -iname hadrian -executable -type f)
+
+# Did the executable change?
+touch hadrian.sha256
+sha256 $hadrian > hadrian.sha256.new
+if diff -q hadrian.sha256 hadrian.sha256.new; then
+    echo "Hadrian has changed. Deleting cache... "
+    mv hadrian.sha256.new hadrian.sha256
+    rm -R _cache
+fi
+