Skip to content

Commit

Permalink
Remove ConstraintSources from preferences
Browse files Browse the repository at this point in the history
From @grayjay:
> The dependency solver currently doesn't describe preferences in error
> messages, so I think that it would take a lot more work to make this
> useful.
  • Loading branch information
9999years committed Dec 6, 2024
1 parent 7375dfb commit 0546f08
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 20 deletions.
6 changes: 3 additions & 3 deletions cabal-install/src/Distribution/Client/Configure.hs
Original file line number Diff line number Diff line change
Expand Up @@ -377,13 +377,13 @@ checkConfigExFlags verbosity installedPkgIndex sourcePkgIndex flags = do
for_ (safeHead unknownPreferences) $ \h ->
warn verbosity $
"Preference refers to an unknown package: "
++ showWithConstraintSource prettyShow h
++ prettyShow h
where
unknownConstraints =
filter (unknown . userConstraintPackageName . constraintInner) $
configExConstraints flags
unknownPreferences =
filter (unknown . (\(PackageVersionConstraint name _) -> name) . constraintInner) $
filter (unknown . (\(PackageVersionConstraint name _) -> name)) $
configPreferences flags
unknown pkg =
null (PackageIndex.lookupPackageName installedPkgIndex pkg)
Expand Down Expand Up @@ -443,7 +443,7 @@ planLocalPackage
. addPreferences
-- preferences from the config file or command line
[ PackageVersionPreference name ver
| PackageVersionConstraint name ver <- map constraintInner $ configPreferences configExFlags
| PackageVersionConstraint name ver <- configPreferences configExFlags
]
. addConstraints
-- version constraints from the config file or command line
Expand Down
2 changes: 1 addition & 1 deletion cabal-install/src/Distribution/Client/Install.hs
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ planPackages
. addPreferences
-- preferences from the config file or command line
[ PackageVersionPreference name ver
| PackageVersionConstraint name ver <- map constraintInner $ configPreferences configExFlags
| PackageVersionConstraint name ver <- configPreferences configExFlags
]
. addConstraints
-- version constraints from the config file or command line
Expand Down
6 changes: 2 additions & 4 deletions cabal-install/src/Distribution/Client/ProjectConfig/Legacy.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1430,10 +1430,8 @@ legacySharedConfigFieldDescrs constraintSrc =
(\v conf -> conf{configExConstraints = v})
, commaNewLineListFieldParsec
"preferences"
(pretty . constraintInner)
( (\preference -> WithConstraintSource{constraintInner = preference, constraintSource = constraintSrc})
`fmap` parsec
)
pretty
parsec
configPreferences
(\v conf -> conf{configPreferences = v})
, monoidFieldParsec
Expand Down
4 changes: 2 additions & 2 deletions cabal-install/src/Distribution/Client/ProjectConfig/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ data ProjectConfigShared = ProjectConfigShared
, projectConfigStoreDir :: Flag FilePath
, -- solver configuration
projectConfigConstraints :: [WithConstraintSource UserConstraint]
, projectConfigPreferences :: [WithConstraintSource PackageVersionConstraint]
, projectConfigPreferences :: [PackageVersionConstraint]
, projectConfigCabalVersion :: Flag Version -- TODO: [required eventually] unused
, projectConfigSolver :: Flag PreSolver
, projectConfigAllowOlder :: Maybe AllowOlder
Expand Down Expand Up @@ -411,7 +411,7 @@ data SolverSettings = SolverSettings
-- ^ Available Hackage servers.
, solverSettingLocalNoIndexRepos :: [LocalRepo]
, solverSettingConstraints :: [WithConstraintSource UserConstraint]
, solverSettingPreferences :: [WithConstraintSource PackageVersionConstraint]
, solverSettingPreferences :: [PackageVersionConstraint]
, solverSettingFlagAssignment :: FlagAssignment
-- ^ For all local packages
, solverSettingFlagAssignments :: Map PackageName FlagAssignment
Expand Down
2 changes: 1 addition & 1 deletion cabal-install/src/Distribution/Client/ProjectPlanning.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1299,7 +1299,7 @@ planPackages
. addPreferences
-- preferences from the config file or command line
[ PackageVersionPreference name ver
| PackageVersionConstraint name ver <- map constraintInner solverSettingPreferences
| PackageVersionConstraint name ver <- solverSettingPreferences
]
. addConstraints
-- version constraints from the config file or command line
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,7 @@ pkgEnvFieldDescrs src =
, commaListFieldParsec
"preferences"
pretty
( (\preference -> WithConstraintSource{constraintInner = preference, constraintSource = src})
`fmap` parsec
)
parsec
(configPreferences . savedConfigureExFlags . pkgEnvSavedConfig)
( \v pkgEnv ->
updateConfigureExFlags
Expand Down
8 changes: 3 additions & 5 deletions cabal-install/src/Distribution/Client/Setup.hs
Original file line number Diff line number Diff line change
Expand Up @@ -915,7 +915,7 @@ data ConfigExFlags = ConfigExFlags
, configAppend :: Flag Bool
, configBackup :: Flag Bool
, configExConstraints :: [WithConstraintSource UserConstraint]
, configPreferences :: [WithConstraintSource PackageVersionConstraint]
, configPreferences :: [PackageVersionConstraint]
, configSolver :: Flag PreSolver
, configAllowNewer :: Maybe AllowNewer
, configAllowOlder :: Maybe AllowOlder
Expand Down Expand Up @@ -1008,11 +1008,9 @@ configureExOptions _showOrParseArgs constraint =
"CONSTRAINT"
( parsecToReadE
(const "dependency expected")
( (\pkg -> [WithConstraintSource{constraintInner = pkg, constraintSource = constraint}])
`fmap` parsec
)
(fmap (\x -> [x]) parsec)
)
(map $ showWithConstraintSource prettyShow)
(map prettyShow)
)
, optionSolver configSolver (\v flags -> flags{configSolver = v})
, option
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,7 @@ instance Arbitrary ProjectConfigShared where
projectConfigIndexState <- arbitrary
projectConfigStoreDir <- arbitraryFlag arbitraryShortToken
projectConfigConstraints <- arbitraryWithConstraintSources
projectConfigPreferences <- shortListOf 2 arbitraryWithConstraintSource
projectConfigPreferences <- shortListOf 2 arbitrary
projectConfigCabalVersion <- arbitrary
projectConfigSolver <- arbitrary
projectConfigAllowOlder <- arbitrary
Expand Down

0 comments on commit 0546f08

Please sign in to comment.