Skip to content

Commit

Permalink
Remove the NoLocal config type split
Browse files Browse the repository at this point in the history
This was originally done to help implementation of #2805, but we ended
up going a different route.
  • Loading branch information
snoyberg committed Feb 14, 2017
1 parent 2a17e0e commit 32e664f
Show file tree
Hide file tree
Showing 11 changed files with 89 additions and 189 deletions.
3 changes: 0 additions & 3 deletions src/Stack/Build/ConstructPlan.hs
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,7 @@ data Ctx = Ctx
instance HasPlatform Ctx
instance HasGHCVariant Ctx
instance HasConfig Ctx
instance HasBuildConfigNoLocal Ctx
instance HasBuildConfig Ctx
instance HasEnvConfigNoLocal Ctx where
envConfigNoLocalL = envConfigL.envConfigNoLocalL
instance HasEnvConfig Ctx where
envConfigL = lens ctxEnvConfig (\x y -> x { ctxEnvConfig = y })

Expand Down
19 changes: 9 additions & 10 deletions src/Stack/Build/Source.hs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ loadSourceMapFull omitWiredIn needTargets boptsCli = do
-- Extend extra-deps to encompass targets requested on the command line
-- that are not in the snapshot.
extraDeps0 <- extendExtraDeps
(bcExtraDeps $ bcLocal bconfig)
(bcExtraDeps bconfig)
cliExtraDeps
(Map.keysSet $ Map.filter (== STUnknown) targets)

Expand Down Expand Up @@ -145,7 +145,7 @@ loadSourceMapFull omitWiredIn needTargets boptsCli = do
let flags =
case ( Map.lookup (Just n) $ boptsCLIFlags boptsCli
, Map.lookup Nothing $ boptsCLIFlags boptsCli
, Map.lookup n $ unPackageFlags $ bcFlags $ bcLocal bconfig
, Map.lookup n $ unPackageFlags $ bcFlags bconfig
) of
-- Didn't have any flag overrides, fall back to the flags
-- defined in the snapshot.
Expand Down Expand Up @@ -195,7 +195,7 @@ getLocalFlags
getLocalFlags bconfig boptsCli name = Map.unions
[ Map.findWithDefault Map.empty (Just name) cliFlags
, Map.findWithDefault Map.empty Nothing cliFlags
, Map.findWithDefault Map.empty name (unPackageFlags (bcFlags (bcLocal bconfig)))
, Map.findWithDefault Map.empty name (unPackageFlags (bcFlags bconfig))
]
where
cliFlags = boptsCLIFlags boptsCli
Expand Down Expand Up @@ -245,8 +245,7 @@ parseTargetsFromBuildOptsWith
-> m (MiniBuildPlan, M.Map PackageName Version, M.Map PackageName SimpleTarget)
parseTargetsFromBuildOptsWith rawLocals needTargets boptscli = do
$logDebug "Parsing the targets"
bconfig <- view buildConfigNoLocalL
bconfigl <- view buildConfigLocalL
bconfig <- view buildConfigL
mbp0 <-
case bcResolver bconfig of
ResolverCompiler _ -> do
Expand All @@ -264,16 +263,16 @@ parseTargetsFromBuildOptsWith rawLocals needTargets boptscli = do
let snapshot = mpiVersion <$> mbpPackages mbp0
flagExtraDeps <- convertSnapshotToExtra
snapshot
(bcExtraDeps bconfigl)
(bcExtraDeps bconfig)
rawLocals
(catMaybes $ Map.keys $ boptsCLIFlags boptscli)

(cliExtraDeps, targets) <-
parseTargets
needTargets
(bcImplicitGlobal bconfigl)
(bcImplicitGlobal bconfig)
snapshot
(flagExtraDeps <> bcExtraDeps bconfigl)
(flagExtraDeps <> bcExtraDeps bconfig)
(fst <$> rawLocals)
workingDir
(boptsCLITargets boptscli)
Expand Down Expand Up @@ -460,7 +459,7 @@ checkFlagsUsed :: (MonadThrow m, MonadReader env m, HasBuildConfig env)
-> Map PackageName snapshot -- ^ snapshot, for error messages
-> m ()
checkFlagsUsed boptsCli lps extraDeps snapshot = do
bconfig <- view buildConfigLocalL
bconfig <- view buildConfigL

