Skip to content

Commit

Permalink
cabal-install: Use AllowNewer from Cabal
Browse files Browse the repository at this point in the history
  • Loading branch information
maralorn committed Jun 13, 2023
1 parent 668c8a2 commit 19dd95a
Show file tree
Hide file tree
Showing 17 changed files with 62 additions and 394 deletions.
1 change: 0 additions & 1 deletion cabal-install/cabal-install.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@ library
Distribution.Client.TargetSelector
Distribution.Client.Targets
Distribution.Client.Types
Distribution.Client.Types.AllowNewer
Distribution.Client.Types.BuildResults
Distribution.Client.Types.ConfiguredId
Distribution.Client.Types.ConfiguredPackage
Expand Down
34 changes: 16 additions & 18 deletions cabal-install/src/Distribution/Client/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,17 @@ import Distribution.Client.Setup
, reportCommand
, uploadCommand
)
import Distribution.Client.Types
import Distribution.Types.AllowNewer
( AllowNewer (..)
, AllowOlder (..)
, LocalRepo (..)
, RelaxDeps (..)
, isRelaxDeps
)
import Distribution.Client.Types
( LocalRepo (..)
, RemoteRepo (..)
, RepoName (..)
, emptyRemoteRepo
, isRelaxDeps
, unRepoName
)
import Distribution.Client.Types.Credentials (Password (..), Username (..))
Expand Down Expand Up @@ -526,6 +528,8 @@ instance Semigroup SavedConfig where
, configDumpBuildInfo = combine configDumpBuildInfo
, configAllowDependingOnPrivateLibs =
combine configAllowDependingOnPrivateLibs
, configAllowNewer = combineMonoid savedConfigureFlags configAllowNewer
, configAllowOlder = combineMonoid savedConfigureFlags configAllowOlder
}
where
combine = combine' savedConfigureFlags
Expand All @@ -543,10 +547,6 @@ instance Semigroup SavedConfig where
, -- TODO: NubListify
configPreferences = lastNonEmpty configPreferences
, configSolver = combine configSolver
, configAllowNewer =
combineMonoid savedConfigureExFlags configAllowNewer
, configAllowOlder =
combineMonoid savedConfigureExFlags configAllowOlder
, configWriteGhcEnvironmentFilesPolicy =
combine configWriteGhcEnvironmentFilesPolicy
}
Expand Down Expand Up @@ -1103,14 +1103,12 @@ commentSavedConfig = do
}
, savedInstallFlags = defaultInstallFlags
, savedClientInstallFlags = defaultClientInstallFlags
, savedConfigureExFlags =
defaultConfigExFlags
{ configAllowNewer = Just (AllowNewer mempty)
, configAllowOlder = Just (AllowOlder mempty)
}
, savedConfigureExFlags = defaultConfigExFlags
, savedConfigureFlags =
(defaultConfigFlags defaultProgramDb)
{ configUserInstall = toFlag defaultUserInstall
, configAllowNewer = Just (AllowNewer mempty)
, configAllowOlder = Just (AllowOlder mempty)
}
, savedUserInstallDirs = fmap toFlag userInstallDirs
, savedGlobalInstallDirs = fmap toFlag globalInstallDirs
Expand Down Expand Up @@ -1231,12 +1229,7 @@ configFieldDescriptions src =
++ name
++ "' field is case sensitive, use 'True' or 'False'."
)
]
++ toSavedConfig
liftConfigExFlag
(configureExOptions ParseArgs src)
[]
[ let pkgs =
, let pkgs =
(Just . AllowOlder . RelaxDepsSome)
`fmap` parsecOptCommaList parsec
parseAllowOlder =
Expand Down Expand Up @@ -1265,6 +1258,11 @@ configFieldDescriptions src =
configAllowNewer
(\v flags -> flags{configAllowNewer = v})
]
++ toSavedConfig
liftConfigExFlag
(configureExOptions ParseArgs src)
[]
[]
++ toSavedConfig
liftInstallFlag
(installOptions ParseArgs)
Expand Down
5 changes: 3 additions & 2 deletions cabal-install/src/Distribution/Client/Configure.hs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ import Distribution.Version
)

import System.FilePath ((</>))
import Distribution.Types.AllowNewer (AllowOlder(..), AllowNewer (..))

