Skip to content

Commit

Permalink
aklsdgjlk
Browse files Browse the repository at this point in the history
  • Loading branch information
9999years committed Nov 4, 2024
1 parent 89f6e49 commit 9f653d5
Show file tree
Hide file tree
Showing 10 changed files with 500 additions and 434 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ instance Pretty pkg => Pretty (WithConstraintSource pkg) where
= pretty constraintPackage
pretty (WithConstraintSource { constraintPackage, constraintConstraint })
= pretty constraintPackage
<+> parens (text $ showConstraintSource constraintConstraint)
<+> parens (text "from" <+> pretty constraintConstraint)
40 changes: 23 additions & 17 deletions cabal-install/src/Distribution/Client/CmdInstall.hs
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ type InstallAction =
Verbosity
-> OverwritePolicy
-> InstallExe
-> (UnitId, [(ComponentTarget, NonEmpty TargetSelector)])
-> (UnitId, [(ComponentTarget, NonEmpty (WithConstraintSource TargetSelector))])
-> IO ()

data InstallCfg = InstallCfg
Expand Down Expand Up @@ -610,7 +610,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) targetSelectors
concatMap (targetPkgNames (localPackages baseCtx) . constraintPackage) targetSelectors
return (pkgSpecs, targetSelectors, config)
where
reducedVerbosity = lessVerbose verbosity
Expand Down Expand Up @@ -663,7 +663,7 @@ resolveTargetSelectorsInProjectBaseContext verbosity baseCtx targetStrings targe
targetSelectors <-
readTargetSelectors (localPackages baseCtx) Nothing targetStrings
>>= \case
Left problems -> reportTargetSelectorProblems verbosity problems
Left problems -> reportTargetSelectorProblems verbosity (map constraintPackage problems)
Right ts -> return ts

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

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

