Skip to content

Commit a19b2f5

Browse files
committed
Initial: split out NoLocal config values
1 parent 2744ee1 commit a19b2f5

16 files changed

Lines changed: 196 additions & 102 deletions

src/Stack/Build.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ build setLocalFiles mbuildLk boptsCli = fixCodePage $ do
100100
(targets, mbp, locals, extraToBuild, extraDeps, sourceMap) <- loadSourceMapFull NeedTargets boptsCli
101101

102102
-- Set local files, necessary for file watching
103-
stackYaml <- asks $ bcStackYaml . getBuildConfig
103+
stackYaml <- asks $ bcStackYaml . getBuildConfigLocal
104104
liftIO $ setLocalFiles
105105
$ Set.insert stackYaml
106106
$ Set.unions
@@ -158,7 +158,7 @@ allLocal =
158158
checkCabalVersion :: (StackM env m, HasEnvConfig env) => m ()
159159
checkCabalVersion = do
160160
allowNewer <- asks (configAllowNewer . getConfig)
161-
cabalVer <- asks (envConfigCabalVersion . getEnvConfig)
161+
cabalVer <- asks (envConfigCabalVersion . getEnvConfigLocal)
162162
-- https://github.com/haskell/cabal/issues/2023
163163
when (allowNewer && cabalVer < $(mkVersion "1.22")) $ throwM $
164164
CabalVersionException $
@@ -322,7 +322,7 @@ withLoadPackage menv inner = do
322322
, packageConfigEnableBenchmarks = False
323323
, packageConfigFlags = flags
324324
, packageConfigGhcOptions = ghcOptions
325-
, packageConfigCompilerVersion = envConfigCompilerVersion econfig
325+
, packageConfigCompilerVersion = envConfigCompilerVersion (ecLocal econfig)
326326
, packageConfigPlatform = configPlatform (getConfig econfig)
327327
}
328328

src/Stack/Build/Cache.hs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -253,8 +253,9 @@ precompiledCacheFile :: (MonadThrow m, MonadReader env m, HasEnvConfig env, Mona
253253
precompiledCacheFile pkgident copts installedPackageIDs = do
254254
ec <- asks getEnvConfig
255255

256-
compiler <- parseRelDir $ compilerVersionString $ envConfigCompilerVersion ec
257-
cabal <- parseRelDir $ versionString $ envConfigCabalVersion ec
256+
compiler <- parseRelDir $ compilerVersionString $ envConfigCompilerVersion
257+
$ ecLocal ec
258+
cabal <- parseRelDir $ versionString $ envConfigCabalVersion $ ecLocal ec
258259
pkg <- parseRelDir $ packageIdentifierString pkgident
259260
platformRelDir <- platformGhcRelDir
260261

@@ -266,7 +267,7 @@ precompiledCacheFile pkgident copts installedPackageIDs = do
266267
-- supplement it with the installed package IDs directly.
267268
-- See issue: https://github.com/commercialhaskell/stack/issues/1103
268269
let oldHash = B16.encode $ SHA256.hash $ LBS.toStrict $
269-
if envConfigCabalVersion ec >= $(mkVersion "1.22")
270+
if envConfigCabalVersion (ecLocal ec) >= $(mkVersion "1.22")
270271
then Binary.encode (coNoDirs copts)
271272
else Binary.encode input
272273
hashToPath hash = do

src/Stack/Build/ConstructPlan.hs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,10 @@ data Ctx = Ctx
139139
instance HasStackRoot Ctx
140140
instance HasPlatform Ctx
141141
instance HasGHCVariant Ctx
142-
instance HasConfig Ctx
142+
instance HasConfig Ctx where
143+
setConfig cfg ctx = ctx { ctxEnvConfig = setConfig cfg (ctxEnvConfig ctx) }
144+
instance HasBuildConfigNoLocal Ctx where
145+
getBuildConfigNoLocal = bcNoLocal . getBuildConfig
143146
instance HasBuildConfig Ctx where
144147
getBuildConfig = getBuildConfig . getEnvConfig
145148
instance HasEnvConfig Ctx where
@@ -195,7 +198,7 @@ constructPlan mbp0 baseConfigOpts0 locals extraToBuild0 localDumpPkgs loadPackag
195198
}
196199
else do
197200
planDebug $ show errs
198-
$prettyError $ pprintExceptions errs (bcStackYaml (getBuildConfig econfig)) parents (wantedLocalPackages locals)
201+
$prettyError $ pprintExceptions errs (bcStackYaml (getBuildConfigLocal econfig)) parents (wantedLocalPackages locals)
199202
throwM $ ConstructPlanFailed "Plan construction failed."
200203
where
201204
ctx econfig getVersions0 lf = Ctx

