Skip to content

Commit

Permalink
Finer specification of compiler versions #736
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
mgsloan committed Aug 14, 2015
1 parent a3236ee commit fcedab0
Show file tree
Hide file tree
Showing 14 changed files with 271 additions and 206 deletions.
11 changes: 7 additions & 4 deletions src/Stack/Build/Source.hs
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,13 @@ parseTargetsFromBuildOpts needTargets bopts = do
ResolverSnapshot snapName -> do
$logDebug $ "Checking resolver: " <> renderSnapName snapName
loadMiniBuildPlan snapName
ResolverGhc ghc ->
return
MiniBuildPlan
{ mbpGhcVersion = fromMajorVersion ghc
ResolverCompiler _ -> do
-- We ignore the resolver version, as it might be
-- GhcMajorVersion, and we want the exact version
-- we're using.
version <- asks (envConfigGhcVersion . getEnvConfig)
return MiniBuildPlan
{ mbpGhcVersion = version
, mbpPackages = Map.empty
}
ResolverCustom _ url -> do
Expand Down
4 changes: 2 additions & 2 deletions src/Stack/BuildPlan.hs
Original file line number Diff line number Diff line change
Expand Up @@ -735,7 +735,7 @@ data CustomSnapshot = CustomSnapshot
instance FromJSON CustomSnapshot where
parseJSON = withObject "CustomSnapshot" $ \o -> CustomSnapshot
<$> ((o .: "compiler") >>= (\t -> maybe (fail $ "Invalid compiler: " ++ T.unpack t) return $ do
t' <- T.stripPrefix "ghc-" t
parseVersionFromString $ T.unpack t'))
GhcVersion v <- parseCompilerVersion t
return v))
<*> o .: "packages"
<*> o .:? "flags" .!= Map.empty
12 changes: 7 additions & 5 deletions src/Stack/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ configFromConfigMonoid configStackRoot mproject configMonoid@ConfigMonoid{..} =

configImage = Image.imgOptsFromMonoid configMonoidImageOpts

configCompilerCheck = fromMaybe MatchMinor configMonoidCompilerCheck

origEnv <- getEnvOverride configPlatform
let configEnvOverride _ = return origEnv

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

ghcVersion <-
wantedCompiler <-
case projectResolver project of
ResolverSnapshot snapName -> do
mbp <- runReaderT (loadMiniBuildPlan snapName) miniConfig
return $ mbpGhcVersion mbp
ResolverGhc m -> return $ fromMajorVersion m
return $ GhcVersion $ mbpGhcVersion mbp
ResolverCustom _name url -> do
mbp <- runReaderT (parseCustomMiniBuildPlan stackYamlFP url) miniConfig
return $ mbpGhcVersion mbp
return $ GhcVersion $ mbpGhcVersion mbp
ResolverCompiler wantedCompiler -> return wantedCompiler

return BuildConfig
{ bcConfig = config
, bcResolver = projectResolver project
, bcGhcVersionExpected = ghcVersion
, bcWantedCompiler = wantedCompiler
, bcPackageEntries = projectPackages project
, bcExtraDeps = projectExtraDeps project
, bcStackYaml = stackYamlFP
Expand Down
4 changes: 2 additions & 2 deletions src/Stack/Fetch.hs
Original file line number Diff line number Diff line change
Expand Up @@ -335,14 +335,14 @@ fuzzyLookupCandidates (PackageIdentifier name ver) caches =
if null sameMajor then Nothing else Just (map fst sameMajor)
where
sameMajor = filter (\(PackageIdentifier _ v, _) ->
getMajorVersion ver == getMajorVersion v)
toMajorVersion ver == toMajorVersion v)
sameIdentCaches
sameIdentCaches = maybe biggerFiltered
(\z -> (zeroIdent, z) : biggerFiltered)
zeroVer
biggerFiltered = takeWhile (\(PackageIdentifier n _, _) -> name == n)
(Map.toList bigger)
zeroIdent = PackageIdentifier name (fromMajorVersion (MajorVersion 0 0))
zeroIdent = PackageIdentifier name $(mkVersion "0.0")
(_, zeroVer, bigger) = Map.splitLookup zeroIdent caches

-- | Figure out where to fetch from.
Expand Down
4 changes: 2 additions & 2 deletions src/Stack/Init.hs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ getDefaultResolver cabalfps gpds initOpts =
mpair <-
case resolver of
ResolverSnapshot name -> findBuildPlan gpds [name]
ResolverGhc _ -> return Nothing
ResolverCompiler _ -> return Nothing
ResolverCustom _ _ -> return Nothing
case mpair of
Just (snap, flags) ->
Expand All @@ -157,7 +157,7 @@ getDefaultResolver cabalfps gpds initOpts =
MethodSolver -> do
(ghcVersion, extraDeps) <- cabalSolver (map parent cabalfps) Map.empty []
return
( ResolverGhc ghcVersion
( ResolverCompiler (GhcVersion ghcVersion)
, Map.filter (not . Map.null) $ fmap snd extraDeps
, fmap fst extraDeps
)
Expand Down
Loading

0 comments on commit fcedab0

Please sign in to comment.