Skip to content

Commit

Permalink
Use exact GHC versions rather than major-version #736
Browse files Browse the repository at this point in the history
* Requires the exact GHC version specified by the snapshot.

* Deprecates major-version (ghc-7.10, ghc-7.8) resolvers, but still
  supports them.  They resolve to the newest installed / available ghc
  matching that number.

* 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 13, 2015
1 parent a3236ee commit 57369d4
Show file tree
Hide file tree
Showing 19 changed files with 249 additions and 199 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
18 changes: 13 additions & 5 deletions src/Stack/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -281,20 +281,28 @@ loadBuildConfig mproject config stackRoot mresolver = do
(MiniConfig manager config)
let project = project' { projectResolver = resolver }

ghcVersion <-
expectedCompiler <-
case projectResolver project of
ResolverSnapshot snapName -> do
mbp <- runReaderT (loadMiniBuildPlan snapName) miniConfig
return $ mbpGhcVersion mbp
ResolverGhc m -> return $ fromMajorVersion m
return $ ExactVersion $ GhcVersion $ mbpGhcVersion mbp
ResolverCustom _name url -> do
mbp <- runReaderT (parseCustomMiniBuildPlan stackYamlFP url) miniConfig
return $ mbpGhcVersion mbp
return $ ExactVersion $ GhcVersion $ mbpGhcVersion mbp
r@(ResolverCompiler expected@(GhcMajorVersion version)) -> do
$logWarn $ T.concat
[ "Warning: you are using a deprecated major-version ghc resolver, "
, resolverName r
, ", which will be removed in a future version of stack."
, " Instead, please specify a full ghc version, such as ghc-7.10.2."
]
return expected
ResolverCompiler expected -> return expected

return BuildConfig
{ bcConfig = config
, bcResolver = projectResolver project
, bcGhcVersionExpected = ghcVersion
, bcExpectedCompiler = expectedCompiler
, 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 (ExactVersion (GhcVersion ghcVersion))
, Map.filter (not . Map.null) $ fmap snd extraDeps
, fmap fst extraDeps
)
Expand Down
Loading

0 comments on commit 57369d4

Please sign in to comment.