src/Stack/Build/Execute.hs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -266,10 +266,10 @@ getSetupExe :: (StackM env m, HasEnvConfig env)
266266
-> m (Maybe (Path Abs File))
267267
getSetupExe setupHs setupShimHs tmpdir = do
268268
wc <- getWhichCompiler
269-
econfig <- asks getEnvConfig
269+
econfig <- asks getEnvConfigLocal
270270
platformDir <- platformGhcRelDir
271-
let config = getConfig econfig
272-
baseNameS = concat
271+
config <- asks getConfig
272+
let baseNameS = concat
273273
[ "Cabal-simple_"
274274
, simpleSetupHash
275275
, "_"
@@ -353,7 +353,7 @@ withExecuteEnv menv bopts boptsCli baseConfigOpts locals globalPackages snapshot
353353
unless setupShimHsExists $ liftIO $ S.writeFile (toFilePath setupShimHs) setupGhciShimCode
354354
setupExe <- getSetupExe setupHs setupShimHs tmpdir
355355

356-
cabalPkgVer <- asks (envConfigCabalVersion . getEnvConfig)
356+
cabalPkgVer <- asks (envConfigCabalVersion . getEnvConfigLocal)
357357
globalDB <- getGlobalDB menv =<< getWhichCompiler
358358
snapshotPackagesTVar <- liftIO $ newTVarIO (toDumpPackagesByGhcPkgId snapshotPackages)
359359
localPackagesTVar <- liftIO $ newTVarIO (toDumpPackagesByGhcPkgId localPackages)
@@ -582,7 +582,7 @@ executePlan' :: (StackM env m, HasEnvConfig env)
582582
executePlan' installedMap0 targets plan ee@ExecuteEnv {..} = do
583583
when (toCoverage $ boptsTestOpts eeBuildOpts) deleteHpcReports
584584
wc <- getWhichCompiler
585-
cv <- asks $ envConfigCompilerVersion . getEnvConfig
585+
cv <- asks $ envConfigCompilerVersion . getEnvConfigLocal
586586
case Map.toList $ planUnregisterLocal plan of
587587
[] -> return ()
588588
ids -> do

src/Stack/Build/Source.hs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ loadSourceMapFull needTargets boptsCli = do
108108
-- Extend extra-deps to encompass targets requested on the command line
109109
-- that are not in the snapshot.
110110
extraDeps0 <- extendExtraDeps
111-
(bcExtraDeps bconfig)
111+
(bcExtraDeps (bcLocal bconfig))
112112
cliExtraDeps
113113
(Map.keysSet $ Map.filter (== STUnknown) targets)
114114

@@ -144,7 +144,7 @@ loadSourceMapFull needTargets boptsCli = do
144144
let flags =
145145
case ( Map.lookup (Just n) $ boptsCLIFlags boptsCli
146146
, Map.lookup Nothing $ boptsCLIFlags boptsCli
147-
, Map.lookup n $ unPackageFlags $ bcFlags bconfig
147+
, Map.lookup n $ unPackageFlags $ bcFlags $ bcLocal bconfig
148148
) of
149149
-- Didn't have any flag overrides, fall back to the flags
150150
-- defined in the snapshot.
@@ -186,7 +186,7 @@ getLocalFlags
186186
getLocalFlags bconfig boptsCli name = Map.unions
187187
[ Map.findWithDefault Map.empty (Just name) cliFlags
188188
, Map.findWithDefault Map.empty Nothing cliFlags
189-
, Map.findWithDefault Map.empty name (unPackageFlags (bcFlags bconfig))
189+
, Map.findWithDefault Map.empty name (unPackageFlags (bcFlags (bcLocal bconfig)))
190190
]
191191
where
192192
cliFlags = boptsCLIFlags boptsCli
@@ -207,7 +207,7 @@ getGhcOptions bconfig boptsCli name isTarget isLocal = concat
207207
]
208208
where
209209
bopts = configBuild config
210-
config = bcConfig bconfig
210+
config = getConfig bconfig
211211
includeExtraOptions =
212212
case configApplyGhcOptions config of
213213
AGOTargets -> isTarget
@@ -238,32 +238,32 @@ parseTargetsFromBuildOptsWith rawLocals needTargets boptscli = do
238238
$logDebug "Parsing the targets"
239239
bconfig <- asks getBuildConfig
240240
mbp0 <-
241-
case bcResolver bconfig of
241+
case bcResolver $ bcNoLocal bconfig of
242242
ResolverCompiler _ -> do
243243
-- We ignore the resolver version, as it might be
244244
-- GhcMajorVersion, and we want the exact version
245245
-- we're using.
246-
version <- asks (envConfigCompilerVersion . getEnvConfig)
246+
version <- asks (envConfigCompilerVersion . ecLocal . getEnvConfig)
247247
return MiniBuildPlan
248248
{ mbpCompilerVersion = version
249249
, mbpPackages = Map.empty
250250
}
251-
_ -> return (bcWantedMiniBuildPlan bconfig)
251+
_ -> return (bcWantedMiniBuildPlan (bcNoLocal bconfig))
252252
workingDir <- getCurrentDir
253253

