Skip to content

Commit

Permalink
Rename WithConstraintSource fields
Browse files Browse the repository at this point in the history
`constraintPackage` -> `constraintInner`
`constraintConstraint` -> `constraintSource`
  • Loading branch information
9999years committed Nov 20, 2024
1 parent 44fcf38 commit db60ab4
Show file tree
Hide file tree
Showing 40 changed files with 329 additions and 329 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ import Text.PrettyPrint
-- | A package bundled with a `ConstraintSource`.
data WithConstraintSource pkg =
WithConstraintSource
{ constraintPackage :: pkg
{ constraintInner :: pkg
-- ^ The package.
, constraintConstraint :: ConstraintSource
, constraintSource :: ConstraintSource
-- ^ The constraint source for the package.
}
deriving (Show, Functor, Eq, Ord, Traversable, Foldable, Generic, Typeable)
Expand All @@ -30,21 +30,21 @@ instance Binary pkg => Binary (WithConstraintSource pkg)
instance Structured pkg => Structured (WithConstraintSource pkg)

withUnknownConstraint :: pkg -> WithConstraintSource pkg
withUnknownConstraint constraintPackage =
withUnknownConstraint constraintInner =
WithConstraintSource
{ constraintPackage
, constraintConstraint = ConstraintSourceUnknown
{ constraintInner
, constraintSource = ConstraintSourceUnknown
}

showWithConstraintSource :: (pkg -> String) -> WithConstraintSource pkg -> String
showWithConstraintSource
showPackage
(WithConstraintSource { constraintPackage, constraintConstraint }) =
showPackage constraintPackage ++ " (" ++ showConstraintSource constraintConstraint ++ ")"
(WithConstraintSource { constraintInner, constraintSource }) =
showPackage constraintInner ++ " (" ++ showConstraintSource constraintSource ++ ")"

instance Pretty pkg => Pretty (WithConstraintSource pkg) where
pretty (WithConstraintSource { constraintPackage, constraintConstraint = ConstraintSourceUnknown })
= pretty constraintPackage
pretty (WithConstraintSource { constraintPackage, constraintConstraint })
= pretty constraintPackage
<+> parens (text "from" <+> pretty constraintConstraint)
pretty (WithConstraintSource { constraintInner, constraintSource = ConstraintSourceUnknown })
= pretty constraintInner
pretty (WithConstraintSource { constraintInner, constraintSource })
= pretty constraintInner
<+> parens (text "from" <+> pretty constraintSource)
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ fromPlanPackage
( SourcePackage
{ srcpkgSource =
WithConstraintSource
{ constraintPackage =
{ constraintInner =
RepoTarballPackage repo _ _
}
}
Expand Down
6 changes: 3 additions & 3 deletions cabal-install/src/Distribution/Client/CmdBench.hs
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,11 @@ benchAction flags@NixStyleFlags{..} targetStrings globalFlags = do
baseCtx <- establishProjectBaseContext verbosity cliConfig OtherCommand

targetSelectors <-
either (reportTargetSelectorProblems verbosity . map constraintPackage) return
either (reportTargetSelectorProblems verbosity . map constraintInner) return
=<< readTargetSelectors
(localPackages baseCtx)
(Just BenchKind)
(map (\target -> WithConstraintSource{constraintPackage = target, constraintConstraint = ConstraintSourceCommandlineFlag}) targetStrings)
(map (\target -> WithConstraintSource{constraintInner = target, constraintSource = ConstraintSourceCommandlineFlag}) targetStrings)

buildCtx <-
runProjectPreBuildPhase verbosity baseCtx $ \elaboratedPlan -> do
Expand All @@ -140,7 +140,7 @@ benchAction flags@NixStyleFlags{..} targetStrings globalFlags = do
-- Interpret the targets on the command line as bench targets
-- (as opposed to say build or haddock targets).
targets <-
either (reportTargetProblems verbosity . map constraintPackage) return $
either (reportTargetProblems verbosity . map constraintInner) return $
resolveTargets
selectPackageTargets
selectComponentTarget
Expand Down
6 changes: 3 additions & 3 deletions cabal-install/src/Distribution/Client/CmdBuild.hs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ buildAction flags@NixStyleFlags{extraFlags = buildFlags, ..} targetStrings globa
-- Interpret the targets on the command line as build targets
-- (as opposed to say repl or haddock targets).
targets <-
either (reportBuildTargetProblems verbosity . map constraintPackage) return $
either (reportBuildTargetProblems verbosity . map constraintInner) return $
resolveTargets
selectPackageTargets
selectComponentTarget
Expand Down Expand Up @@ -196,8 +196,8 @@ buildAction flags@NixStyleFlags{extraFlags = buildFlags, ..} targetStrings globa
map
( \target ->
WithConstraintSource
{ constraintPackage = target
, constraintConstraint = ConstraintSourceCommandlineFlag
{ constraintInner = target
, constraintSource = ConstraintSourceCommandlineFlag
}
)
targetStrings
Expand Down
10 changes: 5 additions & 5 deletions cabal-install/src/Distribution/Client/CmdFreeze.hs
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,8 @@ projectFreezeConstraints plan =
Map.mapWithKey
( \p v ->
[ WithConstraintSource
{ constraintPackage = UserConstraint (UserAnyQualifier p) (PackagePropertyVersion v)
, constraintConstraint = ConstraintSourceFreeze
{ constraintInner = UserConstraint (UserAnyQualifier p) (PackagePropertyVersion v)
, constraintSource = ConstraintSourceFreeze
}
]
)
Expand All @@ -242,8 +242,8 @@ projectFreezeConstraints plan =
Map.mapWithKey
( \p f ->
[ WithConstraintSource
{ constraintPackage = UserConstraint (UserQualified UserQualToplevel p) (PackagePropertyFlags f)
, constraintConstraint = ConstraintSourceFreeze
{ constraintInner = UserConstraint (UserQualified UserQualToplevel p) (PackagePropertyFlags f)
, constraintSource = ConstraintSourceFreeze
}
]
)
Expand All @@ -267,7 +267,7 @@ projectFreezeConstraints plan =
deleteLocalPackagesVersionConstraints =
Map.mergeWithKey
( \_pkgname () constraints ->
case filter (not . isVersionConstraint . constraintPackage) constraints of
case filter (not . isVersionConstraint . constraintInner) constraints of
[] -> Nothing
constraints' -> Just constraints'
)
Expand Down
6 changes: 3 additions & 3 deletions cabal-install/src/Distribution/Client/CmdHaddock.hs
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,11 @@ haddockAction relFlags targetStrings globalFlags = do
let baseCtx = relBaseCtx{projectConfig = absProjectConfig}

targetSelectors <-
either (reportTargetSelectorProblems verbosity . map constraintPackage) return
either (reportTargetSelectorProblems verbosity . map constraintInner) return
=<< readTargetSelectors
(localPackages baseCtx)
Nothing
(map (\target -> WithConstraintSource{constraintPackage = target, constraintConstraint = ConstraintSourceCommandlineFlag}) targetStrings)
(map (\target -> WithConstraintSource{constraintInner = target, constraintSource = ConstraintSourceCommandlineFlag}) targetStrings)

buildCtx <-
runProjectPreBuildPhase verbosity baseCtx $ \elaboratedPlan -> do
Expand All @@ -183,7 +183,7 @@ haddockAction relFlags targetStrings globalFlags = do
-- When we interpret the targets on the command line, interpret them as
-- haddock targets
targets <-
either (reportBuildDocumentationTargetProblems verbosity . map constraintPackage) return $
either (reportBuildDocumentationTargetProblems verbosity . map constraintInner) return $
resolveTargets
(selectPackageTargets haddockFlags)
selectComponentTarget
Expand Down
2 changes: 1 addition & 1 deletion cabal-install/src/Distribution/Client/CmdHaddockProject.hs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ haddockProjectAction flags _extraArgs globalFlags = do
RejectNoTargets
Nothing
(commandDefaultFlags CmdBuild.buildCommand)
[WithConstraintSource{constraintPackage = "all", constraintConstraint = ConstraintSourceImplicit}]
[WithConstraintSource{constraintInner = "all", constraintSource = ConstraintSourceImplicit}]
globalFlags
HaddockCommand
$ \targetCtx ctx targetSelectors -> do
Expand Down
66 changes: 33 additions & 33 deletions cabal-install/src/Distribution/Client/CmdInstall.hs
Original file line number Diff line number Diff line change
Expand Up @@ -373,16 +373,16 @@ installAction flags@NixStyleFlags{extraFlags, configFlags, installFlags, project
if null targetStrings
then
[ WithConstraintSource
{ constraintPackage = "."
, constraintConstraint = ConstraintSourceImplicit
{ constraintInner = "."
, constraintSource = ConstraintSourceImplicit
}
]
else
map
( \target ->
WithConstraintSource
{ constraintPackage = target
, constraintConstraint = ConstraintSourceCommandlineFlag
{ constraintInner = target
, constraintSource = ConstraintSourceCommandlineFlag
}
)
targetStrings
Expand Down Expand Up @@ -615,7 +615,7 @@ withProject verbosity cliConfig targetStrings installLibs = do
-- We want to apply the local configuration only to the actual targets.
let config =
addLocalConfigToPkgs (projectConfig baseCtx) $
concatMap (targetPkgNames (localPackages baseCtx) . constraintPackage) targetSelectors
concatMap (targetPkgNames (localPackages baseCtx) . constraintInner) targetSelectors
return (pkgSpecs, targetSelectors, config)
where
reducedVerbosity = lessVerbose verbosity
Expand All @@ -625,10 +625,10 @@ withProject verbosity cliConfig targetStrings installLibs = do
(unresolvedTargetStrings, parsedPackageIds) =
partitionEithers $
flip map targetStrings $ \target ->
case eitherParsec $ constraintPackage target of
case eitherParsec $ constraintInner target of
Right pkgId@PackageIdentifier{pkgVersion}
| pkgVersion /= nullVersion ->
pure $ target{constraintPackage = pkgId}
pure $ target{constraintInner = pkgId}
_ -> Left target

-- For each packageId, we output a NamedPackage specifier (i.e. a package only known by
Expand All @@ -637,13 +637,13 @@ withProject verbosity cliConfig targetStrings installLibs = do
unzip
[ ( mkNamedPackage src pkgId
, withConstraint
{ constraintPackage =
{ constraintInner =
TargetPackageNamed (pkgName pkgId) targetFilter
}
)
| withConstraint@WithConstraintSource
{ constraintPackage = pkgId
, constraintConstraint = src
{ constraintInner = pkgId
, constraintSource = src
} <-
parsedPackageIds
]
Expand All @@ -668,7 +668,7 @@ resolveTargetSelectorsInProjectBaseContext verbosity baseCtx targetStrings targe
targetSelectors <-
readTargetSelectors (localPackages baseCtx) Nothing targetStrings
>>= \case
Left problems -> reportTargetSelectorProblems verbosity (map constraintPackage problems)
Left problems -> reportTargetSelectorProblems verbosity (map constraintInner problems)
Right ts -> return ts

getSpecsAndTargetSelectors
Expand Down Expand Up @@ -719,7 +719,7 @@ withoutProject verbosity globalConfig targetStrings = do
buildSettings
(getSourcePackages verbosity)

for_ (concatMap (woPackageNames . constraintPackage) tss) $ \name -> do
for_ (concatMap (woPackageNames . constraintInner) tss) $ \name -> do
when (null (lookupPackageName packageIndex name)) $ do
let xs = searchByName packageIndex (unPackageName name)
let emptyIf True _ = []
Expand All @@ -734,19 +734,19 @@ withoutProject verbosity globalConfig targetStrings = do

let
outerEither :: WithConstraintSource (Either a b) -> Either (WithConstraintSource a) (WithConstraintSource b)
outerEither (withConstraint@WithConstraintSource{constraintPackage = either'}) =
outerEither (withConstraint@WithConstraintSource{constraintInner = either'}) =
case either' of
Left inner -> Left (withConstraint{constraintPackage = inner})
Right inner -> Right (withConstraint{constraintPackage = inner})
Left inner -> Left (withConstraint{constraintInner = inner})
Right inner -> Right (withConstraint{constraintInner = inner})

packageSpecifiers :: [WithConstraintSource (PackageSpecifier UnresolvedSourcePackage)]
(uris, packageSpecifiers) = partitionEithers $ map (outerEither . fmap woPackageSpecifiers) tss
packageTargets = map (fmap woPackageTargets) tss

-- Apply the local configuration (e.g. cli flags) to all direct targets of install command,
-- see note in 'installAction'
let config = addLocalConfigToPkgs globalConfig (concatMap (woPackageNames . constraintPackage) tss)
return (map constraintPackage packageSpecifiers, uris, packageTargets, config)
let config = addLocalConfigToPkgs globalConfig (concatMap (woPackageNames . constraintInner) tss)
return (map constraintInner packageSpecifiers, uris, packageTargets, config)

addLocalConfigToPkgs :: ProjectConfig -> [PackageName] -> ProjectConfig
addLocalConfigToPkgs config pkgs =
Expand Down Expand Up @@ -827,7 +827,7 @@ getSpecsAndTargetSelectors verbosity reducedVerbosity sourcePkgDb targetSelector
spkg
{ srcpkgSource =
(srcpkgSource spkg)
{ constraintPackage = LocalTarballPackage sdistPath
{ constraintInner = LocalTarballPackage sdistPath
}
}
sdistize named = named
Expand All @@ -844,14 +844,14 @@ getSpecsAndTargetSelectors verbosity reducedVerbosity sourcePkgDb targetSelector

hackagePkgs :: [PackageSpecifier UnresolvedSourcePackage]
hackagePkgs =
[ Named (withConstraint{constraintPackage = NamedPackage packageName []})
| withConstraint@WithConstraintSource{constraintPackage = packageName} <- hackageNames
[ Named (withConstraint{constraintInner = NamedPackage packageName []})
| withConstraint@WithConstraintSource{constraintInner = packageName} <- hackageNames
]

hackageTargets :: [WithConstraintSource TargetSelector]
hackageTargets =
[ withConstraint{constraintPackage = TargetPackageNamed packageName targetFilter}
| withConstraint@WithConstraintSource{constraintPackage = packageName} <- hackageNames
[ withConstraint{constraintInner = TargetPackageNamed packageName targetFilter}
| withConstraint@WithConstraintSource{constraintInner = packageName} <- hackageNames
]

createDirectoryIfMissing True (distSdistDirectory distDirLayout)
Expand Down Expand Up @@ -901,8 +901,8 @@ partitionToKnownTargetsAndHackagePackages verbosity pkgDb elaboratedPlan targetS
Left errs -> do
-- Not everything is local.
let
(errs', hackageNames) = partitionEithers . flip fmap errs $ \problem -> case constraintPackage problem of
TargetAvailableInIndex name -> Right problem{constraintPackage = name}
(errs', hackageNames) = partitionEithers . flip fmap errs $ \problem -> case constraintInner problem of
TargetAvailableInIndex name -> Right problem{constraintInner = name}
err -> Left err

-- report incorrect case for known package.
Expand All @@ -917,17 +917,17 @@ partitionToKnownTargetsAndHackagePackages verbosity pkgDb elaboratedPlan targetS
when (not . null $ errs') $ reportBuildTargetProblems verbosity errs'

let
targetSelectors' = flip filter targetSelectors $ \target -> case constraintPackage target of
targetSelectors' = flip filter targetSelectors $ \target -> case constraintInner target of
TargetComponentUnknown name _ _
| name `elem` (map constraintPackage hackageNames) -> False
| name `elem` (map constraintInner hackageNames) -> False
TargetPackageNamed name _
| name `elem` (map constraintPackage hackageNames) -> False
| name `elem` (map constraintInner hackageNames) -> False
_ -> True

-- This can't fail, because all of the errors are
-- removed (or we've given up).
targets <-
either (reportBuildTargetProblems verbosity . map constraintPackage) return $
either (reportBuildTargetProblems verbosity . map constraintInner) return $
resolveTargets
selectPackageTargets
selectComponentTarget
Expand All @@ -947,7 +947,7 @@ constructProjectBuildContext verbosity baseCtx targetSelectors = do
runProjectPreBuildPhase verbosity baseCtx $ \elaboratedPlan -> do
-- Interpret the targets on the command line as build targets
targets <-
either (reportBuildTargetProblems verbosity . map constraintPackage) return $
either (reportBuildTargetProblems verbosity . map constraintInner) return $
resolveTargets
selectPackageTargets
selectComponentTarget
Expand Down Expand Up @@ -1109,11 +1109,11 @@ warnIfNoExes verbosity buildCtx =
<> "The command \"cabal install [TARGETS]\" doesn't expose libraries.\n"
<> "* You might have wanted to add them as dependencies to your package."
<> " In this case add \""
<> intercalate ", " (map (showTargetSelector . constraintPackage) selectors)
<> intercalate ", " (map (showTargetSelector . constraintInner) selectors)
<> "\" to the build-depends field(s) of your package's .cabal file.\n"
<> "* You might have wanted to add them to a GHC environment. In this case"
<> " use \"cabal install --lib "
<> unwords (map (showTargetSelector . constraintPackage) selectors)
<> unwords (map (showTargetSelector . constraintInner) selectors)
<> "\". "
<> " The \"--lib\" flag is provisional: see"
<> " https://github.com/haskell/cabal/issues/6481 for more information."
Expand Down Expand Up @@ -1158,9 +1158,9 @@ environmentFileToSpecifiers ipi = foldMap $ \case
(
[ Named
( WithConstraintSource
{ constraintPackage =
{ constraintInner =
pkgSpec
, constraintConstraint = ConstraintSourceUnknown
, constraintSource = ConstraintSourceUnknown
}
)
]
Expand Down
6 changes: 3 additions & 3 deletions cabal-install/src/Distribution/Client/CmdListBin.hs
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ listbinAction flags@NixStyleFlags{..} args globalFlags = do

let targetProvenance =
WithConstraintSource
{ constraintPackage = target
, constraintConstraint = ConstraintSourceCommandlineFlag
{ constraintInner = target
, constraintSource = ConstraintSourceCommandlineFlag
}

-- configure and elaborate target selectors
Expand All @@ -116,7 +116,7 @@ listbinAction flags@NixStyleFlags{..} args globalFlags = do
-- Interpret the targets on the command line as build targets
-- (as opposed to say repl or haddock targets).
targets <-
either (reportTargetProblems verbosity . map constraintPackage) return $
either (reportTargetProblems verbosity . map constraintInner) return $
resolveTargets
selectPackageTargets
selectComponentTarget
Expand Down
4 changes: 2 additions & 2 deletions cabal-install/src/Distribution/Client/CmdOutdated.hs
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ depsFromFreezeFile verbosity = do
cwd <- getCurrentDirectory
userConfig <- loadUserConfig verbosity cwd Nothing
let ucnstrs =
map constraintPackage . configExConstraints . savedConfigureExFlags $
map constraintInner . configExConstraints . savedConfigureExFlags $
userConfig
deps = userConstraintsToDependencies ucnstrs
debug verbosity "Reading the list of dependencies from the freeze file"
Expand All @@ -425,7 +425,7 @@ depsFromNewFreezeFile verbosity httpTransport compiler (Platform arch os) mproje
pcs <- readProjectLocalFreezeConfig verbosity httpTransport distDirLayout
pure $ instantiateProjectConfigSkeletonWithCompiler os arch (compilerInfo compiler) mempty pcs
let ucnstrs =
map constraintPackage . projectConfigConstraints . projectConfigShared $
map constraintInner . projectConfigConstraints . projectConfigShared $
projectConfig
deps = userConstraintsToDependencies ucnstrs
freezeFile = distProjectFile distDirLayout "freeze"
Expand Down
Loading

0 comments on commit db60ab4

Please sign in to comment.