Skip to content

Refactor of PackageIndex and InstallPlan #3525

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 30 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
457605c
Comment.
ezyang Jul 11, 2016
49d69a9
Move SolverInstallPlan to its own module.
ezyang Jul 3, 2016
a0891eb
Make a copy of InstallPlan named SolverInstallPlan.
ezyang Jul 4, 2016
07bb6d1
Specialize and delete code not needed by SolverInstallPlan.
ezyang Jul 4, 2016
0462e16
Delete code not needed by InstallPlan.
ezyang Jul 6, 2016
59faddb
IsNode instance for InstalledPackageInfo.
ezyang Jul 19, 2016
c0fd748
Rewrite SolverInstallPlan so that it uses Distribution.Compat.Graph.
ezyang Jul 6, 2016
42f223c
Rewrite InstallPlan so that it uses Distribution.Compat.Graph.
ezyang Jul 6, 2016
d350003
Axe SolverPlanPackage to reuse ResolverPackage.
ezyang Jul 7, 2016
f76e3cb
Change key of SolverInstallPlan to be SolverId.
ezyang Jul 7, 2016
caf691f
Delete unsafeInternalFakeUnitId and chase consequences.
ezyang Jul 7, 2016
3b2d82e
Dependency inconsistency must consider non-setup dep closures.
ezyang Jul 9, 2016
309a012
Don't include package in the transitive dependency list.
ezyang Jul 10, 2016
a493bca
Display class for ComponentName.
ezyang Jul 10, 2016
b67bb96
Delete unused exposedSignatures method.
ezyang Jul 19, 2016
3d4cabb
Fix PR builds by only setting up .ssh/id_rsa when on master.
ezyang Jul 19, 2016
851600e
Rewrite Travis CI script.
ezyang Jul 20, 2016
9eb65cd
Fix orphan warning
ezyang Jul 21, 2016
3920a49
Turn up sdist verbosity
ezyang Jul 21, 2016
82ea96d
Swizzle.
ezyang Jul 21, 2016
1225293
travis fixes
ezyang Jul 21, 2016
5c03866
Minor fixes.
ezyang Jul 21, 2016
b12025d
I think this should fix all the bugs
ezyang Jul 21, 2016
66eb252
Try this.
ezyang Jul 21, 2016
76f23fe
Fix up
ezyang Jul 21, 2016
ab1d627
Hack
ezyang Jul 21, 2016
4252d89
Hmmmm
ezyang Jul 21, 2016
4567452
Try handling BUILDDIR directly in integration-tests
ezyang Jul 21, 2016
14a320c
Typofix.
ezyang Jul 21, 2016
fe853c2
Different strategy.
ezyang Jul 21, 2016
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
65 changes: 49 additions & 16 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,53 +2,73 @@
# We specify language: c, so it doesn't default to e.g. ruby
language: c

sudo: required
sudo: false

# The following enables several GHC versions to be tested; often it's enough to
# test only against the last release in a major GHC version. Feel free to omit
# lines listings versions you don't need/want testing for.
matrix:
include:
- env: GHCVER=7.4.2
- env: GHCVER=none SCRIPT=meta
os: linux
- env: GHCVER=7.6.3
# These don't have -dyn/-prof whitelisted yet, so we have to
# do the old-style installation
- env: GHCVER=7.4.2 SCRIPT=script
os: linux
- env: GHCVER=7.8.4
sudo: required
- env: GHCVER=7.6.3 SCRIPT=script
os: linux
- env: GHCVER=7.10.3
sudo: required
- env: GHCVER=7.8.4 SCRIPT=script
os: linux
- env: GHCVER=8.0.1 TEST_OLDER=NO DEPLOY_DOCS=YES
sudo: required
# Ugh, we'd like to drop 'sudo: required' and use the
# apt plugin for the next two
# but the GCE instance we get has more memory, which makes
# a big difference
- env: GHCVER=7.10.3 SCRIPT=script
os: linux
sudo: required
- env: GHCVER=8.0.1 SCRIPT=script DEPLOY_DOCS=YES
sudo: required
os: linux
- env: GHCVER=8.0.1 SCRIPT=bootstrap
sudo: required
os: linux
# It's not worth the trouble to make older GHC work with clang's cpp
# Obviously TEST_OLDER doesn't work with OSX
# TEST_OLDER is not implemented on OSX
#
# Also we might want to specify OSX version
# https://docs.travis-ci.com/user/osx-ci-environment/#OS-X-Version
- env: GHCVER=7.8.4
- env: GHCVER=7.8.4 SCRIPT=script
os: osx
- env: GHCVER=7.10.3
- env: GHCVER=7.10.3 SCRIPT=script
os: osx
- env: GHCVER=8.0.1
- env: GHCVER=8.0.1 SCRIPT=script
os: osx
allow_failures:
- env: GHCVER=head
sudo: required

