Skip to content

Commit

Permalink
Merge pull request #6312 from commercialhaskell/format
Browse files Browse the repository at this point in the history
Reformatting, for consistency
  • Loading branch information
mpilgrem authored Oct 21, 2023
2 parents c98ea8a + 40337d5 commit ede6fa4
Show file tree
Hide file tree
Showing 11 changed files with 567 additions and 535 deletions.
2 changes: 1 addition & 1 deletion .stan.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@

# Anti-pattern: Data.ByteString.Char8.pack
[[ignore]]
id = "OBS-STAN-0203-fki0nd-2614:3"
id = "OBS-STAN-0203-fki0nd-2626:3"
# ✦ Description: Usage of 'pack' function that doesn't handle Unicode characters
# ✦ Category: #AntiPattern
# ✦ File: src\Stack\Build\Execute.hs
Expand Down
8 changes: 7 additions & 1 deletion src/Stack/Build.hs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,13 @@ build msetLocalFiles = do
getInstalled installMap

baseConfigOpts <- mkBaseConfigOpts boptsCli
plan <- constructPlan baseConfigOpts localDumpPkgs loadPackage sourceMap installedMap (boptsCLIInitialBuildSteps boptsCli)
plan <- constructPlan
baseConfigOpts
localDumpPkgs
loadPackage
sourceMap
installedMap
(boptsCLIInitialBuildSteps boptsCli)

allowLocals <- view $ configL.to configAllowLocals
unless allowLocals $ case justLocals plan of
Expand Down
151 changes: 79 additions & 72 deletions src/Stack/Build/ConstructPlan.hs
Original file line number Diff line number Diff line change
Expand Up @@ -238,73 +238,81 @@ constructPlan ::
-> InstalledMap
-> Bool
-> RIO env Plan
constructPlan baseConfigOpts0 localDumpPkgs loadPackage0 sourceMap installedMap initialBuildSteps = do
logDebug "Constructing the build plan"

when hasBaseInDeps $
prettyWarn $
fillSep
[ flow "You are trying to upgrade or downgrade the"
, style Current "base"
, flow "package, which is almost certainly not what you really \
\want. Please, consider using another GHC version if you \
\need a certain version of"
, style Current "base" <> ","
, flow "or removing"
, style Current "base"
, flow "as an"
, style Shell "extra-deps" <> "."
, flow "For further information, see"
, style Url "https://github.com/commercialhaskell/stack/issues/3940" <> "."
]
<> line

econfig <- view envConfigL
globalCabalVersion <- view $ compilerPathsL.to cpCabalVersion
sources <- getSources globalCabalVersion
mcur <- view $ buildConfigL.to bcCurator

let onTarget = void . getCachedDepOrAddDep
let inner = mapM_ onTarget $ Map.keys (smtTargets $ smTargets sourceMap)
pathEnvVar' <- liftIO $ maybe mempty T.pack <$> lookupEnv "PATH"
let ctx = mkCtx econfig globalCabalVersion sources mcur pathEnvVar'
((), m, W efinals installExes dirtyReason warnings parents) <-
liftIO $ runRWST inner ctx Map.empty
mapM_ prettyWarn (warnings [])
let toEither (_, Left e) = Left e
toEither (k, Right v) = Right (k, v)
(errlibs, adrs) = partitionEithers $ map toEither $ Map.toList m
(errfinals, finals) = partitionEithers $ map toEither $ Map.toList efinals
errs = errlibs ++ errfinals
if null errs
then do
let toTask (_, ADRFound _ _) = Nothing
toTask (name, ADRToInstall task) = Just (name, task)
tasks = Map.fromList $ mapMaybe toTask adrs
takeSubset =
case boptsCLIBuildSubset $ bcoBuildOptsCLI baseConfigOpts0 of
BSAll -> pure
BSOnlySnapshot -> pure . stripLocals
BSOnlyDependencies ->
pure . stripNonDeps (Map.keysSet $ smDeps sourceMap)
BSOnlyLocals -> errorOnSnapshot
takeSubset Plan
{ planTasks = tasks
, planFinals = Map.fromList finals
, planUnregisterLocal =
mkUnregisterLocal tasks dirtyReason localDumpPkgs initialBuildSteps
, planInstallExes =
if boptsInstallExes (bcoBuildOpts baseConfigOpts0) ||
boptsInstallCompilerTool (bcoBuildOpts baseConfigOpts0)
then installExes
else Map.empty
}
else do
stackYaml <- view stackYamlL
stackRoot <- view stackRootL
isImplicitGlobal <- view $ configL.to (isPCGlobalProject . configProject)
prettyThrowM $ ConstructPlanFailed
errs stackYaml stackRoot isImplicitGlobal parents (wanted ctx) prunedGlobalDeps
constructPlan
baseConfigOpts0
localDumpPkgs
loadPackage0
sourceMap
installedMap
initialBuildSteps
= do
logDebug "Constructing the build plan"

