-
Notifications
You must be signed in to change notification settings - Fork 65
Explicitly model more dependencies on cradle startup #463
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
base: master
Are you sure you want to change the base?
Changes from 1 commit
4b8fe70
d7f1bc3
3025d2d
0485f71
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,7 +57,8 @@ | |
import qualified Data.Conduit as C | ||
import qualified Data.Conduit.Text as C | ||
import qualified Data.HashMap.Strict as Map | ||
import Data.Maybe (fromMaybe) | ||
import Data.Foldable (for_) | ||
import Data.Maybe (fromMaybe, isJust, maybe) | ||
Check warning on line 61 in src/HIE/Bios/Cradle.hs
|
||
import Data.List | ||
import Data.List.Extra (trimEnd, nubOrd) | ||
import Data.Ord (Down(..)) | ||
|
@@ -155,15 +156,15 @@ | |
-- each prefix we know how to handle | ||
data ResolvedCradles a | ||
= ResolvedCradles | ||
{ cradleRoot :: FilePath | ||
Check warning on line 159 in src/HIE/Bios/Cradle.hs
|
||
, resolvedCradles :: [ResolvedCradle a] -- ^ In order of decreasing specificity | ||
Check warning on line 160 in src/HIE/Bios/Cradle.hs
|
||
, cradleBuildToolVersions :: BuildToolVersions | ||
} | ||
|
||
type BuildToolVersions = BuildToolVersions' (Maybe Version) | ||
data BuildToolVersions' v = | ||
BuildToolVersions { cabalVersion :: v | ||
, stackVersion :: v | ||
Check warning on line 167 in src/HIE/Bios/Cradle.hs
|
||
} | ||
deriving (Functor, Foldable, Traversable) | ||
|
||
|
@@ -280,7 +281,7 @@ | |
|
||
|
||
resolveCradleAction :: Show a => LogAction IO (WithSeverity Log) -> (b -> CradleAction a) -> ResolvedCradles b -> FilePath -> ResolvedCradle b -> IO (CradleAction a) | ||
resolveCradleAction l buildCustomCradle cs root cradle = fmap addLoadStyleLogToCradleAction $ | ||
Check warning on line 284 in src/HIE/Bios/Cradle.hs
|
||
case concreteCradle cradle of | ||
ConcreteCabal t -> cabalCradle l cs root (cabalComponent t) (projectConfigFromMaybe root (cabalProjectFile t)) | ||
ConcreteStack t -> pure $ stackCradle l root (stackComponent t) (projectConfigFromMaybe root (stackYaml t)) | ||
|
@@ -479,7 +480,7 @@ | |
, runCradle = biosAction runGhcCmd wdir biosCall biosDepsCall l | ||
, runGhcCmd = runGhcCmd | ||
} | ||
where runGhcCmd = \args -> readProcessWithCwd l wdir (fromMaybe "ghc" mbGhc) args "" | ||
Check warning on line 483 in src/HIE/Bios/Cradle.hs
|
||
|
||
biosWorkDir :: FilePath -> MaybeT IO FilePath | ||
biosWorkDir = findFileUpwards ".hie-bios" | ||
|
@@ -506,15 +507,14 @@ | |
-> FilePath | ||
-> LoadStyle | ||
-> IO (CradleLoadResult ComponentOptions) | ||
biosAction runGhcCmd wdir bios bios_deps l fp loadStyle = do | ||
Check warning on line 510 in src/HIE/Bios/Cradle.hs
|
||
ghc_version <- getGhcVersion runGhcCmd | ||
determinedLoadStyle <- case ghc_version of | ||
Just ghc | ||
-- Multi-component supported from ghc 9.4 | ||
-- We trust the assertion for a bios program, as we have no way of | ||
-- checking its version | ||
| LoadWithContext _ <- loadStyle -> | ||
if ghc >= makeVersion [9,4] | ||
if isCabalMultipleCompSupported Nothing (Just ghc) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can just do |
||
then pure loadStyle | ||
else do | ||
liftIO $ l <& WithSeverity | ||
|
@@ -596,10 +596,10 @@ | |
CradleSuccess out -> out | ||
_ -> Nothing | ||
|
||
ghcPath = fst <$> cabalPathOutput | ||
Check warning on line 599 in src/HIE/Bios/Cradle.hs
|
||
ghcVersion = snd =<< cabalPathOutput | ||
|
||
runGhcCmd args = runCradleResultT $ do | ||
Check warning on line 602 in src/HIE/Bios/Cradle.hs
|
||
case ghcPath of | ||
Just p -> readProcessWithCwd_ l wdir p args "" | ||
Nothing -> do | ||
|
@@ -630,7 +630,7 @@ | |
-- 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 :: LogAction IO (WithSeverity Log) -> CradleProjectConfig -> FilePath -> Maybe FilePath -> String -> [String] -> CradleLoadResultT IO CreateProcess | ||
cabalProcess l cabalProject workDir ghcPath command args = do | ||
Check warning on line 633 in src/HIE/Bios/Cradle.hs
|
||
ghcDirs@(ghcBin, libdir) <- case ghcPath of | ||
Just p -> do | ||
libdir <- readProcessWithCwd_ l workDir p ["--print-libdir"] "" | ||
|
@@ -885,12 +885,11 @@ | |
isCabalPathSupported :: BuildToolVersions -> Bool | ||
isCabalPathSupported = maybe False (>= makeVersion [3,14]) . cabalVersion | ||
|
||
isCabalMultipleCompSupported :: BuildToolVersions -> Maybe Version -> Bool | ||
isCabalMultipleCompSupported vs ghcVersion = do | ||
-- determine which load style is supported by this cabal cradle. | ||
case (cabalVersion vs, ghcVersion) of | ||
(Just cabal, Just ghc) -> ghc >= makeVersion [9, 4] && cabal >= makeVersion [3, 11] | ||
_ -> False | ||
isCabalMultipleCompSupported :: Maybe BuildToolVersions -> Maybe Version -> Bool | ||
isCabalMultipleCompSupported mvs ghcVersion = isJust $ do | ||
let atLeast v = guard . maybe False (makeVersion v <=) | ||
atLeast [9,4] ghcVersion | ||
for_ mvs $ \vs -> atLeast [3,11] $ cabalVersion vs -- Only gate on cabal version if known | ||
|
||
cabalAction | ||
:: ResolvedCradles a | ||
|
@@ -904,7 +903,7 @@ | |
-> LoadStyle | ||
-> CradleLoadResultT IO ComponentOptions | ||
cabalAction (ResolvedCradles root cs vs) workDir ghcPath ghcVersion mc l projectFile fp loadStyle = do | ||
let multiCompSupport = isCabalMultipleCompSupported vs ghcVersion | ||
let multiCompSupport = isCabalMultipleCompSupported (Just vs) ghcVersion | ||
-- determine which load style is supported by this cabal cradle. | ||
determinedLoadStyle <- case loadStyle of | ||
LoadWithContext _ | not multiCompSupport -> do | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this one can be made pure again, but it needs some other changes first