Skip to content

Commit

Permalink
Store dependencies in CradleError
Browse files Browse the repository at this point in the history
This allows you to attempt to rerun a failed cradle if any of the
dependencies change. It is not a very precise measure of why a cradle
failed but better than nothing.
  • Loading branch information
mpickering committed May 8, 2020
1 parent 6460ab4 commit 583c0cc
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion exe/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ main = flip E.catches handlers $ do
res <- forM remainingArgs $ \fp -> do
res <- getCompilerOptions fp cradle
case res of
CradleFail (CradleError _ex err) ->
CradleFail (CradleError _deps _ex err) ->
return $ "Failed to show flags for \""
++ fp
++ "\": " ++ show err
Expand Down
8 changes: 4 additions & 4 deletions src/HIE/Bios/Cradle.hs
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ multiAction buildCustomCradle cur_dir cs l cur_fp =
<$> mapM (\(p, c) -> (,c) <$> (canonicalizePath (cur_dir </> p))) cs

selectCradle [] =
return (CradleFail (CradleError ExitSuccess err_msg))
return (CradleFail (CradleError [] ExitSuccess err_msg))
selectCradle ((p, c): css) =
if p `isPrefixOf` cur_fp
then runCradle
Expand Down Expand Up @@ -428,7 +428,7 @@ cabalAction work_dir mc l fp = do
readProcessWithOutputFile l work_dir "cabal" cab_args
deps <- cabalCradleDependencies work_dir
case processCabalWrapperArgs args of
Nothing -> pure $ CradleFail (CradleError ex
Nothing -> pure $ CradleFail (CradleError deps ex
["Failed to parse result of calling cabal"
, unlines output
, unlines stde
Expand Down Expand Up @@ -496,7 +496,7 @@ stackAction work_dir mc l _fp = do
pkg_ghc_args = concatMap (\p -> ["-package-db", p] ) split_pkgs
deps <- stackCradleDependencies work_dir
return $ case processCabalWrapperArgs args of
Nothing -> CradleFail (CradleError ex1 $
Nothing -> CradleFail (CradleError deps ex1 $
("Failed to parse result of calling stack":
stde)
++ args)
Expand Down Expand Up @@ -676,7 +676,7 @@ readProcessInDirectory wdir p args = (proc p args) { cwd = Just wdir }
makeCradleResult :: (ExitCode, [String], FilePath, [String]) -> [FilePath] -> CradleLoadResult ComponentOptions
makeCradleResult (ex, err, componentDir, gopts) deps =
case ex of
ExitFailure _ -> CradleFail (CradleError ex err)
ExitFailure _ -> CradleFail (CradleError deps ex err)
_ ->
let compOpts = ComponentOptions gopts componentDir deps
in CradleSuccess compOpts
5 changes: 3 additions & 2 deletions src/HIE/Bios/Internal/Debug.hs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ debugInfo fp cradle = unlines <$> do
, "Cradle: " ++ crdl
, "Dependencies: " ++ unwords deps
]
CradleFail (CradleError ext stderr) ->
CradleFail (CradleError deps ext stderr) ->
return ["Cradle failed to load"
, "Deps: " ++ show deps
, "Exit Code: " ++ show ext
, "Stderr: " ++ unlines stderr]
CradleNone ->
Expand Down Expand Up @@ -96,4 +97,4 @@ findCradle' fp =
return $ show crdl
Nothing -> do
crdl <- loadImplicitCradle fp :: IO (Cradle Void)
return $ show crdl
return $ show crdl
6 changes: 3 additions & 3 deletions src/HIE/Bios/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,16 @@ data CradleLoadResult r
deriving (Functor, Show)


data CradleError = CradleError ExitCode [String] deriving (Show)
data CradleError = CradleError [FilePath] ExitCode [String] deriving (Show)

instance Exception CradleError where
----------------------------------------------------------------

-- | Option information for GHC
data ComponentOptions = ComponentOptions {
componentOptions :: [String] -- ^ Command line options.
, componentRoot :: FilePath
-- ^ Root directory of the component. All 'componentOptions' are either
, componentRoot :: FilePath
-- ^ Root directory of the component. All 'componentOptions' are either
-- absolute, or relative to this directory.
, componentDependencies :: [FilePath]
-- ^ Dependencies of a cradle that might change the cradle.
Expand Down

0 comments on commit 583c0cc

Please sign in to comment.