packages feed

hie-bios 0.9.0 → 0.9.1

raw patch · 3 files changed

+81/−18 lines, 3 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

Files

ChangeLog.md view
@@ -1,5 +1,12 @@ # ChangeLog hie-bios +## 2022-03-07 - 0.9.1++* Ignore .ghci files while querying project GHC [#337](https://github.com/haskell/hie-bios/pull/337)+  * Fixes a bug where hie-bios fails to load cabal cradles with `.ghci` files+* Improve error messages if cabal invocation fails [#338](https://github.com/haskell/hie-bios/pull/338)+* Allow text-2.0 [#335](https://github.com/haskell/hie-bios/pull/335)+ ## 2022-02-25 - 0.9.0  * Use the proper GHC version given by cabal [#282](https://github.com/haskell/hie-bios/pull/282)@@ -18,7 +25,7 @@ ## 2021-08-30 - 0.7.6  * Don't look for NIX_GHC_LIBDIR as it is redundant [#294](https://github.com/mpickering/hie-bios/pull/294)-* Add compatbility for GHC 9.0 and 9.2 [#300](https://github.com/mpickering/hie-bios/pull/300)+* Add compatibility for GHC 9.0 and 9.2 [#300](https://github.com/mpickering/hie-bios/pull/300)   * Add CPP statements for IncludeSpecs [#307](https://github.com/mpickering/hie-bios/pull/307) * Refactor implicit config discovery [#291](https://github.com/mpickering/hie-bios/pull/291) * Log stderr of stack to display more informative error messages to users. [#254](https://github.com/mpickering/hie-bios/pull/254)
hie-bios.cabal view
@@ -1,6 +1,6 @@ Cabal-Version:          2.2 Name:                   hie-bios-Version:                0.9.0+Version:                0.9.1 Author:                 Matthew Pickering <matthewtpickering@gmail.com> Maintainer:             Matthew Pickering <matthewtpickering@gmail.com> License:                BSD-3-Clause@@ -165,7 +165,7 @@                         ghc                  >= 8.6.1 && < 9.3,                         transformers         >= 0.5.2 && < 0.7,                         temporary            >= 1.2 && < 1.4,-                        text                 >= 1.2.3 && < 2,+                        text                 >= 1.2.3 && < 2.1,                         unix-compat          >= 0.5.1 && < 0.6,                         unordered-containers >= 0.2.9 && < 0.3,                         vector               >= 0.12.0 && < 0.13,
src/HIE/Bios/Cradle.hs view
@@ -65,8 +65,42 @@ import GHC.Fingerprint (fingerprintString) import GHC.ResponseFile (escapeArgs) +----------------------------------------------------------------+-- Environment variables used by hie-bios.+--+-- If you need more, add a constant here.+----------------------------------------------------------------++-- | Environment variable containing the filepath to which+-- cradle actions write their results to.+-- If the filepath does not exist, cradle actions must create them. hie_bios_output :: String hie_bios_output = "HIE_BIOS_OUTPUT"++-- | Environment variable pointing to the GHC location used by+-- cabal's and stack's GHC wrapper.+--+-- If not set, will default to sensible defaults.+hie_bios_ghc :: String+hie_bios_ghc = "HIE_BIOS_GHC"++-- | Environment variable with extra arguments passed to the GHC location+-- in cabal's and stack's GHC wrapper.+--+-- If not set, assume no extra arguments.+hie_bios_ghc_args :: String+hie_bios_ghc_args = "HIE_BIOS_GHC_ARGS"++-- | Environment variable pointing to the source file location that caused+-- the cradle action to be executed.+hie_bios_arg :: String+hie_bios_arg = "HIE_BIOS_ARG"++-- | Environment variable pointing to a filepath to which dependencies+-- of a cradle can be written to by the cradle action.+hie_bios_deps :: String+hie_bios_deps = "HIE_BIOS_DEPS"+ ----------------------------------------------------------------  -- | Given root\/foo\/bar.hs, return root\/hie.yaml, or wherever the yaml file was found.@@ -399,7 +433,7 @@ biosAction wdir bios bios_deps l fp = do   bios' <- callableToProcess bios (Just fp)   (ex, _stdo, std, [(_, res),(_, mb_deps)]) <--    readProcessWithOutputs [hie_bios_output, "HIE_BIOS_DEPS"] l wdir bios'+    readProcessWithOutputs [hie_bios_output, hie_bios_deps] l wdir bios'    deps <- case mb_deps of     Just x  -> return x@@ -413,9 +447,7 @@ callableToProcess :: Callable -> Maybe String -> IO CreateProcess callableToProcess (Command shellCommand) file = do   old_env <- getEnvironment-  return $ (shell shellCommand) { env = (: old_env) . (,) hieBiosArg <$> file }-    where-      hieBiosArg = "HIE_BIOS_ARG"+  return $ (shell shellCommand) { env = (: old_env) . (,) hie_bios_arg <$> file } callableToProcess (Program path) file = do   canon_path <- canonicalizePath path   return $ proc canon_path (maybeToList file)@@ -447,7 +479,7 @@ -- -- Invokes the cabal process in the given directory. -- Finds the appropriate @ghc@ version as a fallback and provides the path--- to the custom ghc wrapper via 'HIE_BIOS_GHC' environment variable which+-- to the custom ghc wrapper via 'hie_bios_ghc' environment variable which -- the custom ghc wrapper may use as a fallback if it can not respond to certain -- queries, such as ghc version or location of the libdir. cabalProcess :: FilePath -> String -> [String] -> CradleLoadResultT IO CreateProcess@@ -462,7 +494,7 @@   where     processEnvironment :: (FilePath, FilePath) -> [(String, String)]     processEnvironment (ghcBin, libdir) =-      [("HIE_BIOS_GHC", ghcBin), ("HIE_BIOS_GHC_ARGS",  "-B" ++ libdir)]+      [(hie_bios_ghc, ghcBin), (hie_bios_ghc_args,  "-B" ++ libdir)]      setupEnvironment :: (FilePath, FilePath) -> IO [(String, String)]     setupEnvironment ghcDirs = do@@ -646,14 +678,20 @@ -- If cabal can not figure it out, a 'CradleError' is returned. cabalGhcDirs :: FilePath -> CradleLoadResultT IO (FilePath, FilePath) cabalGhcDirs workDir = do-  libdir <- readProcessWithCwd_ workDir  "cabal" ["exec", "-v0", "--", "ghc", "--print-libdir"] ""-  exe <- readProcessWithCwd_ workDir  "cabal"-      ["exec", "-v0", "--", "ghc", "-package-env=-", "-e", "do e <- System.Environment.getExecutablePath ; System.IO.putStr e"] ""+  libdir <- readProcessWithCwd_ workDir "cabal" ["exec", "-v0", "--", "ghc", "--print-libdir"] ""+  exe <- readProcessWithCwd_ workDir "cabal"+      -- DON'T TOUCH THIS CODE+      -- This works with 'NoImplicitPrelude', with 'RebindableSyntax' and other shenanigans.+      -- @-package-env=-@ doesn't work with ghc prior 8.4.x+      [ "exec", "-v0", "--" , "ghc", "-package-env=-", "-ignore-dot-ghci", "-e"+      , "Control.Monad.join (Control.Monad.fmap System.IO.putStr System.Environment.getExecutablePath)"+      ]+      ""   pure (trimEnd exe, trimEnd libdir)  cabalAction :: FilePath -> Maybe String -> LoggingFunction -> FilePath -> CradleLoadResultT IO ComponentOptions cabalAction workDir mc l fp = do-  cabalProc <- (cabalProcess workDir "v2-repl" [fromMaybe (fixTargetPath fp) mc]) `modCradleError` \err -> do+  cabalProc <- cabalProcess workDir "v2-repl" [fromMaybe (fixTargetPath fp) mc] `modCradleError` \err -> do       deps <- cabalCradleDependencies workDir workDir       pure $ err { cradleErrorDependencies = cradleErrorDependencies err ++ deps } @@ -666,11 +704,14 @@       -- Best effort. Assume the working directory is the       -- root of the component, so we are right in trivial cases at least.       deps <- liftIO $ cabalCradleDependencies workDir workDir-      throwCE (CradleError deps ex-                ["Failed to parse result of calling cabal"+      throwCE (CradleError deps ex $+                [ "Failed to parse result of calling cabal"+                , "Failed command: " <> prettyCmdSpec (cmdspec cabalProc)                 , unlines output                 , unlines stde-                , unlines $ args])+                , unlines $ args+                , "Process Environment:"]+                <> prettyProcessEnv cabalProc)     Just (componentDir, final_args) -> do       deps <- liftIO $ cabalCradleDependencies workDir componentDir       CradleLoadResultT $ pure $ makeCradleResult (ex, stde, componentDir, final_args) deps@@ -1042,11 +1083,26 @@   case mResult of     Just (ExitSuccess, stdo, _) -> pure stdo     Just (exitCode, stdo, stde) -> throwCE $-      CradleError [] exitCode ["Error when calling " <> cmdString, stdo, stde]+      CradleError [] exitCode $+        ["Error when calling " <> cmdString, stdo, stde] <> prettyProcessEnv createdProcess     Nothing -> throwCE $-      CradleError [] ExitSuccess ["Couldn't execute " <> cmdString]+      CradleError [] ExitSuccess $+        ["Couldn't execute " <> cmdString] <> prettyProcessEnv createdProcess  -- | Prettify 'CmdSpec', so we can show the command to a user prettyCmdSpec :: CmdSpec -> String prettyCmdSpec (ShellCommand s) = s prettyCmdSpec (RawCommand cmd args) = cmd ++ " " ++ unwords args++-- | Pretty print hie-bios's relevant environment variables.+prettyProcessEnv :: CreateProcess -> [String]+prettyProcessEnv p =+  [ key <> ": " <> value+  | (key, value) <- fromMaybe [] (env p)+  , key `elem` [ hie_bios_output+               , hie_bios_ghc+               , hie_bios_ghc_args+               , hie_bios_arg+               , hie_bios_deps+               ]+  ]