Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stack path --stack-root wants GHC installed; vicious cycle with CI caching #6340

Closed
andreasabel opened this issue Nov 20, 2023 · 1 comment
Closed
Assignees

Comments

@andreasabel
Copy link

All that stack path --stack-root should do is to print out the stack root directory.
Nothing more. Because everything else is just making it behave worse.

Currently stack path --stack-root does tons of things before printing the stack root, and these things can fail, e.g. if no GHC is installed:
https://github.com/agda/agda-language-server/actions/runs/6930512530/job/18850319673

echo STACK_ROOT="$(stack --no-install-ghc path --stack-root)" >> "${GITHUB_ENV}"

Warning: Continuing despite missing tool: msys2
Error: [S-pointlessnumber]
No compiler found, expected minor version match or newer with ghc-8.10.7 (x86_64) (based on resolver setting in D:\a\agda-language-server\agda-language-server\stack.yaml).
To install the correct GHC into C:\Users\runneradmin\AppData\Local\Programs\stack\x86_64-windows\, try running 'stack setup' or use the '--install-ghc' flag. To use your system GHC installation, run 'stack config set system-ghc --global true', or use the '--system-ghc' flag.

What is stack doing here? I has given away the stack root in an error message:

To install the correct GHC into C:\Users\runneradmin\AppData\Local\Programs\stack\x86_64-windows ...

But it can print it for me in a regular fashion? Instead, it insists on a operational system.

Why is it problematic that stack path --stack-root does its full "system operational" check at the beginning?
Because one may need the stack root location to restore the "operational system" from a cache.
Before restoring, the system is simply not operational...

Stack needlessly constructs a vicious cycle here between needing the stack root to restore a cached GHC and needing a GHC to print the stack root. (Not sure if I should laugh or cry here.)

Request: make stack path --stack-root simply print the stack root and do nothing else.
This will also bring the runtime of this command down by 3 orders of magnitude; it currently takes >1000ms on my system.

Here is a dump of what stack path --stack-root does on a specific project of mine:

Version 2.13.1, Git revision 8102bb8afce90fc954f48efae38b87f37cabc988 x86_64 hpack-0.36.0
2023-11-20 21:24:45.647127: [debug] Checking for project config at: .../stack.yaml
2023-11-20 21:24:45.651389: [debug] Loading project config file stack.yaml
2023-11-20 21:24:45.681590: [debug] Use of Casa server enabled: (CasaRepoPrefix "https://casa.stackage.org", 1280).
2023-11-20 21:24:45.707139: [debug] (SQL) SELECT COUNT(*) FROM "last_performed" WHERE ("action"=?) AND ("timestamp">=?); [PersistInt64 1,PersistUTCTime 2023-11-19 13:24:45.706403 UTC]
2023-11-20 21:24:45.713999: [debug] Using package location completions from a lock file
2023-11-20 21:24:45.729765: [debug] Loaded snapshot from Pantry database.
2023-11-20 21:24:46.042721: [debug] Running Hpack on .../package.yaml
2023-11-20 21:24:46.054086: [debug] Hpack output unchanged in .../agda-language-server.cabal
2023-11-20 21:24:46.054701: [debug] Prefetching git repos: []
2023-11-20 21:24:46.054765: [debug] []
2023-11-20 21:24:46.055803: [debug] Parsing cabal file for Agda (from Hackage)
2023-11-20 21:24:46.057210: [debug] Got blob from Pantry database for Agda-2.6.2.2@sha256:b69c2f317db2886cb387134af00a3e42a06fab6422686938797924d034255a55,37047
2023-11-20 21:24:46.105154: [debug] Asking for a supported GHC version
2023-11-20 21:24:46.105429: [debug] Getting system compiler version
2023-11-20 21:24:46.138231: [debug] (SQL) SELECT "id","actual_version","arch","ghc_path","ghc_size","ghc_modified","ghc_pkg_path","runghc_path","haddock_path","cabal_version","global_db","global_db_cache_size","global_db_cache_modified","info","global_dump" FROM "compiler_cache" WHERE "ghc_path"=?; [PersistText "/usr/local/bin/ghc-8.10.7"]
2023-11-20 21:24:46.199671: [debug] Loaded compiler information from cache
2023-11-20 21:24:46.199829: [debug] Asking for a supported GHC version
2023-11-20 21:24:46.199888: [debug] Resolving package entries
2023-11-20 21:24:46.199954: [debug] Parsing the targets
2023-11-20 21:24:46.203941: [debug] Checking flags
2023-11-20 21:24:46.204312: [debug] SourceMap constructed
2023-11-20 21:24:46.221763: [debug] Run process: /usr/local/bin/ghc-pkg-8.10.7 init /Users/abel/.stack/snapshots/x86_64-osx/63d15aee5b7a1bf5deccdd3e187d8717ed023d339e15844489a96429439b2c15/8.10.7/pkgdb/
2023-11-20 21:24:46.419287: [debug] Process finished in 197216896000ms: /usr/local/bin/ghc-pkg-8.10.7 init /Users/abel/.stack/snapshots/x86_64-osx/63d15aee5b7a1bf5deccdd3e187d8717ed023d339e15844489a96429439b2c15/8.10.7/pkgdb/
2023-11-20 21:24:46.420442: [debug] Run process: /usr/local/bin/ghc-pkg-8.10.7 init /.../.stack-work/install/x86_64-osx/63d15aee5b7a1bf5deccdd3e187d8717ed023d339e15844489a96429439b2c15/8.10.7/pkgdb/
2023-11-20 21:24:46.470519: [debug] Process finished in 49993980000ms: /usr/local/bin/ghc-pkg-8.10.7 init .../.stack-work/install/x86_64-osx/63d15aee5b7a1bf5deccdd3e187d8717ed023d339e15844489a96429439b2c15/8.10.7/pkgdb/
2023-11-20 21:24:46.470839: [debug] Starting to execute command inside EnvConfig
2023-11-20 21:24:46.471269: [debug] Checking for project config at: .../stack.yaml
2023-11-20 21:24:46.471352: [debug] Loading project config file stack.yaml
2023-11-20 21:24:46.472616: [debug] Use of Casa server enabled: (CasaRepoPrefix "https://casa.stackage.org", 1280).
2023-11-20 21:24:46.474439: [debug] (SQL) SELECT COUNT(*) FROM "last_performed" WHERE ("action"=?) AND ("timestamp">=?); [PersistInt64 1,PersistUTCTime 2023-11-19 13:24:46.474404 UTC]
2023-11-20 21:24:46.474849: [debug] Using package location completions from a lock file
2023-11-20 21:24:46.476795: [debug] Loaded snapshot from Pantry database.
2023-11-20 21:24:46.734981: [debug] Running Hpack on .../package.yaml
2023-11-20 21:24:46.740440: [debug] Hpack output unchanged in ....cabal
2023-11-20 21:24:46.740858: [debug] Prefetching git repos: []
2023-11-20 21:24:46.740915: [debug] []
2023-11-20 21:24:46.741878: [debug] Parsing cabal file for Agda (from Hackage)
2023-11-20 21:24:46.742208: [debug] Got blob from Pantry database for Agda-2.6.2.2@sha256:b69c2f317db2886cb387134af00a3e42a06fab6422686938797924d034255a55,37047
2023-11-20 21:24:46.753838: [debug] Asking for a supported GHC version
2023-11-20 21:24:46.753931: [debug] Getting system compiler version
2023-11-20 21:24:46.755844: [debug] (SQL) SELECT "id","actual_version","arch","ghc_path","ghc_size","ghc_modified","ghc_pkg_path","runghc_path","haddock_path","cabal_version","global_db","global_db_cache_size","global_db_cache_modified","info","global_dump" FROM "compiler_cache" WHERE "ghc_path"=?; [PersistText "/usr/local/bin/ghc-8.10.7"]
2023-11-20 21:24:46.815015: [debug] Loaded compiler information from cache
2023-11-20 21:24:46.815166: [debug] Asking for a supported GHC version
2023-11-20 21:24:46.815250: [debug] Resolving package entries
2023-11-20 21:24:46.815310: [debug] Parsing the targets
2023-11-20 21:24:46.818406: [debug] Checking flags
2023-11-20 21:24:46.818498: [debug] SourceMap constructed
2023-11-20 21:24:46.825414: [debug] Starting to execute command inside EnvConfig
/Users/abel/.stack
@mpilgrem
Copy link
Member

@andreasabel, I think that should be relatively easy to change. Currently, all the path options happen within:

runHaddock :: Bool -> RIO EnvConfig () -> RIO Runner ()
runHaddock x action = local modifyConfig $
  withConfig YesReexec $
    withDefaultEnvConfig action
 where
  modifyConfig = set
    (globalOptsL.globalOptsBuildOptsMonoidL.buildOptsMonoidHaddockL) (Just x)

but some only need the information in the RIO Config environment and --stack-root only needs the information in the RIO Runner environment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants