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

Warning: Unable to save CompilerPaths cache: #6330

Closed
kant2002 opened this issue Nov 5, 2023 · 9 comments
Closed

Warning: Unable to save CompilerPaths cache: #6330

kant2002 opened this issue Nov 5, 2023 · 9 comments

Comments

@kant2002
Copy link

kant2002 commented Nov 5, 2023

General summary/comments (optional)

Steps to reproduce

Not sure what steps:

  1. Install Stack using Windows Installer
  2. Install GHCup using Set-ExecutionPolicy Bypass -Scope Process -Force;[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; try { Invoke-Command -ScriptBlock ([ScriptBlock]::Create((Invoke-WebRequest https://www.haskell.org/ghcup/sh/bootstrap-haskell.ps1 -UseBasicParsing))) -ArgumentList $true } catch { Write-Error $_ }
  3. Install VS code extension.

Expected

I would like that stack path --stack-root return c:\sr.

Actual

After running stack path --stack-root

Warning: Unable to save CompilerPaths cache:

         CreateFile "D:\\ghcup\\ghc\\9.0.2\\bin\\ghc": does not exist (The system cannot find the file specified.)

Warning: Unable to save CompilerPaths cache:

         CreateFile "D:\\ghcup\\ghc\\9.0.2\\bin\\ghc": does not exist (The system cannot find the file specified.)
C:\sr

when add --verbose

Version 2.13.1, Git revision 8102bb8afce90fc954f48efae38b87f37cabc988 x86_64 hpack-0.36.0
2023-11-05 21:39:02.306046: [debug] Checking for project config at: C:\d\github\gmcheck\stack.yaml
2023-11-05 21:39:02.309052: [debug] Loading project config file stack.yaml
2023-11-05 21:39:02.318046: [debug] Use of Casa server enabled: (CasaRepoPrefix "https://casa.stackage.org", 1280).
2023-11-05 21:39:02.342100: [debug] (SQL) SELECT COUNT(*) FROM "last_performed" WHERE ("action"=?) AND ("timestamp">=?); [PersistInt64 1,PersistUTCTime 2023-11-04 15:39:02.3421 UTC]
2023-11-05 21:39:02.344100: [debug] Using package location completions from a lock file
2023-11-05 21:39:02.349097: [debug] Loaded snapshot from Pantry database.
2023-11-05 21:39:02.623443: [debug] Running Hpack on C:\d\github\gmcheck\package.yaml
2023-11-05 21:39:02.634431: [debug] Hpack output unchanged in C:\d\github\gmcheck\gmcheck.cabal
2023-11-05 21:39:02.636439: [debug] Prefetching git repos: []
2023-11-05 21:39:02.637407: [debug] []
2023-11-05 21:39:02.642395: [debug] Asking for a supported GHC version
2023-11-05 21:39:02.643392: [debug] Getting hook installed compiler version
2023-11-05 21:39:02.646397: [debug] Run process: C:\Users\kant\AppData\Local\Programs\stack\x86_64-windows\msys2-20230526\usr\bin\sh.EXE C:\sr\hooks\ghc-install.sh
2023-11-05 21:39:02.879727: [debug] Process finished in 233ms: C:\Users\kant\AppData\Local\Programs\stack\x86_64-windows\msys2-20230526\usr\bin\sh.EXE C:\sr\hooks\ghc-install.sh
2023-11-05 21:39:02.880737: [debug] Using GHC compiler at: D:\ghcup\ghc\9.0.2\bin\ghc
2023-11-05 21:39:02.881713: [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 "D:\\ghcup\\ghc\\9.0.2\\bin\\ghc"]
2023-11-05 21:39:02.882688: [debug] Looking for executable(s):
* D:\ghcup\ghc\9.0.2\bin\ghc-pkg.exe
2023-11-05 21:39:02.883688: [debug] Looking for executable(s):
* D:\ghcup\ghc\9.0.2\bin\runghc.exe
2023-11-05 21:39:02.884691: [debug] Looking for executable(s):
* D:\ghcup\ghc\9.0.2\bin\haddock.exe
* D:\ghcup\ghc\9.0.2\bin\haddock-ghc.exe
2023-11-05 21:39:02.886859: [debug] Run process: D:\ghcup\ghc\9.0.2\bin\ghc.EXE --info
2023-11-05 21:39:03.000598: [debug] Process finished in 114ms: D:\ghcup\ghc\9.0.2\bin\ghc.EXE --info
2023-11-05 21:39:03.008599: [debug] Run process: D:\ghcup\ghc\9.0.2\bin\ghc-pkg.exe --global --no-user-package-db dump --expand-pkgroot
2023-11-05 21:39:03.133261: [debug] Process finished in 124ms: D:\ghcup\ghc\9.0.2\bin\ghc-pkg.exe --global --no-user-package-db dump --expand-pkgroot
2023-11-05 21:39:03.134253: [debug] (SQL) DELETE FROM "compiler_cache" WHERE "ghc_path"=?; [PersistText "D:\\ghcup\\ghc\\9.0.2\\bin\\ghc"]
2023-11-05 21:39:03.135247: [warn] 
Warning: Unable to save CompilerPaths cache:

         CreateFile "D:\\ghcup\\ghc\\9.0.2\\bin\\ghc": does not exist (The system cannot find the file specified.)
2023-11-05 21:39:03.136262: [debug] Asking for a supported GHC version
2023-11-05 21:39:03.136262: [debug] Resolving package entries
2023-11-05 21:39:03.137245: [debug] Parsing the targets
2023-11-05 21:39:03.138243: [debug] Checking flags
2023-11-05 21:39:03.138243: [debug] SourceMap constructed
2023-11-05 21:39:03.155243: [debug] Starting to execute command inside EnvConfig
2023-11-05 21:39:03.156244: [debug] Checking for project config at: C:\d\github\gmcheck\stack.yaml
2023-11-05 21:39:03.157243: [debug] Loading project config file stack.yaml
2023-11-05 21:39:03.162247: [debug] Use of Casa server enabled: (CasaRepoPrefix "https://casa.stackage.org", 1280).
2023-11-05 21:39:03.167259: [debug] (SQL) SELECT COUNT(*) FROM "last_performed" WHERE ("action"=?) AND ("timestamp">=?); [PersistInt64 1,PersistUTCTime 2023-11-04 15:39:03.1672592 UTC]
2023-11-05 21:39:03.169249: [debug] Using package location completions from a lock file
2023-11-05 21:39:03.172243: [debug] Loaded snapshot from Pantry database.
2023-11-05 21:39:03.493854: [debug] Running Hpack on C:\d\github\gmcheck\package.yaml
2023-11-05 21:39:03.503747: [debug] Hpack output unchanged in C:\d\github\gmcheck\gmcheck.cabal
2023-11-05 21:39:03.506758: [debug] Prefetching git repos: []
2023-11-05 21:39:03.506758: [debug] []
2023-11-05 21:39:03.513715: [debug] Asking for a supported GHC version
2023-11-05 21:39:03.514717: [debug] Getting hook installed compiler version
2023-11-05 21:39:03.517756: [debug] Run process: C:\Users\kant\AppData\Local\Programs\stack\x86_64-windows\msys2-20230526\usr\bin\sh.EXE C:\sr\hooks\ghc-install.sh
2023-11-05 21:39:03.746369: [debug] Process finished in 228ms: C:\Users\kant\AppData\Local\Programs\stack\x86_64-windows\msys2-20230526\usr\bin\sh.EXE C:\sr\hooks\ghc-install.sh
2023-11-05 21:39:03.746369: [debug] Using GHC compiler at: D:\ghcup\ghc\9.0.2\bin\ghc
2023-11-05 21:39:03.747367: [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 "D:\\ghcup\\ghc\\9.0.2\\bin\\ghc"]
2023-11-05 21:39:03.748368: [debug] Looking for executable(s):
* D:\ghcup\ghc\9.0.2\bin\ghc-pkg.exe
2023-11-05 21:39:03.749369: [debug] Looking for executable(s):
* D:\ghcup\ghc\9.0.2\bin\runghc.exe
2023-11-05 21:39:03.750369: [debug] Looking for executable(s):
* D:\ghcup\ghc\9.0.2\bin\haddock.exe
* D:\ghcup\ghc\9.0.2\bin\haddock-ghc.exe
2023-11-05 21:39:03.752370: [debug] Run process: D:\ghcup\ghc\9.0.2\bin\ghc.EXE --info
2023-11-05 21:39:03.866372: [debug] Process finished in 113ms: D:\ghcup\ghc\9.0.2\bin\ghc.EXE --info
2023-11-05 21:39:03.868412: [debug] Run process: D:\ghcup\ghc\9.0.2\bin\ghc-pkg.exe --global --no-user-package-db dump --expand-pkgroot
2023-11-05 21:39:03.997369: [debug] Process finished in 129ms: D:\ghcup\ghc\9.0.2\bin\ghc-pkg.exe --global --no-user-package-db dump --expand-pkgroot
2023-11-05 21:39:03.998369: [debug] (SQL) DELETE FROM "compiler_cache" WHERE "ghc_path"=?; [PersistText "D:\\ghcup\\ghc\\9.0.2\\bin\\ghc"]
2023-11-05 21:39:03.999370: [warn] 
Warning: Unable to save CompilerPaths cache:

         CreateFile "D:\\ghcup\\ghc\\9.0.2\\bin\\ghc": does not exist (The system cannot find the file specified.)
2023-11-05 21:39:04.001369: [debug] Asking for a supported GHC version
2023-11-05 21:39:04.001369: [debug] Resolving package entries
2023-11-05 21:39:04.002368: [debug] Parsing the targets
2023-11-05 21:39:04.005369: [debug] Checking flags
2023-11-05 21:39:04.009372: [debug] SourceMap constructed
2023-11-05 21:39:04.022370: [debug] Starting to execute command inside EnvConfig
C:\sr

Stack version

stack --version
Version 2.13.1, Git revision 8102bb8afce90fc954f48efae38b87f37cabc988 x86_64 hpack-0.36.0

Platform

Windows 10 x64

@mpilgrem
Copy link
Member

mpilgrem commented Nov 5, 2023

@kant2002, thanks for reporting. It looks to me like you are using GHCup to customise Stack's installation of GHC (https://docs.haskellstack.org/en/stable/yaml_configuration/#ghc-installation-customisation), because of the line:

Using GHC compiler at: D:\ghcup\ghc\9.0.2\bin\ghc

So, this may be a GHCup bug rather than a Stack one. The basic problem seems to me to be that GHCup is promising to provide GHC 9.0.2 and is failing to do so.

A work around might be to allow Stack to manage its GHC requirments. That would involve deleting the hooks directory in the Stack root that has been created by GHCup.

@kant2002
Copy link
Author

kant2002 commented Nov 5, 2023

I forgot to mention that stack build/stack run seems tot be working fine. Also this EXE file is present and is executed seems to be correctly.

@mpilgrem
Copy link
Member

mpilgrem commented Nov 5, 2023

Ok, so GHCup must be supplying GHC 9.0.2 (contrary to what I assumed above).

@mpilgrem
Copy link
Member

mpilgrem commented Nov 5, 2023

Stack throws that warning in Stack.Setup.pathsFromCompiler:

    mres <-
      case eres of
        Left e -> do
          prettyWarn $
               flow "Trouble loading CompilerPaths cache:"
            <> blankLine
            <> string (displayException e)
          pure Nothing
        Right x -> pure x
    case mres of
      Just cp -> cp <$ logDebug "Loaded compiler information from cache"
      Nothing -> do
        cp <- inner
        saveCompilerPaths cp `catchAny` \e ->
          prettyWarn $
               flow "Unable to save CompilerPaths cache:"
            <> blankLine
            <> string (displayException e)
        pure cp

I suspect the exception reported as a warning is thrown in Stack.Storage.User.saveCompilerPaths:

compilerStatus <- liftIO $ getFileStatus $ toFilePath cpCompiler

Perhaps it is something to do with the difference between D:\ghcup\ghc\9.0.2\bin\ghc and D:\ghcup\ghc\9.0.2\bin\ghc.exe.

EDIT: I am assuming that System.PosixCompat.Files.getFileStatus (from package unix-compat) would not tolerate a missing .exe extension.

@mpilgrem
Copy link
Member

mpilgrem commented Nov 5, 2023

That is, the hook script must output to standard output the absolute path to the GHC binary that was installed (by GHCup) but D:\ghcup\ghc\9.0.2\bin\ghc is missing the extension of the executable file? If I am correct, that would be a bug in the GHCup hook script.

@mpilgrem
Copy link
Member

mpilgrem commented Nov 5, 2023

Bringing in @hasufell, as he is the expert in this field.

@mpilgrem
Copy link
Member

mpilgrem commented Nov 5, 2023

@kant2002, one way to test my theory is that in the hooks directory of the Stack root, there is likely a file ghc-install.sh with contents similar to this:

#!/bin/sh

set -eu

case $HOOK_GHC_TYPE in
    bindist)
        ghcdir=$(ghcup whereis --directory ghc "$HOOK_GHC_VERSION" || ghcup run --ghc "$HOOK_GHC_VERSION" --install) || exit 3
        printf "%s/ghc" "${ghcdir}"
        ;;
    git)
        # TODO: should be somewhat possible
        >&2 echo "Hook doesn't support installing from source"
        exit 1
        ;;
    *)
        >&2 echo "Unsupported GHC installation type: $HOOK_GHC_TYPE"
        exit 2
        ;;
esac

I suspect the line printf "%s/ghc" "${ghcdir}" should be printf "%s/ghc.exe" "${ghcdir}"

@mpilgrem
Copy link
Member

mpilgrem commented Nov 6, 2023

@kant2002, the master branch of GHCup now has a new ghc-install.sh (in directory scripts/hooks/stack) that addresses this. See https://www.haskell.org/ghcup/guide/#strategy-1-stack-hooks-new-recommended for documentation on how install/update it manually.

@mpilgrem mpilgrem closed this as completed Nov 6, 2023
@kant2002
Copy link
Author

kant2002 commented Nov 6, 2023

Ooh. That was lightning fast. I go to sleep and on next day before I at home this is fixed. Super cool!

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

No branches or pull requests

2 participants