when hasBaseInDeps $
prettyWarn $
fillSep
[ flow "You are trying to upgrade or downgrade the"
, style Current "base"
, flow "package, which is almost certainly not what you really \
\want. Please, consider using another GHC version if you \
\need a certain version of"
, style Current "base" <> ","
, flow "or removing"
, style Current "base"
, flow "as an"
, style Shell "extra-deps" <> "."
, flow "For further information, see"
, style Url "https://github.com/commercialhaskell/stack/issues/3940" <> "."
]
<> line

econfig <- view envConfigL
globalCabalVersion <- view $ compilerPathsL.to cpCabalVersion
sources <- getSources globalCabalVersion
mcur <- view $ buildConfigL.to bcCurator

let onTarget = void . getCachedDepOrAddDep
let inner = mapM_ onTarget $ Map.keys (smtTargets $ smTargets sourceMap)
pathEnvVar' <- liftIO $ maybe mempty T.pack <$> lookupEnv "PATH"
let ctx = mkCtx econfig globalCabalVersion sources mcur pathEnvVar'
((), m, W efinals installExes dirtyReason warnings parents) <-
liftIO $ runRWST inner ctx Map.empty
mapM_ prettyWarn (warnings [])
let toEither (_, Left e) = Left e
toEither (k, Right v) = Right (k, v)
(errlibs, adrs) = partitionEithers $ map toEither $ Map.toList m
(errfinals, finals) =
partitionEithers $ map toEither $ Map.toList efinals
errs = errlibs ++ errfinals
if null errs
then do
let toTask (_, ADRFound _ _) = Nothing
toTask (name, ADRToInstall task) = Just (name, task)
tasks = Map.fromList $ mapMaybe toTask adrs
takeSubset =
case boptsCLIBuildSubset $ bcoBuildOptsCLI baseConfigOpts0 of
BSAll -> pure
BSOnlySnapshot -> pure . stripLocals
BSOnlyDependencies ->
pure . stripNonDeps (Map.keysSet $ smDeps sourceMap)
BSOnlyLocals -> errorOnSnapshot
takeSubset Plan
{ planTasks = tasks
, planFinals = Map.fromList finals
, planUnregisterLocal =
mkUnregisterLocal tasks dirtyReason localDumpPkgs initialBuildSteps
, planInstallExes =
if boptsInstallExes (bcoBuildOpts baseConfigOpts0) ||
boptsInstallCompilerTool (bcoBuildOpts baseConfigOpts0)
then installExes
else Map.empty
}
else do
stackYaml <- view stackYamlL
stackRoot <- view stackRootL
isImplicitGlobal <- view $ configL.to (isPCGlobalProject . configProject)
prettyThrowM $ ConstructPlanFailed
errs stackYaml stackRoot isImplicitGlobal parents (wanted ctx) prunedGlobalDeps
where
hasBaseInDeps = Map.member (mkPackageName "base") (smDeps sourceMap)