-- | Choose the Cabal version such that the setup scripts compiled against this
-- version will support the given command-line flags. Currently, it implements no
Expand Down Expand Up @@ -430,9 +431,9 @@ planLocalPackage
resolverParams :: DepResolverParams
resolverParams =
removeLowerBounds
(fromMaybe (AllowOlder mempty) $ configAllowOlder configExFlags)
(fromMaybe (AllowOlder mempty) $ configAllowOlder configFlags)
. removeUpperBounds
(fromMaybe (AllowNewer mempty) $ configAllowNewer configExFlags)
(fromMaybe (AllowNewer mempty) $ configAllowNewer configFlags)
. addPreferences
-- preferences from the config file or command line
[ PackageVersionPreference name ver
Expand Down
63 changes: 6 additions & 57 deletions cabal-install/src/Distribution/Client/Dependency.hs
Original file line number Diff line number Diff line change
Expand Up @@ -77,19 +77,17 @@ import Distribution.Client.Dependency.Types
)
import Distribution.Client.SolverInstallPlan (SolverInstallPlan)
import qualified Distribution.Client.SolverInstallPlan as SolverInstallPlan
import Distribution.Client.Types
import Distribution.Types.AllowNewer
( AllowNewer (..)
, AllowOlder (..)
, PackageSpecifier (..)
, RelaxDepMod (..)
, RelaxDepScope (..)
, RelaxDepSubject (..)
, RelaxDeps (..)
, RelaxedDep (..)
, isRelaxDeps
)
import Distribution.Client.Types
( PackageSpecifier (..)
, SourcePackageDb (SourcePackageDb)
, UnresolvedPkgLoc
, UnresolvedSourcePackage
, isRelaxDeps
, pkgSpecifierConstraints
, pkgSpecifierTarget
)
Expand Down Expand Up @@ -163,6 +161,7 @@ import Data.List
)
import qualified Data.Map as Map
import qualified Data.Set as Set
import Distribution.AllowNewer (RelaxKind (..), relaxPackageDeps)

-- ------------------------------------------------------------

Expand Down Expand Up @@ -528,8 +527,6 @@ removeUpperBounds (AllowNewer relDeps) = removeBounds RelaxUpper relDeps
removeLowerBounds :: AllowOlder -> DepResolverParams -> DepResolverParams
removeLowerBounds (AllowOlder relDeps) = removeBounds RelaxLower relDeps

data RelaxKind = RelaxLower | RelaxUpper

-- | Common internal implementation of 'removeLowerBounds'/'removeUpperBounds'
removeBounds :: RelaxKind -> RelaxDeps -> DepResolverParams -> DepResolverParams
removeBounds _ rd params | not (isRelaxDeps rd) = params -- no-op optimisation
Expand All @@ -547,54 +544,6 @@ removeBounds relKind relDeps params =
{ srcpkgDescription = relaxPackageDeps relKind relDeps (srcpkgDescription srcPkg)
}

-- | Relax the dependencies of this package if needed.
--
-- Helper function used by 'removeBounds'
relaxPackageDeps
:: RelaxKind
-> RelaxDeps
-> PD.GenericPackageDescription
-> PD.GenericPackageDescription
relaxPackageDeps _ rd gpd | not (isRelaxDeps rd) = gpd -- subsumed by no-op case in 'removeBounds'
relaxPackageDeps relKind RelaxDepsAll gpd = PD.transformAllBuildDepends relaxAll gpd
where
relaxAll :: Dependency -> Dependency
relaxAll (Dependency pkgName verRange cs) =
Dependency pkgName (removeBound relKind RelaxDepModNone verRange) cs
relaxPackageDeps relKind (RelaxDepsSome depsToRelax0) gpd =
PD.transformAllBuildDepends relaxSome gpd
where
thisPkgName = packageName gpd
thisPkgId = packageId gpd
depsToRelax = Map.fromList $ mapMaybe f depsToRelax0

f :: RelaxedDep -> Maybe (RelaxDepSubject, RelaxDepMod)
f (RelaxedDep scope rdm p) = case scope of
RelaxDepScopeAll -> Just (p, rdm)
RelaxDepScopePackage p0
| p0 == thisPkgName -> Just (p, rdm)
| otherwise -> Nothing
RelaxDepScopePackageId p0
| p0 == thisPkgId -> Just (p, rdm)
| otherwise -> Nothing

