Skip to content

Commit fcedab0

Browse files
committed
Finer specification of compiler versions commercialhaskell#736
* Stack now defaults to matching the minor version specified in the resolver / snapshot, whereas before only the major version was significant. * Adds a 'compiler-check' field which specifies a policy for checking the GHC version. * Changes the format of stack-setup.yaml, and so changes which URL is used to find it (in order to not break old stack versions). * Refactors ensureTool code, as it already had a lot of special cases, which I found confusing. Main cause is that I needed to pass in a 'CompilerVersion' instead of 'Version', but just for installing ghc, not for git. * Introduces a 'CompilerVersion' type, and changes some naming to specify that compiler versions are being passed around rather than ghc versions. The change could be a simpler without this, but this will be helpful for GHCJS support.
1 parent a3236ee commit fcedab0

14 files changed

Lines changed: 271 additions & 206 deletions

File tree

src/Stack/Build/Source.hs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,13 @@ parseTargetsFromBuildOpts needTargets bopts = do
143143
ResolverSnapshot snapName -> do
144144
$logDebug $ "Checking resolver: " <> renderSnapName snapName
145145
loadMiniBuildPlan snapName
146-
ResolverGhc ghc ->
147-
return
148-
MiniBuildPlan
149-
{ mbpGhcVersion = fromMajorVersion ghc
146+
ResolverCompiler _ -> do
147+
-- We ignore the resolver version, as it might be
148+
-- GhcMajorVersion, and we want the exact version
149+
-- we're using.
150+
version <- asks (envConfigGhcVersion . getEnvConfig)
151+
return MiniBuildPlan
152+
{ mbpGhcVersion = version
150153
, mbpPackages = Map.empty
151154
}
152155
ResolverCustom _ url -> do

src/Stack/BuildPlan.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -735,7 +735,7 @@ data CustomSnapshot = CustomSnapshot
735735
instance FromJSON CustomSnapshot where
736736
parseJSON = withObject "CustomSnapshot" $ \o -> CustomSnapshot
737737
<$> ((o .: "compiler") >>= (\t -> maybe (fail $ "Invalid compiler: " ++ T.unpack t) return $ do
738-
t' <- T.stripPrefix "ghc-" t
739-
parseVersionFromString $ T.unpack t'))
738+
GhcVersion v <- parseCompilerVersion t
739+
return v))
740740
<*> o .: "packages"
741741
<*> o .:? "flags" .!= Map.empty

src/Stack/Config.hs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ configFromConfigMonoid configStackRoot mproject configMonoid@ConfigMonoid{..} =
137137

138138
configImage = Image.imgOptsFromMonoid configMonoidImageOpts
139139

140+
configCompilerCheck = fromMaybe MatchMinor configMonoidCompilerCheck
141+
140142
origEnv <- getEnvOverride configPlatform
141143
let configEnvOverride _ = return origEnv
142144

@@ -281,20 +283,20 @@ loadBuildConfig mproject config stackRoot mresolver = do
281283
(MiniConfig manager config)
282284
let project = project' { projectResolver = resolver }
283285

284-
ghcVersion <-
286+
wantedCompiler <-
285287
case projectResolver project of
286288
ResolverSnapshot snapName -> do
287289
mbp <- runReaderT (loadMiniBuildPlan snapName) miniConfig
288-
return $ mbpGhcVersion mbp
289-
ResolverGhc m -> return $ fromMajorVersion m
290+
return $ GhcVersion $ mbpGhcVersion mbp
290291
ResolverCustom _name url -> do
291292
mbp <- runReaderT (parseCustomMiniBuildPlan stackYamlFP url) miniConfig
292-
return $ mbpGhcVersion mbp
293+
return $ GhcVersion $ mbpGhcVersion mbp
294+
ResolverCompiler wantedCompiler -> return wantedCompiler
293295

294296
return BuildConfig
295297
{ bcConfig = config
296298
, bcResolver = projectResolver project
297-
, bcGhcVersionExpected = ghcVersion
299+
, bcWantedCompiler = wantedCompiler
298300
, bcPackageEntries = projectPackages project
299301
, bcExtraDeps = projectExtraDeps project
300302
, bcStackYaml = stackYamlFP

src/Stack/Fetch.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,14 +335,14 @@ fuzzyLookupCandidates (PackageIdentifier name ver) caches =
335335
if null sameMajor then Nothing else Just (map fst sameMajor)
336336
where
337337
sameMajor = filter (\(PackageIdentifier _ v, _) ->
338-
getMajorVersion ver == getMajorVersion v)
338+
toMajorVersion ver == toMajorVersion v)
339339
sameIdentCaches
340340
sameIdentCaches = maybe biggerFiltered
341341
(\z -> (zeroIdent, z) : biggerFiltered)
342342
zeroVer
343343
biggerFiltered = takeWhile (\(PackageIdentifier n _, _) -> name == n)
344344
(Map.toList bigger)
345-
zeroIdent = PackageIdentifier name (fromMajorVersion (MajorVersion 0 0))
345+
zeroIdent = PackageIdentifier name $(mkVersion "0.0")
346346
(_, zeroVer, bigger) = Map.splitLookup zeroIdent caches
347347

348348
-- | Figure out where to fetch from.

src/Stack/Init.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ getDefaultResolver cabalfps gpds initOpts =
148148
mpair <-
149149
case resolver of
150150
ResolverSnapshot name -> findBuildPlan gpds [name]
151-
ResolverGhc _ -> return Nothing
151+
ResolverCompiler _ -> return Nothing
152152
ResolverCustom _ _ -> return Nothing
153153
case mpair of
154154
Just (snap, flags) ->
@@ -157,7 +157,7 @@ getDefaultResolver cabalfps gpds initOpts =
157157
MethodSolver -> do
158158
(ghcVersion, extraDeps) <- cabalSolver (map parent cabalfps) Map.empty []
159159
return
160-
( ResolverGhc ghcVersion
160+
( ResolverCompiler (GhcVersion ghcVersion)
161161
, Map.filter (not . Map.null) $ fmap snd extraDeps
162162
, fmap fst extraDeps
163163
)

0 commit comments

Comments
 (0)