Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove package prefix from Package field names #6404

Merged
merged 3 commits into from
Jan 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 17 additions & 16 deletions src/Stack/Build.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE OverloadedRecordDot #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE OverloadedRecordDot #-}
{-# LANGUAGE OverloadedStrings #-}

-- | Build the project.

Expand Down Expand Up @@ -152,7 +153,7 @@ build msetLocalFiles = do
if boptsCli.boptsCLIWatchAll
then sequence [lpFiles lp | lp <- allLocals]
else forM allLocals $ \lp -> do
let pn = lp.lpPackage.packageName
let pn = lp.package.name
case Map.lookup pn sourceMap.smTargets.smtTargets of
Nothing ->
pure Set.empty
Expand Down Expand Up @@ -294,13 +295,13 @@ warnIfExecutablesWithSameNameCouldBeOverwritten locals plan = do
[ (exe, pkgName')
| (pkgName', task) <- Map.toList plan.planTasks
, TTLocalMutable lp <- [task.taskType]
, exe <- (Set.toList . exeComponents . (.lpComponents)) lp
, exe <- (Set.toList . exeComponents . (.components)) lp
]
localExes :: Map Text (NonEmpty PackageName)
localExes =
collect
[ (exe, pkg.packageName)
| pkg <- map (.lpPackage) locals
[ (exe, pkg.name)
| pkg <- map (.package) locals
, exe <- Set.toList (buildableExes pkg)
]
collect :: Ord k => [(k, v)] -> Map k (NonEmpty v)
Expand Down Expand Up @@ -355,13 +356,13 @@ loadPackage loc flags ghcOptions cabalConfigOpts = do
compiler <- view actualCompilerVersionL
platform <- view platformL
let pkgConfig = PackageConfig
{ packageConfigEnableTests = False
, packageConfigEnableBenchmarks = False
, packageConfigFlags = flags
, packageConfigGhcOptions = ghcOptions
, packageConfigCabalConfigOpts = cabalConfigOpts
, packageConfigCompilerVersion = compiler
, packageConfigPlatform = platform
{ enableTests = False
, enableBenchmarks = False
, flags = flags
, ghcOptions = ghcOptions
, cabalConfigOpts = cabalConfigOpts
, compilerVersion = compiler
, platform = platform
}
resolvePackage pkgConfig <$> loadCabalFileImmutable loc

Expand All @@ -371,7 +372,7 @@ checkComponentsBuildable lps =
prettyThrowM $ SomeTargetsNotBuildable unbuildable
where
unbuildable =
[ (lp.lpPackage.packageName, c)
[ (lp.package.name, c)
| lp <- lps
, c <- Set.toList lp.lpUnbuildable
, c <- Set.toList lp.unbuildable
]
49 changes: 25 additions & 24 deletions src/Stack/Build/ConstructPlan.hs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedRecordDot #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ViewPatterns #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedRecordDot #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ViewPatterns #-}

-- | Construct a @Plan@ for how to build
module Stack.Build.ConstructPlan
Expand Down Expand Up @@ -291,8 +292,8 @@ constructPlan
let loadLocalPackage' pp = do
lp <- loadLocalPackage pp
let lpPackage' =
applyForceCustomBuild globalCabalVersion lp.lpPackage
pure lp { lpPackage = lpPackage' }
applyForceCustomBuild globalCabalVersion lp.package
pure lp { package = lpPackage' }
pPackages <- for sourceProject $ \pp -> do
lp <- loadLocalPackage' pp
pure $ PSFilePath lp
Expand Down Expand Up @@ -449,10 +450,10 @@ addFinal lp package isAllInOne buildHaddocks = do
, taskPresent = present
, taskType = TTLocalMutable lp
, taskAllInOne = isAllInOne
, taskCachePkgSrc = CacheSrcLocal (toFilePath (parent lp.lpCabalFile))
, taskCachePkgSrc = CacheSrcLocal (toFilePath (parent lp.cabalFile))
, taskBuildTypeConfig = packageBuildTypeConfig package
}
tell mempty { wFinals = Map.singleton package.packageName res }
tell mempty { wFinals = Map.singleton package.name res }

-- | Given a 'PackageName', adds all of the build tasks to build the package, if
-- needed. First checks if the package name is in the library map.
Expand Down Expand Up @@ -563,7 +564,7 @@ addDep name packageInfo = do
-- executables to the collected output.
tellExecutables :: PackageName -> PackageSource -> M ()
tellExecutables _name (PSFilePath lp)
| lp.lpWanted = tellExecutablesPackage Local lp.lpPackage
| lp.wanted = tellExecutablesPackage Local lp.package
| otherwise = pure ()
-- Ignores ghcOptions because they don't matter for enumerating executables.
tellExecutables name (PSRemote pkgloc _version _fromSnapshot cp) =
Expand Down Expand Up @@ -594,14 +595,14 @@ tellExecutablesPackage loc p = do
cm <- asks (.combinedMap)
-- Determine which components are enabled so we know which ones to copy
let myComps =
case Map.lookup p.packageName cm of
case Map.lookup p.name cm of
Nothing -> assert False Set.empty
Just (PIOnlyInstalled _ _) -> Set.empty
Just (PIOnlySource ps) -> goSource ps
Just (PIBoth ps _) -> goSource ps

goSource (PSFilePath lp)
| lp.lpWanted = exeComponents lp.lpComponents
| lp.wanted = exeComponents lp.components
| otherwise = Set.empty
goSource PSRemote{} = Set.empty

Expand Down Expand Up @@ -632,14 +633,14 @@ installPackage name ps minstalled = do
pkgLoc cp.cpFlags cp.cpGhcOptions cp.cpCabalConfigOpts
resolveDepsAndInstall True cp.cpHaddocks ps package minstalled
PSFilePath lp -> do
case lp.lpTestBench of
case lp.testBench of
Nothing -> do
logDebugPlanS "installPackage" $
"No test or bench component for "
<> fromPackageName name
<> " so doing an all-in-one build."
resolveDepsAndInstall
True lp.lpBuildHaddocks ps lp.lpPackage minstalled
True lp.buildHaddocks ps lp.package minstalled
Just tb -> do
-- Attempt to find a plan which performs an all-in-one build. Ignore
-- the writer action + reset the state if it fails.
Expand All @@ -663,7 +664,7 @@ installPackage name ps minstalled = do
splitRequired <- expectedTestOrBenchFailures <$> asks (.mcurator)
let isAllInOne = not splitRequired
adr <- installPackageGivenDeps
isAllInOne lp.lpBuildHaddocks ps tb minstalled deps
isAllInOne lp.buildHaddocks ps tb minstalled deps
let finalAllInOne = case adr of
ADRToInstall _ | splitRequired -> False
_ -> True
Expand All @@ -681,7 +682,7 @@ installPackage name ps minstalled = do
-- Otherwise, fall back on building the tests / benchmarks in a
-- separate step.
res' <- resolveDepsAndInstall
False lp.lpBuildHaddocks ps lp.lpPackage minstalled
False lp.buildHaddocks ps lp.package minstalled
when (isRight res') $ do
-- Insert it into the map so that it's available for addFinal.
updateLibMap name res'
Expand Down Expand Up @@ -728,7 +729,7 @@ installPackageGivenDeps ::
-> M AddDepRes
installPackageGivenDeps isAllInOne buildHaddocks ps package minstalled
(missing, present, minMutable) = do
let name = package.packageName
let name = package.name
ctx <- ask
mRightVersionInstalled <- case (minstalled, Set.null missing) of
(Just installed, True) -> do
Expand Down Expand Up @@ -773,7 +774,7 @@ installPackageGivenDeps isAllInOne buildHaddocks ps package minstalled

-- | Is the build type of the package Configure
packageBuildTypeConfig :: Package -> Bool
packageBuildTypeConfig pkg = pkg.packageBuildType == Configure
packageBuildTypeConfig pkg = pkg.buildType == Configure

-- Update response in the library map. If it is an error, and there's already an
-- error about cyclic dependencies, prefer the cyclic error.
Expand Down Expand Up @@ -1020,7 +1021,7 @@ checkDirtiness ps installed package present buildHaddocks = do
, configCacheComponents =
case ps of
PSFilePath lp ->
Set.map (encodeUtf8 . renderComponent) lp.lpComponents
Set.map (encodeUtf8 . renderComponent) lp.components
PSRemote{} -> Set.empty
, configCacheHaddock = buildHaddocks
, configCachePkgSrc = toCachePkgSrc ps
Expand All @@ -1045,7 +1046,7 @@ checkDirtiness ps installed package present buildHaddocks = do
case mreason of
Nothing -> pure False
Just reason -> do
tell mempty { wDirty = Map.singleton package.packageName reason }
tell mempty { wDirty = Map.singleton package.name reason }
pure True

describeConfigDiff :: Config -> ConfigCache -> ConfigCache -> Maybe Text
Expand Down Expand Up @@ -1137,14 +1138,14 @@ describeConfigDiff config old new
pkgSrcName CacheSrcUpstream = "upstream source"

psForceDirty :: PackageSource -> Bool
psForceDirty (PSFilePath lp) = lp.lpForceDirty
psForceDirty (PSFilePath lp) = lp.forceDirty
psForceDirty PSRemote{} = False

psDirty ::
(MonadIO m, HasEnvConfig env, MonadReader env m)
=> PackageSource
-> m (Maybe (Set FilePath))
psDirty (PSFilePath lp) = runMemoizedWith lp.lpDirtyFiles
psDirty (PSFilePath lp) = runMemoizedWith lp.dirtyFiles
psDirty PSRemote {} = pure Nothing -- files never change in a remote package

psLocal :: PackageSource -> Bool
Expand Down Expand Up @@ -1179,8 +1180,8 @@ checkAndWarnForUnknownTools p = do
-- From Cabal 1.12, build-tools can specify another executable in the same
-- package.
notPackageExe toolName =
MaybeT $ skipIf $ collectionMember toolName p.packageExecutables
warn name = MaybeT . pure . Just $ ToolWarning (ExeName name) p.packageName
MaybeT $ skipIf $ collectionMember toolName p.executables
warn name = MaybeT . pure . Just $ ToolWarning (ExeName name) p.name
skipIf p' = pure $ if p' then Nothing else Just ()

toolWarningText :: ToolWarning -> StyleDoc
Expand Down
Loading
Loading