# TODO add PARSEC_BUNDLED=YES when it's so
# It seems pointless to run head if we're going to ignore the results.
#- GHCVER=head

# Note: the distinction between `before_install` and `install` is not important.
before_install:
- ./travis-install.sh
- export PATH=/opt/ghc/$GHCVER/bin:$PATH
- export PATH=$HOME/.ghc-install/$GHCVER/bin:$PATH;
- export PATH=$HOME/.ghc-install/$GHCVER/bin:$PATH
- export PATH=$HOME/bin:$PATH
- export PATH=$HOME/.cabal/bin:$PATH
- export PATH=/opt/cabal/1.24/bin:$PATH
- export PATH=/opt/happy/1.19.5/bin:$PATH
- ./travis-install.sh

# Set up deployment to the haskell/cabal-website repo.
# NB: these commands MUST be in .travis.yml, otherwise the secret key can be
# leaked! See https://github.com/travis-ci/travis.rb/issues/423.
- openssl aes-256-cbc -K $encrypted_edaf6551664d_key -iv $encrypted_edaf6551664d_iv -in id_rsa_cabal_website.aes256.enc -out id_rsa -d
- mv id_rsa ~/.ssh/id_rsa
- chmod 400 ~/.ssh/id_rsa
# umask to get the permissions to be 400.
- if [ "x$TRAVIS_PULL_REQUEST" = "xfalse" -a "x$TRAVIS_BRANCH" = "xmaster" -a "x$DEPLOY_DOCS" = "xYES" ]; then (umask 377 && openssl aes-256-cbc -K $encrypted_edaf6551664d_key -iv $encrypted_edaf6551664d_iv -in id_rsa_cabal_website.aes256.enc -out ~/.ssh/id_rsa -d); fi

install:
# We intentionally do not install anything before trying to build Cabal because
Expand All @@ -59,7 +79,20 @@ install:
# ./dist/setup/setup here instead of cabal-install to avoid breakage when the
# build config format changed.
script:
- ./travis-script.sh -j
- ./travis-${SCRIPT}.sh

cache:
directories:
- $HOME/.cabal/packages
- $HOME/.cabal/store
- $HOME/.cabal/bin

# We remove the index because it churns quite a bit and we don't want
# to pay the cost of repeatedly caching it even though we don't care
# about most changing packages.
before_cache:
- rm -fv $HOME/.cabal/packages/hackage.haskell.org/build-reports.log
- rm -fv $HOME/.cabal/packages/hackage.haskell.org/00-index*