relaxSome :: Dependency -> Dependency
relaxSome d@(Dependency depName verRange cs)
| Just relMod <- Map.lookup RelaxDepSubjectAll depsToRelax =
-- a '*'-subject acts absorbing, for consistency with
-- the 'Semigroup RelaxDeps' instance
Dependency depName (removeBound relKind relMod verRange) cs
| Just relMod <- Map.lookup (RelaxDepSubjectPkg depName) depsToRelax =
Dependency depName (removeBound relKind relMod verRange) cs
| otherwise = d -- no-op

-- | Internal helper for 'relaxPackageDeps'
removeBound :: RelaxKind -> RelaxDepMod -> VersionRange -> VersionRange
removeBound RelaxLower RelaxDepModNone = removeLowerBound
removeBound RelaxUpper RelaxDepModNone = removeUpperBound
removeBound RelaxLower RelaxDepModCaret = transformCaretLower
removeBound RelaxUpper RelaxDepModCaret = transformCaretUpper

-- | Supply defaults for packages without explicit Setup dependencies
--
-- Note: It's important to apply 'addDefaultSetupDepends' after
Expand Down
5 changes: 3 additions & 2 deletions cabal-install/src/Distribution/Client/Install.hs
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ import Distribution.Version
)

import qualified Data.ByteString as BS
import Distribution.Types.AllowNewer (AllowOlder(..), AllowNewer (..))

-- TODO:

Expand Down Expand Up @@ -678,11 +679,11 @@ planPackages
allowOlder =
fromMaybe
(AllowOlder mempty)
(configAllowOlder configExFlags)
(configAllowOlder configFlags)
allowNewer =
fromMaybe
(AllowNewer mempty)
(configAllowNewer configExFlags)
(configAllowNewer configFlags)

-- | Remove the provided targets from the install plan.
pruneInstallPlan
Expand Down
1 change: 1 addition & 0 deletions cabal-install/src/Distribution/Client/ProjectConfig.hs
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ import System.IO
( IOMode (ReadMode)
, withBinaryFile
)
import Distribution.Types.AllowNewer (AllowOlder(..), AllowNewer (..))

----------------------------------------
-- Resolving configuration to settings
Expand Down
38 changes: 21 additions & 17 deletions cabal-install/src/Distribution/Client/ProjectConfig/Legacy.hs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import Distribution.Client.Compat.Prelude
import Distribution.Types.Flag (FlagName, parsecFlagAssignment)

import Distribution.Client.ProjectConfig.Types
import Distribution.Client.Types.AllowNewer (AllowNewer (..), AllowOlder (..))
import Distribution.Types.AllowNewer (AllowNewer (..), AllowOlder (..))
import Distribution.Client.Types.Repo (LocalRepo (..), RemoteRepo (..), emptyRemoteRepo)
import Distribution.Client.Types.RepoName (RepoName (..), unRepoName)
import Distribution.Client.Types.SourceRepo (SourceRepoList, sourceRepositoryPackageGrammar)
Expand Down Expand Up @@ -631,6 +631,8 @@ convertLegacyAllPackageFlags globalFlags configFlags configExFlags installFlags
, configHcFlavor = projectConfigHcFlavor
, configHcPath = projectConfigHcPath
, configHcPkg = projectConfigHcPkg
, configAllowOlder = projectConfigAllowOlder
, configAllowNewer = projectConfigAllowNewer
, -- configProgramPathExtra = projectConfigProgPathExtra DELETE ME
configInstallDirs = projectConfigInstallDirs
, -- configUserInstall = projectConfigUserInstall,
Expand All @@ -642,8 +644,6 @@ convertLegacyAllPackageFlags globalFlags configFlags configExFlags installFlags
, configExConstraints = projectConfigConstraints
, configPreferences = projectConfigPreferences
, configSolver = projectConfigSolver
, configAllowOlder = projectConfigAllowOlder
, configAllowNewer = projectConfigAllowNewer
, configWriteGhcEnvironmentFilesPolicy =
projectConfigWriteGhcEnvironmentFilesPolicy
} = configExFlags
Expand Down Expand Up @@ -901,6 +901,8 @@ convertToLegacySharedConfig
, configDistPref = projectConfigDistDir
, configPackageDBs = projectConfigPackageDBs
, configInstallDirs = projectConfigInstallDirs
, configAllowOlder = projectConfigAllowOlder
, configAllowNewer = projectConfigAllowNewer
}

