diff --git a/.github/workflows/bootstrap.yml b/.github/workflows/bootstrap.yml index 8f29357bd07..1b1a1922c9b 100644 --- a/.github/workflows/bootstrap.yml +++ b/.github/workflows/bootstrap.yml @@ -44,8 +44,13 @@ jobs: id: bootstrap-cache with: path: "/home/runner/work/cabal/cabal/_build" - key: bootstrap-${{ steps.get-osver.outputs.osver }}-${{ matrix.ghc }}-${{ hashFiles(format('bootstrap/linux-{0}.json', matrix.ghc)) }}-${{ github.sha }} - restore-keys: bootstrap-${{ steps.get-osver.outputs.osver }}-${{ matrix.ghc }}-${{ hashFiles(format('bootstrap/linux-{0}.json', matrix.ghc)) }}- + # Hash the .cabal files of the local packages into the key too: + # the bootstrap plans only reference local packages by name, so + # without this the caches of branches with different local package + # versions (e.g. master vs a release branch) collide and a stale + # _build/packages.conf gets restored. See #12311. + key: bootstrap-${{ steps.get-osver.outputs.osver }}-${{ matrix.ghc }}-${{ hashFiles(format('bootstrap/linux-{0}.json', matrix.ghc), 'Cabal/Cabal.cabal', 'Cabal-syntax/Cabal-syntax.cabal', 'Cabal-hooks/Cabal-hooks.cabal', 'hooks-exe/hooks-exe.cabal', 'cabal-install-solver/cabal-install-solver.cabal', 'cabal-install/cabal-install.cabal') }}-${{ github.sha }} + restore-keys: bootstrap-${{ steps.get-osver.outputs.osver }}-${{ matrix.ghc }}-${{ hashFiles(format('bootstrap/linux-{0}.json', matrix.ghc), 'Cabal/Cabal.cabal', 'Cabal-syntax/Cabal-syntax.cabal', 'Cabal-hooks/Cabal-hooks.cabal', 'hooks-exe/hooks-exe.cabal', 'cabal-install-solver/cabal-install-solver.cabal', 'cabal-install/cabal-install.cabal') }}- - uses: haskell-actions/setup@v2 with: diff --git a/bootstrap/bootstrap.py b/bootstrap/bootstrap.py index 5638b13648c..30dcd9044d7 100755 --- a/bootstrap/bootstrap.py +++ b/bootstrap/bootstrap.py @@ -275,10 +275,12 @@ def hash_file(h, f: BinaryIO) -> SHA256Hash: PlanUnit = NewType('PlanUnit', dict) def bootstrap(info: BootstrapInfo, ghc: Compiler) -> None: - if not PKG_DB.exists(): - print(f'Creating package database {PKG_DB}') - PKG_DB.parent.mkdir(parents=True, exist_ok=True) - subprocess_run([ghc.ghc_pkg_path, 'init', PKG_DB]) + if PKG_DB.exists(): + print(f'Deleting stale package database {PKG_DB}') + shutil.rmtree(PKG_DB) + print(f'Creating package database {PKG_DB}') + PKG_DB.parent.mkdir(parents=True, exist_ok=True) + subprocess_run([ghc.ghc_pkg_path, 'init', PKG_DB]) for dep in info.builtin: check_builtin(dep, ghc)