# Deploy Haddocks to the haskell/cabal-website repo.
after_success:
Expand Down
2 changes: 1 addition & 1 deletion Cabal/Distribution/Compat/Environment.hs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ lookupEnv name = (Just `fmap` System.getEnv name) `catchIO` const (return Nothin
-- empty string or contains an equals sign.
setEnv :: String -> String -> IO ()
setEnv key value_
| null value = error "Distribuiton.Compat.setEnv: empty string"
| null value = error "Distribution.Compat.setEnv: empty string"
| otherwise = setEnv_ key value
where
-- NOTE: Anything that follows NUL is ignored on both POSIX and Windows. We
Expand Down
7 changes: 7 additions & 0 deletions Cabal/Distribution/InstalledPackageInfo.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE TypeFamilies #-}

-----------------------------------------------------------------------------
-- |
Expand Down Expand Up @@ -49,6 +50,7 @@ import Distribution.Version
import Distribution.Text
import qualified Distribution.Compat.ReadP as Parse
import Distribution.Compat.Binary
import Distribution.Compat.Graph

import Text.PrettyPrint as Disp
import Data.Maybe (fromMaybe)
Expand Down Expand Up @@ -120,6 +122,11 @@ instance Package.HasUnitId InstalledPackageInfo where
instance Package.PackageInstalled InstalledPackageInfo where
installedDepends = depends

instance IsNode InstalledPackageInfo where
type Key InstalledPackageInfo = UnitId
nodeKey = installedUnitId
nodeNeighbors = depends

emptyInstalledPackageInfo :: InstalledPackageInfo
emptyInstalledPackageInfo
= InstalledPackageInfo {
Expand Down
21 changes: 17 additions & 4 deletions Cabal/Distribution/PackageDescription.hs
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,6 @@ data Library = Library {
exposedModules :: [ModuleName],
reexportedModules :: [ModuleReexport],
requiredSignatures:: [ModuleName], -- ^ What sigs need implementations?
exposedSignatures:: [ModuleName], -- ^ What sigs are visible to users?
libExposed :: Bool, -- ^ Is the lib to be exposed by default?
libBuildInfo :: BuildInfo
}
Expand All @@ -413,7 +412,6 @@ instance Monoid Library where
exposedModules = mempty,
reexportedModules = mempty,
requiredSignatures = mempty,
exposedSignatures = mempty,
libExposed = True,
libBuildInfo = mempty
}
Expand All @@ -425,7 +423,6 @@ instance Semigroup Library where
exposedModules = combine exposedModules,
reexportedModules = combine reexportedModules,
requiredSignatures = combine requiredSignatures,
exposedSignatures = combine exposedSignatures,
libExposed = libExposed a && libExposed b, -- so False propagates
libBuildInfo = combine libBuildInfo
}
Expand Down Expand Up @@ -462,7 +459,6 @@ withLib pkg_descr f =
libModules :: Library -> [ModuleName]
libModules lib = exposedModules lib
++ otherModules (libBuildInfo lib)
++ exposedSignatures lib
++ requiredSignatures lib

-- -----------------------------------------------------------------------------
Expand Down Expand Up @@ -975,6 +971,23 @@ data ComponentName = CLibName String

instance Binary ComponentName

-- Build-target-ish syntax
instance Text ComponentName where
disp (CLibName str) = Disp.text ("lib:" ++ str)
disp (CExeName str) = Disp.text ("exe:" ++ str)
disp (CTestName str) = Disp.text ("test:" ++ str)
disp (CBenchName str) = Disp.text ("bench:" ++ str)

parse = do
ctor <- Parse.choice [ Parse.string "lib:" >> return CLibName
, Parse.string "exe:" >> return CExeName
, Parse.string "bench:" >> return CBenchName
, Parse.string "test:" >> return CTestName ]
-- For now, component names coincide with package name syntax
-- (since they can show up in build-depends, which are parsed
-- as package names.)
fmap (ctor . unPackageName) parse

defaultLibName :: PackageIdentifier -> ComponentName
defaultLibName pid = CLibName (display (pkgName pid))

Expand Down
5 changes: 0 additions & 5 deletions Cabal/Distribution/PackageDescription/Check.hs
Original file line number Diff line number Diff line change
Expand Up @@ -227,11 +227,6 @@ checkLibrary pkg lib =
PackageDistInexcusable $
"To use the 'required-signatures' field the package needs to specify "
++ "at least 'cabal-version: >= 1.21'."

, checkVersion [1,21] (not (null (exposedSignatures lib))) $
PackageDistInexcusable $
"To use the 'exposed-signatures' field the package needs to specify "
++ "at least 'cabal-version: >= 1.21'."
]

where
Expand Down
3 changes: 0 additions & 3 deletions Cabal/Distribution/PackageDescription/Parse.hs
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,6 @@ libFieldDescrs =
, listFieldWithSep vcat "required-signatures" disp parseModuleNameQ
requiredSignatures (\mods lib -> lib{requiredSignatures=mods})

