packages feed

hie-bios 0.6.1 → 0.6.2

raw patch · 14 files changed

+104/−32 lines, 14 filesPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

API changes (from Hackage documentation)

+ HIE.Bios.Config: [ghcPath] :: CradleType a -> Maybe FilePath
- HIE.Bios.Config: Bios :: Callable -> Maybe Callable -> CradleType a
+ HIE.Bios.Config: Bios :: Callable -> Maybe Callable -> Maybe FilePath -> CradleType a

Files

ChangeLog.md view
@@ -1,5 +1,11 @@ # ChangeLog hie-bios +## 2020-08-08 - 0.6.2++### New Features++* Add optional ghc-path field in bios cradles [#231](https://github.com/mpickering/hie-bios/pull/231)+ ## 2020-07-12 - 0.6.1  ### Bug Fixes
README.md view
@@ -355,6 +355,14 @@     shell: "<build-tool flags $HIE_BIOS_ARG>" ``` +Additionally, you may specify the path to ghc. Otherwise, the one in the PATH will be used:++```yaml+cradle:+  bios:+    program: "<program>"+    with-ghc: "<ghc>"+``` #### Debugging a `bios` cradle  The most common error in creating `bios` cradle is to not list all targets of the component. Please make sure, that you always list all targets of the component, associated with the filepath you want to load.@@ -540,6 +548,7 @@     dependency-program: "optional program to run"     shell: build-tool flags $HIE_BIOS_ARG     dependency-shell: build-tool dependencies+    with-ghc: "optional path to ghc"   direct:     arguments: ["list","of","ghc","arguments"]   none:
hie-bios.cabal view
@@ -1,6 +1,6 @@ Cabal-Version:          2.2 Name:                   hie-bios-Version:                0.6.1+Version:                0.6.2 Author:                 Matthew Pickering <matthewtpickering@gmail.com> Maintainer:             Matthew Pickering <matthewtpickering@gmail.com> License:                BSD-3-Clause@@ -65,6 +65,9 @@                         tests/projects/failing-bios/A.hs                         tests/projects/failing-bios/B.hs                         tests/projects/failing-bios/hie.yaml+                        tests/projects/failing-bios-ghc/A.hs+                        tests/projects/failing-bios-ghc/B.hs+                        tests/projects/failing-bios-ghc/hie.yaml                         tests/projects/failing-cabal/failing-cabal.cabal                         tests/projects/failing-cabal/hie.yaml                         tests/projects/failing-cabal/MyLib.hs@@ -92,6 +95,10 @@                         tests/projects/simple-bios/B.hs                         tests/projects/simple-bios/hie-bios.sh                         tests/projects/simple-bios/hie.yaml+                        tests/projects/simple-bios-ghc/A.hs+                        tests/projects/simple-bios-ghc/B.hs+                        tests/projects/simple-bios-ghc/hie-bios.sh+                        tests/projects/simple-bios-ghc/hie.yaml                         tests/projects/simple-bios-shell/A.hs                         tests/projects/simple-bios-shell/B.hs                         tests/projects/simple-bios-shell/hie.yaml
src/HIE/Bios/Config.hs view
@@ -59,6 +59,8 @@         -- ^ Optional path to program or shell command to obtain cradle dependencies.         -- Each cradle dependency is to be expected to be on a separate line         -- and relative to the root dir of the cradle.+        , ghcPath :: Maybe FilePath+        -- ^ Optional path to the ghc binary         }     | Direct { arguments :: [String] }     | None@@ -128,20 +130,23 @@ parseCabal = parseStackOrCabal Cabal CabalMulti  parseBios :: Value -> Parser (CradleType a)-parseBios (Object x)-    | 2 == Map.size x-    , Just biosCallable <- exclusive (stringTypeFromMap Program "program") (stringTypeFromMap Command "shell")-    , Just biosDepsCallable <- exclusive (stringTypeFromMap Program "dependency-program") (stringTypeFromMap Command "dependency-shell")-    = return $ Bios biosCallable (Just biosDepsCallable)--    | 1 == Map.size x-    , Just biosCallable <- exclusive (stringTypeFromMap Program "program") (stringTypeFromMap Command "shell")-    = return $ Bios biosCallable Nothing--    | otherwise-    = fail "Not a valid Bios Configuration type, following keys are allowed: program or shell, dependency-program or dependency-shell"-+parseBios (Object x) =+    case biosCallable of+        Just bc -> return $ Bios bc biosDepsCallable ghcPath+        _ -> fail $ "Not a valid Bios Configuration type, following keys are allowed:" +++                    "program or shell, dependency-program or dependency-shell, with-ghc"     where+        biosCallable =+            exclusive+                (stringTypeFromMap Program "program")+                (stringTypeFromMap Command "shell")+        biosDepsCallable =+            exclusive+                (stringTypeFromMap Program "dependency-program")+                (stringTypeFromMap Command "dependency-shell")+        ghcPath =+            stringTypeFromMap id "with-ghc"+         exclusive :: Maybe a -> Maybe a -> Maybe a         exclusive (Just _) (Just _) = Nothing         exclusive l Nothing = l
src/HIE/Bios/Cradle.hs view
@@ -106,7 +106,7 @@         , wdir)  --   Bazel -> rulesHaskellCradle wdir  --   Obelisk -> obeliskCradle wdir-    Bios bios deps  -> biosCradle wdir bios deps+    Bios bios deps mbGhc -> biosCradle wdir bios deps mbGhc     Direct xs -> directCradle wdir xs     None      -> noneCradle wdir     Multi ms  -> multiCradle buildCustomCradle wdir ms@@ -139,7 +139,7 @@  implicitConfig' :: FilePath -> MaybeT IO (CradleType a, FilePath) implicitConfig' fp = (\wdir ->-         (Bios (Program $ wdir </> ".hie-bios") Nothing, wdir)) <$> biosWorkDir fp+         (Bios (Program $ wdir </> ".hie-bios") Nothing Nothing, wdir)) <$> biosWorkDir fp   --   <|> (Obelisk,) <$> obeliskWorkDir fp   --   <|> (Bazel,) <$> rulesHaskellWorkDir fp      <|> (stackExecutable >> (Stack Nothing,) <$> stackWorkDir fp)@@ -334,14 +334,14 @@  -- | Find a cradle by finding an executable `hie-bios` file which will -- be executed to find the correct GHC options to use.-biosCradle :: FilePath -> Callable -> Maybe Callable -> Cradle a-biosCradle wdir biosCall biosDepsCall =+biosCradle :: FilePath -> Callable -> Maybe Callable -> Maybe FilePath -> Cradle a+biosCradle wdir biosCall biosDepsCall mbGhc =   Cradle     { cradleRootDir    = wdir     , cradleOptsProg   = CradleAction         { actionName = Types.Bios         , runCradle = biosAction wdir biosCall biosDepsCall-        , runGhcCmd = runGhcCmdOnPath wdir+        , runGhcCmd = \args -> readProcessWithCwd wdir (fromMaybe "ghc" mbGhc) args ""         }     } @@ -452,7 +452,7 @@ -- when run with --interactive, it will print out its -- command-line arguments and exit withCabalWrapperTool :: GhcProc -> FilePath -> (FilePath -> IO a) -> IO a-withCabalWrapperTool (ghcPath, ghcArgs) wdir k = do+withCabalWrapperTool (mbGhc, ghcArgs) wdir k = do   if isWindows     then do       cacheDir <- getCacheDir ""@@ -464,7 +464,7 @@           createDirectoryIfMissing True cacheDir           let wrapper_hs = cacheDir </> wrapper_name <.> "hs"           writeFile wrapper_hs cabalWrapperHs-          let ghc = (proc ghcPath $+          let ghc = (proc mbGhc $                       ghcArgs ++ ["-rtsopts=ignore", "-outputdir", tmpDir, "-o", wrapper_fp, wrapper_hs])                       { cwd = Just wdir }           readCreateProcess ghc "" >>= putStr
tests/BiosTests.hs view
@@ -24,7 +24,7 @@ import System.FilePath (addTrailingPathSeparator,  makeRelative, (</>) ) import System.Info.Extra ( isWindows ) import System.IO.Temp-import System.Exit (ExitCode(ExitFailure))+import System.Exit (ExitCode(ExitSuccess, ExitFailure)) import Control.Monad.Extra (unlessM)  main :: IO ()@@ -99,6 +99,12 @@               (\CradleError {..} -> do                   cradleErrorExitCode `shouldBe` ExitFailure 1                   cradleErrorDependencies `shouldMatchList` ["hie.yaml"])+           , testCaseSteps "failing-bios-ghc" $ testGetGhcVersionFail isBiosCradle "./tests/projects/failing-bios-ghc" "B.hs"+              (\CradleError {..} -> do+                  cradleErrorExitCode `shouldBe` ExitSuccess+                  cradleErrorDependencies `shouldMatchList` []+                  length cradleErrorStderr `shouldBe` 1+                  head cradleErrorStderr `shouldStartWith` "Couldn't execute myGhc")            , testCaseSteps "simple-bios-shell" $ testDirectory isBiosCradle "./tests/projects/simple-bios-shell" "B.hs"            , testCaseSteps "simple-cabal" $ testDirectory isCabalCradle "./tests/projects/simple-cabal" "B.hs"            , testCaseSteps "simple-direct" $ testDirectory isDirectCradle "./tests/projects/simple-direct" "B.hs"@@ -165,8 +171,13 @@       ]  linuxExlusiveTestCases :: [TestTree]-linuxExlusiveTestCases =-  [ testCaseSteps "simple-bios" $ testDirectory isBiosCradle "./tests/projects/simple-bios" "B.hs" | not isWindows ]+linuxExlusiveTestCases+  | not isWindows+  = [ testCaseSteps "simple-bios" $ testDirectory isBiosCradle "./tests/projects/simple-bios" "B.hs"+    , testCaseSteps "simple-bios-ghc" $ testDirectory isBiosCradle "./tests/projects/simple-bios-ghc" "B.hs"+    ]+  | otherwise+  = []  testDirectory :: (Cradle Void -> Bool) -> FilePath -> FilePath -> (String -> IO ()) -> IO () testDirectory cradlePred rootDir file step =@@ -200,13 +211,27 @@ testGetGhcVersion crd =   getRuntimeGhcVersion crd `shouldReturn` CradleSuccess VERSION_ghc +testGetGhcVersionFail :: (Cradle Void -> Bool) -> FilePath -> FilePath -> (CradleError -> Expectation) -> (String -> IO ()) -> IO ()+testGetGhcVersionFail cradlePred rootDir file cradleFailPred step =+  testCradle cradlePred rootDir file step $ \crd _ -> do+    res <- getRuntimeGhcVersion crd++    case res of+      CradleSuccess _ -> liftIO $ expectationFailure "Cradle loaded successfully"+      CradleNone -> liftIO $ expectationFailure "Unexpected none-Cradle"+      CradleFail crdlFail -> liftIO $ cradleFailPred crdlFail+ testDirectoryFail :: (Cradle Void -> Bool) -> FilePath -> FilePath -> (CradleError -> Expectation) -> (String -> IO ()) -> IO ()-testDirectoryFail cradlePred rootDir file cradleFailPred step = do-  withTempCopy rootDir $ \rootDir' -> do+testDirectoryFail cradlePred rootDir file cradleFailPred step =+  testCradle cradlePred rootDir file step $ \crd fp ->+    testLoadFileCradleFail crd fp cradleFailPred step++testCradle :: (Cradle Void -> Bool) -> FilePath -> FilePath -> (String -> IO ()) -> (Cradle Void -> FilePath -> IO a) -> IO a+testCradle cradlePred rootDir file step cont = withTempCopy rootDir $ \rootDir' -> do     fp <- canonicalizePath (rootDir' </> file)     crd <- initialiseCradle cradlePred fp step     step "Initialise Flags"-    testLoadFileCradleFail crd fp cradleFailPred step+    cont crd fp  initialiseCradle :: (Cradle Void -> Bool) -> FilePath -> (String -> IO ()) -> IO (Cradle Void) initialiseCradle cradlePred a_fp step = do
tests/ParserTests.hs view
@@ -20,11 +20,11 @@     assertParser "cabal-1.yaml" (noDeps (Cabal (Just "lib:hie-bios")))     assertParser "stack-config.yaml" (noDeps (Stack Nothing))     --assertParser "bazel.yaml" (noDeps Bazel)-    assertParser "bios-1.yaml" (noDeps (Bios (Program "program") Nothing))-    assertParser "bios-2.yaml" (noDeps (Bios (Program "program") (Just (Program "dep-program"))))-    assertParser "bios-3.yaml" (noDeps (Bios (Command "shellcommand") Nothing))-    assertParser "bios-4.yaml" (noDeps (Bios (Command "shellcommand") (Just (Command "dep-shellcommand"))))-    assertParser "bios-5.yaml" (noDeps (Bios (Command "shellcommand") (Just (Program "dep-program"))))+    assertParser "bios-1.yaml" (noDeps (Bios (Program "program") Nothing Nothing))+    assertParser "bios-2.yaml" (noDeps (Bios (Program "program") (Just (Program "dep-program")) Nothing))+    assertParser "bios-3.yaml" (noDeps (Bios (Command "shellcommand") Nothing Nothing))+    assertParser "bios-4.yaml" (noDeps (Bios (Command "shellcommand") (Just (Command "dep-shellcommand")) Nothing))+    assertParser "bios-5.yaml" (noDeps (Bios (Command "shellcommand") (Just (Program "dep-program")) Nothing))     assertParser "dependencies.yaml" (Config (CradleConfig ["depFile"] (Cabal (Just "lib:hie-bios"))))     assertParser "direct.yaml" (noDeps (Direct ["list", "of", "arguments"]))     assertParser "none.yaml" (noDeps None)
+ tests/projects/failing-bios-ghc/A.hs view
@@ -0,0 +1,1 @@+module A where
+ tests/projects/failing-bios-ghc/B.hs view
@@ -0,0 +1,3 @@+module B where++import A
+ tests/projects/failing-bios-ghc/hie.yaml view
@@ -0,0 +1,7 @@+cradle:+  bios:+    shell:+      echo "-Wall" >> %HIE_BIOS_OUTPUT%+      echo "A" >> %HIE_BIOS_OUTPUT%+      echo "B" >> %HIE_BIOS_OUTPUT%+    with-ghc: myGhc
+ tests/projects/simple-bios-ghc/A.hs view
@@ -0,0 +1,1 @@+module A where
+ tests/projects/simple-bios-ghc/B.hs view
@@ -0,0 +1,3 @@+module B where++import A
+ tests/projects/simple-bios-ghc/hie-bios.sh view
@@ -0,0 +1,3 @@+echo "-Wall" >> $HIE_BIOS_OUTPUT+echo "A" >> $HIE_BIOS_OUTPUT+echo "B" >> $HIE_BIOS_OUTPUT
+ tests/projects/simple-bios-ghc/hie.yaml view
@@ -0,0 +1,2 @@+cradle:+  bios: {program: ./hie-bios.sh, with-ghc: ghc }