254254
let snapshot = mpiVersion <$> mbpPackages mbp0
255255
flagExtraDeps <- convertSnapshotToExtra
256256
snapshot
257-
(bcExtraDeps bconfig)
257+
(bcExtraDeps (bcLocal bconfig))
258258
rawLocals
259259
(catMaybes $ Map.keys $ boptsCLIFlags boptscli)
260260

261261
(cliExtraDeps, targets) <-
262262
parseTargets
263263
needTargets
264-
(bcImplicitGlobal bconfig)
264+
(bcImplicitGlobal (bcLocal bconfig))
265265
snapshot
266-
(flagExtraDeps <> bcExtraDeps bconfig)
266+
(flagExtraDeps <> bcExtraDeps (bcLocal bconfig))
267267
(fst <$> rawLocals)
268268
workingDir
269269
(boptsCLITargets boptscli)
@@ -463,7 +463,7 @@ checkFlagsUsed boptsCli lps extraDeps snapshot = do
463463
-- Check if flags specified in stack.yaml and the command line are
464464
-- used, see https://github.com/commercialhaskell/stack/issues/617
465465
let flags = map (, FSCommandLine) [(k, v) | (Just k, v) <- Map.toList $ boptsCLIFlags boptsCli]
466-
++ map (, FSStackYaml) (Map.toList $ unPackageFlags $ bcFlags bconfig)
466+
++ map (, FSStackYaml) (Map.toList $ unPackageFlags $ bcFlags $ bcLocal bconfig)
467467

468468
localNameMap = Map.fromList $ map (packageName . lpPackage &&& lpPackage) lps
469469
checkFlagUsed ((name, userFlags), source) =
@@ -514,7 +514,7 @@ extendExtraDeps extraDeps0 cliExtraDeps unknowns = do
514514
throwM $ UnknownTargets
515515
(Set.fromList errs)
516516
Map.empty -- TODO check the cliExtraDeps for presence in index
517-
(bcStackYaml bconfig)
517+
(bcStackYaml (bcLocal bconfig))
518518
where
519519
extraDeps1 = Map.union extraDeps0 cliExtraDeps
520520
addUnknown pn = do
@@ -654,7 +654,7 @@ getDefaultPackageConfig = do
654654
, packageConfigEnableBenchmarks = False
655655
, packageConfigFlags = M.empty
656656
, packageConfigGhcOptions = []
657-
, packageConfigCompilerVersion = envConfigCompilerVersion econfig
657+
, packageConfigCompilerVersion = envConfigCompilerVersion (ecLocal econfig)
658658
, packageConfigPlatform = configPlatform $ getConfig bconfig
659659
}
660660

@@ -673,6 +673,6 @@ getPackageConfig boptsCli name isTarget isLocal = do
673673
, packageConfigEnableBenchmarks = False
674674
, packageConfigFlags = getLocalFlags bconfig boptsCli name
675675
, packageConfigGhcOptions = getGhcOptions bconfig boptsCli name isTarget isLocal
676-
, packageConfigCompilerVersion = envConfigCompilerVersion econfig
676+
, packageConfigCompilerVersion = envConfigCompilerVersion (ecLocal econfig)
677677
, packageConfigPlatform = configPlatform $ getConfig bconfig
678678
}

src/Stack/BuildPlan.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ resolveBuildPlan mbp isShadowed packages
216216
unknown = flip Map.mapWithKey (rsUnknown rs) $ \ident x ->
217217
(Map.lookup ident maxVer, x)
218218
throwM $ UnknownPackages
219-
(bcStackYaml bconfig)
219+
(bcStackYaml (bcLocal bconfig))
220220
unknown
221221
(rsShadowed rs)
222222
where

src/Stack/Config.hs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -543,16 +543,20 @@ loadBuildConfig mproject config mresolver mcompiler = do
543543
extraPackageDBs <- mapM resolveDir' (projectExtraPackageDBs project)
544544