configExFlags =
Expand All @@ -911,8 +913,6 @@ convertToLegacySharedConfig
, configExConstraints = projectConfigConstraints
, configPreferences = projectConfigPreferences
, configSolver = projectConfigSolver
, configAllowOlder = projectConfigAllowOlder
, configAllowNewer = projectConfigAllowNewer
, configWriteGhcEnvironmentFilesPolicy =
projectConfigWriteGhcEnvironmentFilesPolicy
}
Expand Down Expand Up @@ -1035,6 +1035,8 @@ convertToLegacyAllPackageConfig
, configUseResponseFiles = mempty
, configDumpBuildInfo = mempty
, configAllowDependingOnPrivateLibs = mempty
, configAllowNewer = Nothing
, configAllowOlder = Nothing
}

haddockFlags =
Expand Down Expand Up @@ -1111,6 +1113,8 @@ convertToLegacyPerPackageConfig PackageConfig{..} =
, configUseResponseFiles = mempty
, configDumpBuildInfo = packageConfigDumpBuildInfo
, configAllowDependingOnPrivateLibs = mempty
, configAllowNewer = Nothing
, configAllowOlder = Nothing
}

installFlags =
Expand Down Expand Up @@ -1325,6 +1329,18 @@ legacySharedConfigFieldDescrs constraintSrc =
(fmap readPackageDb parsecToken)
configPackageDBs
(\v conf -> conf{configPackageDBs = v})
, monoidFieldParsec
"allow-older"
(maybe mempty pretty)
(fmap Just parsec)
(fmap unAllowOlder . configAllowOlder)
(\v conf -> conf{configAllowOlder = fmap AllowOlder v})
, monoidFieldParsec
"allow-newer"
(maybe mempty pretty)
(fmap Just parsec)
(fmap unAllowNewer . configAllowNewer)
(\v conf -> conf{configAllowNewer = fmap AllowNewer v})
]
. filterFields (["verbose", "builddir"] ++ map optionName installDirsOptions)
. commandOptionsToFields
Expand All @@ -1345,18 +1361,6 @@ legacySharedConfigFieldDescrs constraintSrc =
parsec
configPreferences
(\v conf -> conf{configPreferences = v})
, monoidFieldParsec
"allow-older"
(maybe mempty pretty)
(fmap Just parsec)
(fmap unAllowOlder . configAllowOlder)
(\v conf -> conf{configAllowOlder = fmap AllowOlder v})
, monoidFieldParsec
"allow-newer"
(maybe mempty pretty)
(fmap Just parsec)
(fmap unAllowNewer . configAllowNewer)
(\v conf -> conf{configAllowNewer = fmap AllowNewer v})
]
. filterFields
[ "cabal-lib-version"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import Distribution.Client.Dependency.Types
import Distribution.Client.Targets
( UserConstraint
)
import Distribution.Client.Types.AllowNewer (AllowNewer (..), AllowOlder (..))
import Distribution.Types.AllowNewer (AllowNewer (..), AllowOlder (..))
import Distribution.Client.Types.Repo (LocalRepo, RemoteRepo)
import Distribution.Client.Types.SourceRepo (SourceRepoList)
import Distribution.Client.Types.WriteGhcEnvironmentFilesPolicy (WriteGhcEnvironmentFilesPolicy)
Expand Down
2 changes: 2 additions & 0 deletions cabal-install/src/Distribution/Client/ProjectPlanning.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4252,6 +4252,8 @@ setupHsConfigureFlags
configPrograms_ = mempty -- never use, shouldn't exist
configUseResponseFiles = mempty
configAllowDependingOnPrivateLibs = Flag $ not $ libraryVisibilitySupported pkgConfigCompiler
configAllowNewer = Nothing
configAllowOlder = Nothing

cidToGivenComponent :: ConfiguredId -> GivenComponent
cidToGivenComponent (ConfiguredId srcid mb_cn cid) = GivenComponent (packageName srcid) ln cid
Expand Down
Loading

0 comments on commit 19dd95a

Please sign in to comment.