let
packageSpecifiers :: [PackageSpecifier UnresolvedSourcePackage]
(uris, packageSpecifiers) = partitionEithers $ map woPackageSpecifiers tss
packageTargets = map woPackageTargets tss
outerEither :: WithConstraintSource (Either a b) -> Either (WithConstraintSource a) (WithConstraintSource b)
outerEither (withConstraint@WithConstraintSource{constraintPackage = either'}) =
case either' of
Left inner -> Left (withConstraint{constraintPackage=inner})
Right inner -> Right (withConstraint{constraintPackage=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 tss)
return (packageSpecifiers, uris, packageTargets, config)
let config = addLocalConfigToPkgs globalConfig (concatMap (woPackageNames . constraintPackage) tss)
return (map constraintPackage packageSpecifiers, uris, packageTargets, config)

addLocalConfigToPkgs :: ProjectConfig -> [PackageName] -> ProjectConfig
addLocalConfigToPkgs config pkgs =
Expand Down Expand Up @@ -790,11 +796,11 @@ getSpecsAndTargetSelectors
:: Verbosity
-> Verbosity
-> SourcePackageDb
-> [TargetSelector]
-> [WithConstraintSource TargetSelector]
-> DistDirLayout
-> ProjectBaseContext
-> Maybe ComponentKindFilter
-> IO ([PackageSpecifier UnresolvedSourcePackage], [TargetSelector])
-> IO ([PackageSpecifier UnresolvedSourcePackage], [WithConstraintSource TargetSelector])
getSpecsAndTargetSelectors verbosity reducedVerbosity sourcePkgDb targetSelectors distDirLayout baseCtx targetFilter =
withInstallPlan reducedVerbosity baseCtx $ \elaboratedPlan _ -> do
-- Split into known targets and hackage packages.
Expand Down Expand Up @@ -832,7 +838,7 @@ getSpecsAndTargetSelectors verbosity reducedVerbosity sourcePkgDb targetSelector
localTargets = map gatherTargets (Map.keys targetsMap)

hackagePkgs :: [PackageSpecifier UnresolvedSourcePackage]
hackagePkgs = [NamedPackage pn [] | pn <- hackageNames]
hackagePkgs = [Named (WithConstraintSource {constraintPackage=pn}) | pn <- hackageNames]

Check failure on line 841 in cabal-install/src/Distribution/Client/CmdInstall.hs

View workflow job for this annotation

GitHub Actions / Doctest Cabal

Couldn't match type ‘PackageName’

hackageTargets :: [TargetSelector]
hackageTargets = [TargetPackageNamed pn targetFilter | pn <- hackageNames]
Expand Down Expand Up @@ -867,7 +873,7 @@ partitionToKnownTargetsAndHackagePackages
:: Verbosity
-> SourcePackageDb
-> ElaboratedInstallPlan
-> [TargetSelector]
-> [WithConstraintSource TargetSelector]
-> IO (TargetsMap, [PackageName])
partitionToKnownTargetsAndHackagePackages verbosity pkgDb elaboratedPlan targetSelectors = do
let mTargets =
Expand All @@ -884,7 +890,7 @@ partitionToKnownTargetsAndHackagePackages verbosity pkgDb elaboratedPlan targetS
Left errs -> do
-- Not everything is local.
let
(errs', hackageNames) = partitionEithers . flip fmap errs $ \case
(errs', hackageNames) = partitionEithers . flip fmap (map constraintPackage $ errs) $ \case
TargetAvailableInIndex name -> Right name
err -> Left err

Expand All @@ -900,7 +906,7 @@ partitionToKnownTargetsAndHackagePackages verbosity pkgDb elaboratedPlan targetS
when (not . null $ errs') $ reportBuildTargetProblems verbosity errs'

let
targetSelectors' = flip filter targetSelectors $ \case
targetSelectors' = flip filter (map constraintPackage targetSelectors) $ \case
TargetComponentUnknown name _ _
| name `elem` hackageNames -> False
TargetPackageNamed name _
Expand All @@ -910,7 +916,7 @@ partitionToKnownTargetsAndHackagePackages verbosity pkgDb elaboratedPlan targetS
-- This can't fail, because all of the errors are
-- removed (or we've given up).
targets <-
either (reportBuildTargetProblems verbosity) return $
either (reportBuildTargetProblems verbosity . map constraintPackage) return $
resolveTargets
selectPackageTargets
selectComponentTarget
Expand All @@ -924,7 +930,7 @@ constructProjectBuildContext
:: Verbosity
-> ProjectBaseContext
-- ^ The synthetic base context to use to produce the full build context.
-> [TargetSelector]
-> [WithConstraintSource TargetSelector]
-> IO ProjectBuildContext
constructProjectBuildContext verbosity baseCtx targetSelectors = do
runProjectPreBuildPhase verbosity baseCtx $ \elaboratedPlan -> do
Expand Down
12 changes: 10 additions & 2 deletions cabal-install/src/Distribution/Client/CmdListBin.hs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ import Distribution.Client.Errors
import qualified Distribution.Client.InstallPlan as IP
import qualified Distribution.Simple.InstallDirs as InstallDirs
import qualified Distribution.Solver.Types.ComponentDeps as CD
import Distribution.Solver.Types.WithConstraintSource (WithConstraintSource(..))
import Distribution.Solver.Types.ConstraintSource (ConstraintSource (..))

-------------------------------------------------------------------------------
-- Command
Expand Down Expand Up @@ -96,8 +98,14 @@ listbinAction flags@NixStyleFlags{..} args globalFlags = do
[x] -> return x
_ -> dieWithException verbosity OneTargetRequired

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

-- configure and elaborate target selectors
withContextAndSelectors RejectNoTargets (Just ExeKind) flags [target] globalFlags OtherCommand $ \targetCtx ctx targetSelectors -> do
withContextAndSelectors RejectNoTargets (Just ExeKind) flags [targetProvenance] globalFlags OtherCommand $ \targetCtx ctx targetSelectors -> do
baseCtx <- case targetCtx of
ProjectContext -> return ctx
GlobalContext -> return ctx
Expand All @@ -108,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) return $
either (reportTargetProblems verbosity . map constraintPackage) return $
resolveTargets
selectPackageTargets
selectComponentTarget
Expand Down
Loading

0 comments on commit 9f653d5

Please sign in to comment.