545545
return BuildConfig
546-
{ bcConfig = config
547-
, bcResolver = loadedResolver
548-
, bcWantedMiniBuildPlan = mbp
549-
, bcPackageEntries = projectPackages project
550-
, bcExtraDeps = projectExtraDeps project
551-
, bcExtraPackageDBs = extraPackageDBs
552-
, bcStackYaml = stackYamlFP
553-
, bcFlags = projectFlags project
554-
, bcImplicitGlobal = isNothing mproject
555-
, bcGHCVariant = getGHCVariant miniConfig
546+
{ bcNoLocal = BuildConfigNoLocal
547+
{ bcConfig = config
548+
, bcResolver = loadedResolver
549+
, bcWantedMiniBuildPlan = mbp
550+
, bcGHCVariant = getGHCVariant miniConfig
551+
}
552+
, bcLocal = BuildConfigLocal
553+
{ bcPackageEntries = projectPackages project
554+
, bcExtraDeps = projectExtraDeps project
555+
, bcExtraPackageDBs = extraPackageDBs
556+
, bcStackYaml = stackYamlFP
557+
, bcFlags = projectFlags project
558+
, bcImplicitGlobal = isNothing mproject
559+
}
556560
}
557561

558562
-- | Get packages from EnvConfig, downloading and cloning as necessary.
@@ -561,7 +565,7 @@ getLocalPackages
561565
:: (StackMiniM env m, HasEnvConfig env)
562566
=> m (Map.Map (Path Abs Dir) TreatLikeExtraDep)
563567
getLocalPackages = do
564-
cacheRef <- asks (envConfigPackagesRef . getEnvConfig)
568+
cacheRef <- asks (envConfigPackagesRef . ecLocal . getEnvConfig)
565569
mcached <- liftIO $ readIORef cacheRef
566570
case mcached of
567571
Just cached -> return cached
@@ -570,7 +574,7 @@ getLocalPackages = do
570574
bconfig <- asks getBuildConfig
571575
liftM (Map.fromList . concat) $ mapM
572576
(resolvePackageEntry menv (bcRoot bconfig))
573-
(bcPackageEntries bconfig)
577+
(bcPackageEntries (bcLocal bconfig))
574578

575579
-- | Resolve a PackageEntry into a list of paths, downloading and cloning as
576580
-- necessary.

src/Stack/Constants.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ templatesDir config = configStackRoot config </> $(mkRelDir "templates")
155155
distRelativeDir :: (MonadThrow m, MonadReader env m, HasEnvConfig env)
156156
=> m (Path Rel Dir)
157157
distRelativeDir = do
158-
cabalPkgVer <- asks (envConfigCabalVersion . getEnvConfig)
158+
cabalPkgVer <- asks (envConfigCabalVersion . getEnvConfigLocal)
159159
platform <- platformGhcRelDir
160160
wc <- getWhichCompiler
161161
-- Cabal version, suffixed with "_ghcjs" if we're using GHCJS.

src/Stack/Coverage.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ tixFilePath pkgName testName = do
112112
generateHpcReport :: (StackM env m, HasEnvConfig env)
113113
=> Path Abs Dir -> Package -> [Text] -> m ()
114114
generateHpcReport pkgDir package tests = do
115-
compilerVersion <- asks (envConfigCompilerVersion . getEnvConfig)
115+
compilerVersion <- asks (envConfigCompilerVersion . getEnvConfigLocal)
116116
-- If we're using > GHC 7.10, the hpc 'include' parameter must specify a ghc package key. See
117117
-- https://github.com/commercialhaskell/stack/issues/785
118118
let pkgName = packageNameText (packageName package)
@@ -439,7 +439,7 @@ findPackageFieldForBuiltPackage pkgDir pkgId field = do
439439
case asum (map (T.stripPrefix (field <> ": ")) (T.lines contents)) of
440440
Just result -> return $ Right result
441441
Nothing -> notFoundErr
442-
cabalVer <- asks (envConfigCabalVersion . getEnvConfig)
442+
cabalVer <- asks (envConfigCabalVersion . getEnvConfigLocal)
443443
if cabalVer < $(mkVersion "1.24")
444444
then do
445445
path <- liftM (inplaceDir </>) $ parseRelFile (pkgIdStr ++ "-inplace.conf")

src/Stack/Ghci.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ makeGhciPkgInfo sourceMap installedMap locals addPkgs mfileTargets name cabalfp
561561
, packageConfigEnableBenchmarks = True
562562
, packageConfigFlags = getLocalFlags bconfig defaultBuildOptsCLI name
563563
, packageConfigGhcOptions = getGhcOptions bconfig defaultBuildOptsCLI name True True
564-
, packageConfigCompilerVersion = envConfigCompilerVersion econfig
564+
, packageConfigCompilerVersion = envConfigCompilerVersion (ecLocal econfig)
565565
, packageConfigPlatform = configPlatform (getConfig bconfig)
566566
}
567567
(warnings,gpkgdesc) <- readPackageUnresolved cabalfp

0 commit comments

Comments
 (0)