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

Multi Component cabal support #409

Merged
merged 3 commits into from
Aug 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions exe/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -63,28 +63,28 @@ main = do
hSetEncoding stdout utf8
cwd <- getCurrentDirectory
cmd <- execParser progInfo
cradle <-
-- find cradle does a takeDirectory on the argument, so make it into a file
findCradle (cwd </> "File.hs") >>= \case
Just yaml -> loadCradle yaml
Nothing -> loadImplicitCradle (cwd </> "File.hs")

let
printLog (L.WithSeverity l sev) = "[" ++ show sev ++ "] " ++ show (pretty l)
logger :: forall a . Pretty a => L.LogAction IO (L.WithSeverity a)
logger = L.cmap printLog L.logStringStderr

cradle <-
-- find cradle does a takeDirectory on the argument, so make it into a file
findCradle (cwd </> "File.hs") >>= \case
Just yaml -> loadCradle logger yaml
Nothing -> loadImplicitCradle logger (cwd </> "File.hs")

res <- case cmd of
Check targetFiles -> checkSyntax logger logger cradle targetFiles
Check targetFiles -> checkSyntax logger cradle targetFiles
Debug files -> case files of
[] -> debugInfo logger (cradleRootDir cradle) cradle
fp -> debugInfo logger fp cradle
[] -> debugInfo (cradleRootDir cradle) cradle
fp -> debugInfo fp cradle
Flags files -> case files of
-- TODO force optparse to acquire one
[] -> error "too few arguments"
_ -> do
res <- forM files $ \fp -> do
res <- getCompilerOptions logger fp cradle
res <- getCompilerOptions fp [] cradle
case res of
CradleFail (CradleError _deps _ex err) ->
return $ "Failed to show flags for \""
Expand All @@ -97,7 +97,7 @@ main = do
CradleNone -> return $ "No flags/None Cradle: component " ++ fp ++ " should not be loaded"
return (unlines res)
ConfigInfo files -> configInfo files
CradleInfo files -> cradleInfo files
CradleInfo files -> cradleInfo logger files
Root -> rootInfo cradle
Version -> return progVersion
putStr res
26 changes: 13 additions & 13 deletions src/HIE/Bios/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module HIE.Bios.Config(
pattern StackType,
stackComponent,
stackYaml,
CradleType(..),
CradleTree(..),
Callable(..)
) where

Expand Down Expand Up @@ -47,7 +47,7 @@ data CradleConfig a =
-- ^ Dependencies of a cradle.
-- Dependencies are expected to be relative to the root directory.
-- The given files are not required to exist.
, cradleType :: CradleType a
, cradleTree :: CradleTree a
-- ^ Type of the cradle to use. Actions to obtain
-- compiler flags from are dependant on this field.
}
Expand Down Expand Up @@ -100,7 +100,7 @@ pattern StackType { stackComponent, stackYaml } = StackType_ (Last stackComponen
instance Show StackType where
show = show . Stack

data CradleType a
data CradleTree a
= Cabal { cabalType :: !CabalType }
| CabalMulti { defaultCabal :: !CabalType, subCabalComponents :: [ (FilePath, CabalType) ] }
| Stack { stackType :: !StackType }
Expand All @@ -125,7 +125,7 @@ data CradleType a
| Other { otherConfig :: a, originalYamlValue :: Value }
deriving (Eq, Functor)

instance Show (CradleType a) where
instance Show (CradleTree a) where
show (Cabal comp) = "Cabal {component = " ++ show (cabalComponent comp) ++ "}"
show (CabalMulti d a) = "CabalMulti {defaultCabal = " ++ show d ++ ", subCabalComponents = " ++ show a ++ "}"
show (Stack comp) = "Stack {component = " ++ show (stackComponent comp) ++ ", stackYaml = " ++ show (stackYaml comp) ++ "}"
Expand Down Expand Up @@ -154,31 +154,31 @@ readConfig fp = do

fromYAMLConfig :: CradleConfigYAML a -> Config a
fromYAMLConfig cradleYAML = Config $ CradleConfig (fromMaybe [] $ YAML.dependencies cradleYAML)
(toCradleType $ YAML.cradle cradleYAML)
(toCradleTree $ YAML.cradle cradleYAML)

toCradleType :: YAML.CradleComponent a -> CradleType a
toCradleType (YAML.Multi cpts) =
toCradleTree :: YAML.CradleComponent a -> CradleTree a
toCradleTree (YAML.Multi cpts) =
Multi $ (\(YAML.MultiSubComponent fp' cfg) -> (fp', cradle $ fromYAMLConfig cfg)) <$> cpts
toCradleType (YAML.Stack (YAML.StackConfig yaml cpts)) =
toCradleTree (YAML.Stack (YAML.StackConfig yaml cpts)) =
case cpts of
YAML.NoComponent -> Stack $ StackType Nothing yaml
(YAML.SingleComponent c) -> Stack $ StackType (Just c) yaml
(YAML.ManyComponents cs) -> StackMulti (StackType Nothing yaml)
((\(YAML.StackComponent fp' c cYAML) ->
(fp', StackType (Just c) cYAML)) <$> cs)
toCradleType (YAML.Cabal (YAML.CabalConfig prjFile cpts)) =
toCradleTree (YAML.Cabal (YAML.CabalConfig prjFile cpts)) =
case cpts of
YAML.NoComponent -> Cabal $ CabalType Nothing prjFile
(YAML.SingleComponent c) -> Cabal $ CabalType (Just c) prjFile
(YAML.ManyComponents cs) -> CabalMulti (CabalType Nothing prjFile)
((\(YAML.CabalComponent fp' c cPrjFile) ->
(fp', CabalType (Just c) cPrjFile)) <$> cs)
toCradleType (YAML.Direct cfg) = Direct (YAML.arguments cfg)
toCradleType (YAML.Bios cfg) = Bios (toCallable $ YAML.callable cfg)
toCradleTree (YAML.Direct cfg) = Direct (YAML.arguments cfg)
toCradleTree (YAML.Bios cfg) = Bios (toCallable $ YAML.callable cfg)
(toCallable <$> YAML.depsCallable cfg)
(YAML.ghcPath cfg)
toCradleType (YAML.None _) = None
toCradleType (YAML.Other cfg) = Other (YAML.otherConfig cfg)
toCradleTree (YAML.None _) = None
toCradleTree (YAML.Other cfg) = Other (YAML.otherConfig cfg)
(YAML.originalYamlValue cfg)

toCallable :: YAML.Callable -> Callable
Expand Down
Loading