Skip to content
Closed
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
19 changes: 14 additions & 5 deletions Cabal/Distribution/Simple/Register.hs
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,21 @@ import qualified Data.ByteString.Lazy.Char8 as BS.Char8
register :: PackageDescription -> LocalBuildInfo
-> RegisterFlags -- ^Install in the user's database?; verbose
-> IO ()
register pkg_descr lbi flags = when (hasPublicLib pkg_descr) doRegister
register pkg_descr lbi flags =
-- We do NOT register libraries outside of the inplace database
-- if there is no public library, since no one else can use it
-- usefully (they're not public.) If we start supporting scoped
-- packages, we'll have to relax this.
--
-- HOWEVER, we ALWAYS do work if we are asked to generate
-- a file or script.
when (hasPublicLib pkg_descr || modeGenerateRegFile
|| modeGenerateRegScript) doRegister
where
-- We do NOT register libraries outside of the inplace database
-- if there is no public library, since no one else can use it
-- usefully (they're not public.) If we start supporting scoped
-- packages, we'll have to relax this.
-- Urk, duplicate with 'registerAll'
modeGenerateRegFile = isJust (flagToMaybe (regGenPkgConf flags))
modeGenerateRegScript = fromFlag (regGenScript flags)

doRegister = do
targets <- readBuildTargets pkg_descr (regArgs flags)
targets' <- checkBuildTargets verbosity pkg_descr targets
Expand Down
65 changes: 40 additions & 25 deletions cabal-install/Distribution/Client/Dependency/TopDown/Constraints.hs
Original file line number Diff line number Diff line change
Expand Up @@ -76,27 +76,29 @@ import Control.Exception
-- constraints.
--
data Constraints installed source reason
= Constraints
= Constraints {

-- | Targets that we know we need. This is the set for which we
-- guarantee the constraints are satisfiable.
!(Set PackageName)
constraintsTargets :: !(Set PackageName),

-- | The available/remaining set. These are packages that have available
-- choices remaining. This is guaranteed to cover the target packages,
-- but can also cover other packages in the environment. New targets can
-- only be added if there are available choices remaining for them.
!(PackageIndex (InstalledOrSource installed source))
constraintsAvailable :: !(PackageIndex (InstalledOrSource installed source)),

-- | The excluded set. Choices that we have excluded by applying
-- constraints. Excluded choices are tagged with the reason.
!(PackageIndex (ExcludedPkg (InstalledOrSource installed source) reason))
constraintsExcluded :: !(PackageIndex (ExcludedPkg (InstalledOrSource installed source) reason)),

-- | Paired choices, this is an ugly hack.
!(Map PackageName (Version, Version))
constraintsPairs :: !(Map PackageName (Version, Version)),

-- | Purely for the invariant, we keep a copy of the original index
!(PackageIndex (InstalledOrSource installed source))
constraintsOriginal :: !(PackageIndex (InstalledOrSource installed source))

}


-- | Reasons for excluding all, or some choices for a package version.
Expand All @@ -106,21 +108,26 @@ data Constraints installed source reason
-- from reasons for constraints that excluded just one instance.
--
data ExcludedPkg pkg reason
= ExcludedPkg pkg
[reason] -- ^ reasons for excluding both source and installed instances
[reason] -- ^ reasons for excluding the installed instance
[reason] -- ^ reasons for excluding the source instance
= ExcludedPkg {
excludedPkg :: pkg,
_excludedPkgSrcInstReasons :: [reason], -- ^ reasons for excluding both source and installed instances
_excludedPkgInstReasons :: [reason], -- ^ reasons for excluding the installed instance
_excludedPkgSrcReasons :: [reason] -- ^ reasons for excluding the source instance
}

instance Package pkg => Package (ExcludedPkg pkg reason) where
packageId (ExcludedPkg p _ _ _) = packageId p
packageId = packageId . excludedPkg


-- | There is a conservation of packages property. Packages are never gained or
-- lost, they just transfer from the remaining set to the excluded set.
--
invariant :: (Package installed, Package source)
=> Constraints installed source a -> Bool
invariant (Constraints targets available excluded _ original) =
invariant (Constraints { constraintsTargets = targets
, constraintsAvailable = available
, constraintsExcluded = excluded
, constraintsOriginal = original }) =

-- Relationship between available, excluded and original
all check merged
Expand Down Expand Up @@ -182,8 +189,7 @@ invariant (Constraints targets available excluded _ original) =
transitionsTo :: (Package installed, Package source)
=> Constraints installed source a
-> Constraints installed source a -> Bool
transitionsTo constraints @(Constraints _ available excluded _ _)
constraints'@(Constraints _ available' excluded' _ _) =
transitionsTo constraints constraints' =

invariant constraints && invariant constraints'
&& null availableGained && null excludedLost
Expand All @@ -199,13 +205,13 @@ transitionsTo constraints @(Constraints _ available excluded _ _)

availableChange =
mergeBy (\a b -> packageId a `compare` packageId b)
(PackageIndex.allPackages available)
(PackageIndex.allPackages available')
(PackageIndex.allPackages (constraintsAvailable constraints))
(PackageIndex.allPackages (constraintsAvailable constraints'))

excludedChange =
mergeBy (\a b -> packageId a `compare` packageId b)
[ pkg | ExcludedPkg pkg _ _ _ <- PackageIndex.allPackages excluded ]
[ pkg | ExcludedPkg pkg _ _ _ <- PackageIndex.allPackages excluded' ]
(map excludedPkg (PackageIndex.allPackages (constraintsExcluded constraints)))
(map excludedPkg (PackageIndex.allPackages (constraintsExcluded constraints')))

lostAndGained mr rest = case mr of
OnlyInLeft pkg -> Left pkg : rest
Expand All @@ -232,7 +238,13 @@ empty :: PackageIndex InstalledPackageEx
-> PackageIndex UnconfiguredPackage
-> Constraints InstalledPackageEx UnconfiguredPackage reason
empty installed source =
Constraints targets pkgs excluded pairs pkgs
Constraints {
constraintsTargets = targets,
constraintsAvailable = pkgs,
constraintsExcluded = excluded,
constraintsPairs = pairs,
constraintsOriginal = pkgs
}
where
targets = mempty
excluded = mempty
Expand All @@ -256,23 +268,26 @@ empty installed source =
|| any ((pkgid2==) . packageId) (sourceDeps pkg1) ]


-- NB: we don't export the record fields directly to prevent users from
-- being to apply a record update.

-- | The package targets.
--
packages :: Constraints installed source reason
-> Set PackageName
packages (Constraints ts _ _ _ _) = ts
packages = constraintsTargets


-- | The package choices that are still available.
--
choices :: Constraints installed source reason
-> PackageIndex (InstalledOrSource installed source)
choices (Constraints _ available _ _ _) = available
choices = constraintsAvailable

isPaired :: Constraints installed source reason
-> PackageId -> Maybe PackageId
isPaired (Constraints _ _ _ pairs _) (PackageIdentifier name version) =
case Map.lookup name pairs of
isPaired constraints (PackageIdentifier name version) =
case Map.lookup name (constraintsPairs constraints) of
Just (v1, v2)
| version == v1 -> Just (PackageIdentifier name v2)
| version == v2 -> Just (PackageIdentifier name v1)
Expand Down Expand Up @@ -593,7 +608,7 @@ conflicting :: (Package installed, Package source)
=> Constraints installed source reason
-> Dependency
-> [(PackageId, [reason])]
conflicting (Constraints _ _ excluded _ _) dep =
conflicting constraints dep =
[ (packageId pkg, reasonsAll ++ reasonsAvail ++ reasonsInstalled) --TODO
| ExcludedPkg pkg reasonsAll reasonsAvail reasonsInstalled <-
PackageIndex.lookupDependency excluded dep ]
PackageIndex.lookupDependency (constraintsExcluded constraints) dep ]
19 changes: 12 additions & 7 deletions cabal-install/Distribution/Client/Init/Heuristics.hs
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,11 @@ guessAuthorNameMail = fmap authorGuessPure authorGuessIO
-- Ordered in increasing preference, since Flag-as-monoid is identical to
-- Last.
authorGuessPure :: AuthorGuessIO -> AuthorGuess
authorGuessPure (AuthorGuessIO env darcsLocalF darcsGlobalF gitLocal gitGlobal)
authorGuessPure (AuthorGuessIO { authorGuessEnv = env
, authorGuessLocalDarcs = darcsLocalF
, authorGuessGlobalDarcs = darcsGlobalF
, authorGuessLocalGit = gitLocal
, authorGuessGlobalGit = gitGlobal })
= mconcat
[ emailEnv env
, gitGlobal
Expand All @@ -278,12 +282,13 @@ authorGuessIO = AuthorGuessIO
type AuthorGuess = (Flag String, Flag String)
type Enviro = [(String, String)]
data GitLoc = Local | Global
data AuthorGuessIO = AuthorGuessIO
Enviro -- ^ Environment lookup table
(Maybe String) -- ^ Contents of local darcs author info
(Maybe String) -- ^ Contents of global darcs author info
AuthorGuess -- ^ Git config --local
AuthorGuess -- ^ Git config --global
data AuthorGuessIO = AuthorGuessIO {
authorGuessEnv :: Enviro, -- ^ Environment lookup table
authorGuessLocalDarcs :: (Maybe String), -- ^ Contents of local darcs author info
authorGuessGlobalDarcs :: (Maybe String), -- ^ Contents of global darcs author info
authorGuessLocalGit :: AuthorGuess, -- ^ Git config --local
authorGuessGlobalGit :: AuthorGuess -- ^ Git config --global
}

darcsEnv :: Enviro -> AuthorGuess
darcsEnv = maybe mempty nameAndMail . lookup "DARCS_EMAIL"
Expand Down
8 changes: 4 additions & 4 deletions cabal-install/Distribution/Client/ProjectPlanning.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1314,10 +1314,10 @@ elaborateInstallPlan platform compiler compilerprogdb
-- package config validation/resolution pass.

--TODO: [nice to have] config consistency checking:
-- * profiling libs & exes, exe needs lib, recursive
-- * shared libs & exes, exe needs lib, recursive
-- * vanilla libs & exes, exe needs lib, recursive
-- * ghci or shared lib needed by TH, recursive, ghc version dependent
-- + profiling libs & exes, exe needs lib, recursive
-- + shared libs & exes, exe needs lib, recursive
-- + vanilla libs & exes, exe needs lib, recursive
-- + ghci or shared lib needed by TH, recursive, ghc version dependent


---------------------------
Expand Down
2 changes: 1 addition & 1 deletion cabal-install/Distribution/Client/Sandbox.hs
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ loadConfigOrSandboxConfig verbosity globalFlags = do
-- A @cabal.sandbox.config@ file (and possibly @cabal.config@) is present.
SandboxPackageEnvironment -> do
(sandboxDir, pkgEnv) <- tryLoadSandboxConfig verbosity globalFlags
-- ^ Prints an error message and exits on error.
-- Prints an error message and exits on error.
let config = pkgEnvSavedConfig pkgEnv
return (UseSandbox sandboxDir, config)

Expand Down
4 changes: 2 additions & 2 deletions cabal-install/Distribution/Client/Setup.hs
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ configureOptions = commandOptions configureCommand
filterConfigureFlags :: ConfigFlags -> Version -> ConfigFlags
filterConfigureFlags flags cabalLibVersion
| cabalLibVersion >= Version [1,23,0] [] = flags_latest
-- ^ NB: we expect the latest version to be the most common case.
-- NB: we expect the latest version to be the most common case.
| cabalLibVersion < Version [1,3,10] [] = flags_1_3_10
| cabalLibVersion < Version [1,10,0] [] = flags_1_10_0
| cabalLibVersion < Version [1,12,0] [] = flags_1_12_0
Expand Down Expand Up @@ -1716,7 +1716,7 @@ data SDistExFlags = SDistExFlags {
}
deriving (Show, Generic)

data ArchiveFormat = TargzFormat | ZipFormat -- | ...
data ArchiveFormat = TargzFormat | ZipFormat -- ...
deriving (Show, Eq)

defaultSDistExFlags :: SDistExFlags
Expand Down
16 changes: 8 additions & 8 deletions cabal-install/Distribution/Solver/Modular/Solver.hs
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,14 @@ data SolverConfig = SolverConfig {
-- seems to be no statistically significant performance impact of cycle
-- detection in the common case where there are no cycles.
--
solve :: SolverConfig -> -- ^ solver parameters
CompilerInfo ->
Index -> -- ^ all available packages as an index
PkgConfigDb -> -- ^ available pkg-config pkgs
(PN -> PackagePreferences) -> -- ^ preferences
Map PN [LabeledPackageConstraint] -> -- ^ global constraints
[PN] -> -- ^ global goals
Log Message (Assignment, RevDepMap)
solve :: SolverConfig -- ^ solver parameters
-> CompilerInfo
-> Index -- ^ all available packages as an index
-> PkgConfigDb -- ^ available pkg-config pkgs
-> (PN -> PackagePreferences) -- ^ preferences
-> Map PN [LabeledPackageConstraint] -- ^ global constraints
-> [PN] -- ^ global goals
-> Log Message (Assignment, RevDepMap)
solve sc cinfo idx pkgConfigDB userPrefs userConstraints userGoals =
explorePhase $
detectCycles $
Expand Down
Loading