-- Check if flags specified in stack.yaml and the command line are
-- used, see https://github.com/commercialhaskell/stack/issues/617
Expand Down Expand Up @@ -512,7 +511,7 @@ extendExtraDeps extraDeps0 cliExtraDeps unknowns = do
case errs of
[] -> return $ Map.unions $ extraDeps1 : unknowns'
_ -> do
bconfig <- view buildConfigLocalL
bconfig <- view buildConfigL
throwM $ UnknownTargets
(Set.fromList errs)
Map.empty -- TODO check the cliExtraDeps for presence in index
Expand Down
2 changes: 1 addition & 1 deletion src/Stack/BuildPlan.hs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ resolveBuildPlan
resolveBuildPlan mbp isShadowed packages
| Map.null (rsUnknown rs) && Map.null (rsShadowed rs) = return (rsToInstall rs, rsUsedBy rs)
| otherwise = do
bconfig <- view buildConfigLocalL
bconfig <- view buildConfigL
(caches, _gitShaCaches) <- getPackageCaches
let maxVer =
Map.fromListWith max $
Expand Down
36 changes: 16 additions & 20 deletions src/Stack/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -587,24 +587,20 @@ loadBuildConfig mproject config mresolver mcompiler = do
extraPackageDBs <- mapM resolveDir' (projectExtraPackageDBs project)