, listFieldWithSep vcat "exposed-signatures" disp parseModuleNameQ
exposedSignatures (\mods lib -> lib{exposedSignatures=mods})

, boolField "exposed"
libExposed (\val lib -> lib{libExposed=val})
] ++ map biToLib binfoFieldDescrs
Expand Down
1 change: 0 additions & 1 deletion Cabal/Distribution/Simple/Build.hs
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,6 @@ testSuiteLibV09AsLibAndExe pkg_descr
exposedModules = [ m ],
reexportedModules = [],
requiredSignatures = [],
exposedSignatures = [],
libExposed = True,
libBuildInfo = bi
}
Expand Down
4 changes: 3 additions & 1 deletion Cabal/Distribution/Version.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
#endif
#endif

#if !MIN_VERSION_binary_0_8_0
#if !MIN_VERSION_binary_0_8_0 || __GLASGOW_HASKELL__ < 707
-- instance Binary Version for !MIN_VERSION_binary_0_8_0
-- instance Data Version for __GLASGOW_HASKELL__ < 707
{-# OPTIONS_GHC -fno-warn-orphans #-}
#endif

Expand Down
2 changes: 2 additions & 0 deletions Cabal/tests/UnitTests/Distribution/Compat/Graph.hs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ hasNoDups = loop Set.empty
| otherwise
= False

-- | Produces a graph of size @len@. We sample with 'suchThat'; if we
-- dropped duplicate entries our size could be smaller.
arbitraryGraph :: (Ord k, Arbitrary k, Arbitrary a) => Int -> Gen (Graph (Node k a))
arbitraryGraph len = do
-- Careful! Assume k is much larger than size.
Expand Down
2 changes: 1 addition & 1 deletion cabal-install/Distribution/Client/Configure.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module Distribution.Client.Configure (

import Distribution.Client.Dependency
import qualified Distribution.Client.InstallPlan as InstallPlan
import Distribution.Client.InstallPlan (SolverInstallPlan)
import Distribution.Client.SolverInstallPlan (SolverInstallPlan)
import Distribution.Client.IndexUtils as IndexUtils
( getSourcePackages, getInstalledPackages )
import Distribution.Client.Setup
Expand Down
16 changes: 7 additions & 9 deletions cabal-install/Distribution/Client/Dependency.hs
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ import Distribution.Solver.Modular
( modularResolver, SolverConfig(..) )
import Distribution.Simple.PackageIndex (InstalledPackageIndex)
import qualified Distribution.Simple.PackageIndex as InstalledPackageIndex
import qualified Distribution.Client.InstallPlan as InstallPlan
import Distribution.Client.InstallPlan (SolverInstallPlan)
import Distribution.Client.SolverInstallPlan (SolverInstallPlan)
import qualified Distribution.Client.SolverInstallPlan as SolverInstallPlan
import Distribution.Client.Types
( SourcePackageDb(SourcePackageDb)
, UnresolvedPkgLoc, UnresolvedSourcePackage
Expand Down Expand Up @@ -112,6 +112,7 @@ import Distribution.Text
( display )
import Distribution.Verbosity
( Verbosity )
import qualified Distribution.Compat.Graph as Graph

import Distribution.Solver.Types.ComponentDeps (ComponentDeps)
import qualified Distribution.Solver.Types.ComponentDeps as CD
Expand Down Expand Up @@ -718,27 +719,24 @@ validateSolverResult :: Platform
-> SolverInstallPlan
validateSolverResult platform comp indepGoals pkgs =
case planPackagesProblems platform comp pkgs of
[] -> case InstallPlan.new indepGoals index of
[] -> case SolverInstallPlan.new indepGoals index of
Right plan -> plan
Left problems -> error (formatPlanProblems problems)
problems -> error (formatPkgProblems problems)

where
index = InstalledPackageIndex.fromList (map toPlanPackage pkgs)

toPlanPackage (PreExisting pkg) = InstallPlan.PreExisting pkg
toPlanPackage (Configured pkg) = InstallPlan.Configured pkg
index = Graph.fromList pkgs

formatPkgProblems = formatProblemMessage . map showPlanPackageProblem
formatPlanProblems = formatProblemMessage . map InstallPlan.showPlanProblem
formatPlanProblems = formatProblemMessage . map SolverInstallPlan.showPlanProblem

formatProblemMessage problems =
unlines $
"internal error: could not construct a valid install plan."
: "The proposed (invalid) plan contained the following problems:"
: problems
++ "Proposed plan:"
: [InstallPlan.showPlanIndex index]
: [SolverInstallPlan.showPlanIndex index]


data PlanPackageProblem =
Expand Down
8 changes: 6 additions & 2 deletions cabal-install/Distribution/Client/Dependency/TopDown.hs
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,12 @@ topDownResolver' platform cinfo installedPkgIndex sourcePkgIndex
$ finaliseSelectedPackages preferences selected' constraints'

toResolverPackage :: FinalSelectedPackage -> ResolverPackage UnresolvedPkgLoc
toResolverPackage (SelectedInstalled (InstalledPackage pkg _))
= PreExisting pkg
toResolverPackage (SelectedInstalled (InstalledPackage pkg pid_deps))
= PreExisting pkg deps
where deps = CD.fromLibraryDeps lib
. zipWith PreExistingId pid_deps
$ InstalledPackageInfo.depends pkg
lib = display (packageName pkg)
toResolverPackage (SelectedSource pkg) = Configured pkg

addTopLevelTargets :: [PackageName]
Expand Down
6 changes: 3 additions & 3 deletions cabal-install/Distribution/Client/Fetch.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import Distribution.Client.FetchUtils hiding (fetchPackage)
import Distribution.Client.Dependency
import Distribution.Client.IndexUtils as IndexUtils
( getSourcePackages, getInstalledPackages )
import qualified Distribution.Client.InstallPlan as InstallPlan
import qualified Distribution.Client.SolverInstallPlan as SolverInstallPlan
import Distribution.Client.Setup
( GlobalFlags(..), FetchFlags(..), RepoContext(..) )

Expand Down Expand Up @@ -141,8 +141,8 @@ planPackages verbosity comp platform fetchFlags
-- that are in the 'InstallPlan.Configured' state.
return
[ solverPkgSource cpkg
| (InstallPlan.Configured cpkg)
<- InstallPlan.toList installPlan ]
| (SolverInstallPlan.Configured cpkg)
<- SolverInstallPlan.toList installPlan ]

| otherwise =
either (die . unlines . map show) return $
Expand Down
8 changes: 4 additions & 4 deletions cabal-install/Distribution/Client/Freeze.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ import Distribution.Client.Targets
import Distribution.Client.Dependency
import Distribution.Client.IndexUtils as IndexUtils
( getSourcePackages, getInstalledPackages )
import Distribution.Client.InstallPlan
import Distribution.Client.SolverInstallPlan
( SolverInstallPlan, SolverPlanPackage )
import qualified Distribution.Client.InstallPlan as InstallPlan
import qualified Distribution.Client.SolverInstallPlan as SolverInstallPlan
import Distribution.Client.Setup
( GlobalFlags(..), FreezeFlags(..), ConfigExFlags(..)
, RepoContext(..) )
Expand All @@ -41,7 +41,7 @@ import Distribution.Solver.Types.PkgConfigDb
import Distribution.Solver.Types.SolverId

import Distribution.Package
( Package, packageId, packageName, packageVersion, installedUnitId )
( Package, packageId, packageName, packageVersion )
import Distribution.Simple.Compiler
( Compiler, compilerInfo, PackageDBStack )
import Distribution.Simple.PackageIndex (InstalledPackageIndex)
Expand Down Expand Up @@ -227,7 +227,7 @@ pruneInstallPlan :: SolverInstallPlan
-> [SolverPlanPackage]
pruneInstallPlan installPlan pkgSpecifiers =
removeSelf pkgIds $
InstallPlan.dependencyClosure installPlan (map installedUnitId pkgIds)
SolverInstallPlan.dependencyClosure installPlan pkgIds
where
pkgIds = [ PlannedId (packageId pkg)
| SpecificSourcePackage pkg <- pkgSpecifiers ]
Expand Down
Loading