Expand Down Expand Up @@ -1023,11 +1031,10 @@ addPackageDeps package = do
)
)
case partitionEithers deps of
-- Note that the Monoid for 'InstallLocation' means that if any
-- is 'Local', the result is 'Local', indicating that the parent
-- package must be installed locally. Otherwise the result is
-- 'Snap', indicating that the parent can either be installed
-- locally or in the snapshot.
-- Note that the Monoid for 'InstallLocation' means that if any is 'Local',
-- the result is 'Local', indicating that the parent package must be
-- installed locally. Otherwise the result is 'Snap', indicating that the
-- parent can either be installed locally or in the snapshot.
([], pairs) -> pure $ Right $ mconcat pairs
(errs, _) -> pure $ Left $ DependencyPlanFailures
package
Expand Down
54 changes: 33 additions & 21 deletions src/Stack/Build/Execute.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1280,11 +1280,17 @@ withSingleContext ::
-> OutputType
-> RIO env a)
-> RIO env a
withSingleContext ActionContext {..} ee@ExecuteEnv {..} task@Task {..} allDeps msuffix inner0 =
withPackage $ \package cabalfp pkgDir ->
withOutputType pkgDir package $ \outputType ->
withCabal package pkgDir outputType $ \cabal ->
inner0 package cabalfp pkgDir cabal announce outputType
withSingleContext
ActionContext {..}
ee@ExecuteEnv {..}
task@Task {..}
allDeps
msuffix
inner0
= withPackage $ \package cabalfp pkgDir ->
withOutputType pkgDir package $ \outputType ->
withCabal package pkgDir outputType $ \cabal ->
inner0 package cabalfp pkgDir cabal announce outputType
where
announce = announceTask ee task
prettyAnnounce = prettyAnnounceTask ee task
Expand Down Expand Up @@ -1650,22 +1656,28 @@ singleBuild :: forall env. (HasEnvConfig env, HasRunner env)
-> InstalledMap
-> Bool -- ^ Is this a final build?
-> RIO env ()
singleBuild ac@ActionContext {..} ee@ExecuteEnv {..} task@Task {..} installedMap isFinalBuild = do
(allDepsMap, cache) <-
getConfigCache ee task installedMap enableTests enableBenchmarks
mprecompiled <- getPrecompiled cache
minstalled <-
case mprecompiled of
Just precompiled -> copyPreCompiled precompiled
Nothing -> do
mcurator <- view $ buildConfigL.to bcCurator
realConfigAndBuild cache mcurator allDepsMap
case minstalled of
Nothing -> pure ()
Just installed -> do
writeFlagCache installed cache
liftIO $ atomically $
modifyTVar eeGhcPkgIds $ Map.insert taskProvides installed
singleBuild
ac@ActionContext {..}
ee@ExecuteEnv {..}
task@Task {..}
installedMap
isFinalBuild
= do
(allDepsMap, cache) <-
getConfigCache ee task installedMap enableTests enableBenchmarks
mprecompiled <- getPrecompiled cache
minstalled <-
case mprecompiled of
Just precompiled -> copyPreCompiled precompiled
Nothing -> do
mcurator <- view $ buildConfigL.to bcCurator
realConfigAndBuild cache mcurator allDepsMap
case minstalled of
Nothing -> pure ()
Just installed -> do
writeFlagCache installed cache
liftIO $ atomically $
modifyTVar eeGhcPkgIds $ Map.insert taskProvides installed
where
PackageIdentifier pname pversion = taskProvides
doHaddock mcurator package =
Expand Down
10 changes: 5 additions & 5 deletions src/Stack/Build/Haddock.hs
Original file line number Diff line number Diff line change
Expand Up @@ -377,13 +377,13 @@ generateLocalHaddockForHackageArchive pkgDir pkgId = do
<> line
<> pretty tarGzFile

createTarGzFile
:: Path Abs File
-- ^ Full path to archive file
createTarGzFile ::
Path Abs File
-- ^ Full path to archive file
-> Path Abs Dir
-- ^ Base directory
-- ^ Base directory
-> Path Rel Dir
-- ^ Directory to archive, relative to base directory
-- ^ Directory to archive, relative to base directory
-> RIO env ()
createTarGzFile tar base dir = do
entries <- liftIO $ Tar.pack base' [dir']
Expand Down
Loading

0 comments on commit ede6fa4

Please sign in to comment.