return BuildConfig
{ bcNoLocal = BuildConfigNoLocal
{ bcConfig = config
, bcResolver = loadedResolver
, bcWantedMiniBuildPlan = mbp
, bcGHCVariant = view ghcVariantL miniConfig
}
, bcLocal = BuildConfigLocal
{ bcPackageEntries = projectPackages project
, bcExtraDeps = projectExtraDeps project
, bcExtraPackageDBs = extraPackageDBs
, bcStackYaml = stackYamlFP
, bcFlags = projectFlags project
, bcImplicitGlobal =
case mproject of
LCSNoProject -> True
LCSProject _ -> False
LCSNoConfig -> False
}
{ bcConfig = config
, bcResolver = loadedResolver
, bcWantedMiniBuildPlan = mbp
, bcGHCVariant = view ghcVariantL miniConfig
, bcPackageEntries = projectPackages project
, bcExtraDeps = projectExtraDeps project
, bcExtraPackageDBs = extraPackageDBs
, bcStackYaml = stackYamlFP
, bcFlags = projectFlags project
, bcImplicitGlobal =
case mproject of
LCSNoProject -> True
LCSProject _ -> False
LCSNoConfig -> False
}
where
miniConfig = loadMiniConfig config
Expand Down Expand Up @@ -635,14 +631,14 @@ getLocalPackages
:: (StackMiniM env m, HasEnvConfig env)
=> m (Map.Map (Path Abs Dir) TreatLikeExtraDep)
getLocalPackages = do
cacheRef <- view $ envConfigLocalL.to envConfigPackagesRef
cacheRef <- view $ envConfigL.to envConfigPackagesRef
mcached <- liftIO $ readIORef cacheRef
case mcached of
Just cached -> return cached
Nothing -> do
menv <- getMinimalEnvOverride
root <- view projectRootL
entries <- view $ buildConfigLocalL.to bcPackageEntries
entries <- view $ buildConfigL.to bcPackageEntries
liftM (Map.fromList . concat) $ mapM
(resolvePackageEntry menv root)
entries
Expand Down
6 changes: 2 additions & 4 deletions src/Stack/Ghci.hs
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ checkTargets
checkTargets mp = do
let filtered = M.filter (== STUnknown) mp
unless (M.null filtered) $ do
bconfig <- view buildConfigLocalL
bconfig <- view buildConfigL
throwM $ UnknownTargets (M.keysSet filtered) M.empty (bcStackYaml bconfig)

getAllLocalTargets
Expand Down Expand Up @@ -553,10 +553,8 @@ makeGhciPkgInfo
makeGhciPkgInfo sourceMap installedMap locals addPkgs mfileTargets name cabalfp target = do
bopts <- view buildOptsL
econfig <- view envConfigL
bconfignl <- view buildConfigNoLocalL
bconfigl <- view buildConfigLocalL
bconfig <- view buildConfigL
compilerVersion <- view actualCompilerVersionL
let bconfig = BuildConfig bconfignl bconfigl
let config =
PackageConfig
{ packageConfigEnableTests = True
Expand Down
12 changes: 4 additions & 8 deletions src/Stack/Path.hs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ path
path keys =
do -- We must use a BuildConfig from an EnvConfig to ensure that it contains the
-- full environment info including GHC paths etc.
bcnl <- view $ envConfigL.buildConfigNoLocalL
bcl <- view $ envConfigL.buildConfigLocalL
bc <- view $ envConfigL.buildConfigL
-- This is the modified 'bin-path',
-- including the local GHC or MSYS if not configured to operate on
-- global GHC.
Expand Down Expand Up @@ -80,7 +79,7 @@ path keys =
else key <> ": ") <>
path'
(PathInfo
(BuildConfig bcnl bcl)
bc
menv
snap
plocal
Expand Down Expand Up @@ -119,12 +118,9 @@ data PathInfo = PathInfo

instance HasPlatform PathInfo
instance HasConfig PathInfo
instance HasBuildConfigNoLocal PathInfo where
buildConfigNoLocalL = lens piBuildConfig (\x y -> x { piBuildConfig = y })
. buildConfigNoLocalL
instance HasBuildConfig PathInfo where
buildConfigLocalL = lens piBuildConfig (\x y -> x { piBuildConfig = y })
. buildConfigLocalL
buildConfigL = lens piBuildConfig (\x y -> x { piBuildConfig = y })
. buildConfigL

-- | The paths of interest to a user. The first tuple string is used
-- for a description that the optparse flag uses, and the second
Expand Down
44 changes: 16 additions & 28 deletions src/Stack/Setup.hs
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,8 @@ setupEnv :: (StackM env m, HasBuildConfig env, HasGHCVariant env)
-> m EnvConfig
setupEnv mResolveMissingGHC = do
config <- view configL
bconfig <- view buildConfigNoLocalL
stackYaml <- view $ buildConfigLocalL.to bcStackYaml
bconfig <- view buildConfigL
let stackYaml = bcStackYaml bconfig
platform <- view platformL
wcVersion <- view wantedCompilerVersionL
wc <- view $ wantedCompilerVersionL.whichCompilerL
Expand Down Expand Up @@ -253,19 +253,13 @@ setupEnv mResolveMissingGHC = do

$logDebug "Resolving package entries"
packagesRef <- liftIO $ newIORef Nothing
bcnl <- view buildConfigNoLocalL
bcl <- view buildConfigLocalL
bc <- view buildConfigL
let envConfig0 = EnvConfig
{ ecNoLocal = EnvConfigNoLocal
{ envConfigBuildConfigNoLocal = bcnl
, envConfigCabalVersion = cabalVer
, envConfigCompilerVersion = compilerVer
, envConfigCompilerBuild = compilerBuild
}
, ecLocal = EnvConfigLocal
{ envConfigBuildConfigLocal = bcl
, envConfigPackagesRef = packagesRef
}
{ envConfigBuildConfig = bc
, envConfigCabalVersion = cabalVer
, envConfigCompilerVersion = compilerVer
, envConfigCompilerBuild = compilerBuild
, envConfigPackagesRef = packagesRef
}

-- extra installation bin directories
Expand Down Expand Up @@ -335,22 +329,16 @@ setupEnv mResolveMissingGHC = do
(Map.insert es eo m', ())
return eo

bconfigl <- view buildConfigLocalL
return EnvConfig
{ ecNoLocal = EnvConfigNoLocal
{ envConfigBuildConfigNoLocal = bconfig
{ bcConfig = maybe id addIncludeLib mghcBin
(view configL bconfig)
{ configEnvOverride = getEnvOverride' }
}
, envConfigCabalVersion = cabalVer
, envConfigCompilerVersion = compilerVer
, envConfigCompilerBuild = compilerBuild
}
, ecLocal = EnvConfigLocal
{ envConfigBuildConfigLocal = bconfigl
, envConfigPackagesRef = envConfigPackagesRef $ ecLocal envConfig0
{ envConfigBuildConfig = bconfig
{ bcConfig = maybe id addIncludeLib mghcBin
(view configL bconfig)
{ configEnvOverride = getEnvOverride' }
}
, envConfigCabalVersion = cabalVer
, envConfigCompilerVersion = compilerVer
, envConfigCompilerBuild = compilerBuild
, envConfigPackagesRef = envConfigPackagesRef envConfig0
}

-- | Add the include and lib paths to the given Config
Expand Down
11 changes: 5 additions & 6 deletions src/Stack/Solver.hs
Original file line number Diff line number Diff line change
Expand Up @@ -622,10 +622,9 @@ solveExtraDeps
=> Bool -- ^ modify stack.yaml?
-> m ()
solveExtraDeps modStackYaml = do
bconfignl <- view buildConfigNoLocalL
bconfigl <- view buildConfigLocalL
bconfig <- view buildConfigL

let stackYaml = bcStackYaml bconfigl
let stackYaml = bcStackYaml bconfig
relStackYaml <- prettyPath stackYaml

$logInfo $ "Using configuration file: " <> T.pack relStackYaml
Expand All @@ -645,9 +644,9 @@ solveExtraDeps modStackYaml = do
(bundle, _) <- cabalPackagesCheck cabalfps noPkgMsg (Just dupPkgFooter)

let gpds = Map.elems $ fmap snd bundle
oldFlags = unPackageFlags (bcFlags bconfigl)
oldExtraVersions = bcExtraDeps bconfigl
resolver = bcResolver bconfignl
oldFlags = unPackageFlags (bcFlags bconfig)
oldExtraVersions = bcExtraDeps bconfig
resolver = bcResolver bconfig
oldSrcs = gpdPackages gpds
oldSrcFlags = Map.intersection oldFlags oldSrcs
oldExtraFlags = Map.intersection oldFlags oldExtraVersions
Expand Down
Loading

0 comments on commit 32e664f

Please sign in to comment.