Skip to content
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

[RFC] Move dependency solver to library #2768

Closed
wants to merge 6 commits into from
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
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ script:
- cd ../cabal-install
- cabal sandbox init
- cabal sandbox add-source ../Cabal
- cabal sandbox add-source ../cabal-install-lib
- cabal sandbox add-source ../cabal-install-solver
- cabal install --dependencies-only --enable-tests
- cabal configure --enable-tests --ghc-option=-Werror
- cabal build
Expand Down
30 changes: 30 additions & 0 deletions cabal-install-lib/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
Copyright (c) 2015, FIXME

All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.

* Neither the name of FIXME nor the names of other
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2 changes: 2 additions & 0 deletions cabal-install-lib/Setup.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import Distribution.Simple
main = defaultMain
73 changes: 73 additions & 0 deletions cabal-install-lib/cabal-install-lib.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
name: cabal-install-lib
version: 1.23.0.0
synopsis: Cabal-install client utility library
description: Various utilities needed by cabal-install
homepage: http://www.haskell.org/cabal/
bug-reports: https://github.com/haskell/cabal/issues
license: BSD3
license-file: LICENSE
author: Lemmih <[email protected]>
Paolo Martini <[email protected]>
Bjorn Bringert <[email protected]>
Isaac Potoczny-Jones <[email protected]>
Duncan Coutts <[email protected]>
maintainer: FIXME
copyright: 2005 Lemmih <[email protected]>
2006 Paolo Martini <[email protected]>
2007 Bjorn Bringert <[email protected]>
2007 Isaac Potoczny-Jones <[email protected]>
2007-2012 Duncan Coutts <[email protected]>
category: Distribution
build-type: Simple
cabal-version: >=1.10

Flag old-directory
description: Use directory < 1.2 and old-time
default: False

Flag network-uri
description: Get Network.URI from the network-uri package
default: True

library
ghc-options: -Wall -fwarn-tabs
exposed-modules: Distribution.Client.Utils,
Distribution.Client.Utils.LabeledGraph
Distribution.Client.Compat.FilePerms,
Distribution.Client.Compat.Time,
Distribution.Client.ComponentDeps,
Distribution.Client.PackageIndex,
Distribution.Client.PackageUtils,
Distribution.Client.Types

other-extensions: ScopedTypeVariables
default-language: Haskell2010

-- NOTE: when updating build-depends, don't forget to update version regexps
-- in bootstrap.sh.
build-depends: array >= 0.1 && < 0.6,
base >= 4.3 && < 5,
bytestring >= 0.9 && < 1,
Cabal >= 1.22 && < 1.24,
containers >= 0.1 && < 0.6,
filepath >= 1.0 && < 1.5,
time >= 1.1 && < 1.6

if flag(old-directory)
build-depends: directory >= 1 && < 1.2,
old-time >= 1 && < 1.2,
process >= 1.0.1.1 && < 1.1.0.2
else
build-depends: directory >= 1.2 && < 1.3,
process >= 1.1.0.2 && < 1.3

if flag(network-uri)
build-depends: network-uri >= 2.6, network >= 2.6
else
build-depends: network-uri < 2.6, network < 2.6

if os(windows)
build-depends: Win32 >= 2 && < 3
cpp-options: -DWIN32
else
build-depends: unix >= 2.0 && < 2.8
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,6 @@ module Distribution.Client.Dependency (
PackagePreference(..),
InstalledPreference(..),

-- ** Standard policy
standardInstallPolicy,
PackageSpecifier(..),

-- ** Sandbox policy
applySandboxInstallPolicy,

-- ** Extra policy options
dontUpgradeNonUpgradeablePackages,
hideBrokenInstalledPackages,
Expand All @@ -44,6 +37,7 @@ module Distribution.Client.Dependency (

-- ** Policy utils
addConstraints,
addTargets,
addPreferences,
setPreferenceDefault,
setReorderGoals,
Expand All @@ -56,7 +50,8 @@ module Distribution.Client.Dependency (
hideInstalledPackagesSpecificByInstalledPackageId,
hideInstalledPackagesSpecificBySourcePackageId,
hideInstalledPackagesAllVersions,
removeUpperBounds
removeUpperBounds,
basicDepResolverParams
) where

import Distribution.Client.Dependency.TopDown
Expand All @@ -69,8 +64,8 @@ import qualified Distribution.Simple.PackageIndex as InstalledPackageIndex
import qualified Distribution.Client.InstallPlan as InstallPlan
import Distribution.Client.InstallPlan (InstallPlan)
import Distribution.Client.Types
( SourcePackageDb(SourcePackageDb), SourcePackage(..)
, ConfiguredPackage(..), ConfiguredId(..), enableStanzas )
( SourcePackage(..), ConfiguredPackage(..), ConfiguredId(..)
, enableStanzas )
import Distribution.Client.Dependency.Types
( PreSolver(..), Solver(..), DependencyResolver, ResolverPackage(..)
, PackageConstraint(..), showPackageConstraint
Expand All @@ -79,9 +74,6 @@ import Distribution.Client.Dependency.Types
, AllowNewer(..), PackagePreferences(..), InstalledPreference(..)
, PackagesPreferenceDefault(..)
, Progress(..), foldProgress )
import Distribution.Client.Sandbox.Types
( SandboxPackageInfo(..) )
import Distribution.Client.Targets
import Distribution.Client.ComponentDeps (ComponentDeps)
import qualified Distribution.Client.ComponentDeps as CD
import qualified Distribution.InstalledPackageInfo as Installed
Expand All @@ -100,7 +92,7 @@ import Distribution.PackageDescription.Configuration
import Distribution.Client.PackageUtils
( externalBuildDepends )
import Distribution.Version
( VersionRange, anyVersion, thisVersion, withinRange
( VersionRange, anyVersion, withinRange
, removeUpperBound, simplifyVersionRange )
import Distribution.Compiler
( CompilerInfo(..) )
Expand Down Expand Up @@ -438,73 +430,6 @@ reinstallTargets params =
hideInstalledPackagesAllVersions (depResolverTargets params) params


standardInstallPolicy :: InstalledPackageIndex
-> SourcePackageDb
-> [PackageSpecifier SourcePackage]
-> DepResolverParams
standardInstallPolicy
installedPkgIndex (SourcePackageDb sourcePkgIndex sourcePkgPrefs)
pkgSpecifiers

= addPreferences
[ PackageVersionPreference name ver
| (name, ver) <- Map.toList sourcePkgPrefs ]

. addConstraints
(concatMap pkgSpecifierConstraints pkgSpecifiers)

. addTargets
(map pkgSpecifierTarget pkgSpecifiers)

. hideInstalledPackagesSpecificBySourcePackageId
[ packageId pkg | SpecificSourcePackage pkg <- pkgSpecifiers ]

. addSourcePackages
[ pkg | SpecificSourcePackage pkg <- pkgSpecifiers ]

$ basicDepResolverParams
installedPkgIndex sourcePkgIndex

applySandboxInstallPolicy :: SandboxPackageInfo
-> DepResolverParams
-> DepResolverParams
applySandboxInstallPolicy
(SandboxPackageInfo modifiedDeps otherDeps allSandboxPkgs _allDeps)
params

= addPreferences [ PackageInstalledPreference n PreferInstalled
| n <- installedNotModified ]

. addTargets installedNotModified

. addPreferences
[ PackageVersionPreference (packageName pkg)
(thisVersion (packageVersion pkg)) | pkg <- otherDeps ]

. addConstraints
[ let pc = PackageConstraintVersion (packageName pkg)
(thisVersion (packageVersion pkg))
in LabeledPackageConstraint pc ConstraintSourceModifiedAddSourceDep
| pkg <- modifiedDeps ]

. addTargets [ packageName pkg | pkg <- modifiedDeps ]

. hideInstalledPackagesSpecificBySourcePackageId
[ packageId pkg | pkg <- modifiedDeps ]

-- We don't need to add source packages for add-source deps to the
-- 'installedPkgIndex' since 'getSourcePackages' did that for us.

$ params

where
installedPkgIds =
map fst . InstalledPackageIndex.allPackagesBySourcePackageId
$ allSandboxPkgs
modifiedPkgIds = map packageId modifiedDeps
installedNotModified = [ packageName pkg | pkg <- installedPkgIds,
pkg `notElem` modifiedPkgIds ]

-- ------------------------------------------------------------
-- * Interface to the standard resolver
-- ------------------------------------------------------------
Expand Down
30 changes: 30 additions & 0 deletions cabal-install-solver/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
Copyright (c) 2015, FIXME

All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.

* Neither the name of FIXME nor the names of other
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2 changes: 2 additions & 0 deletions cabal-install-solver/Setup.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import Distribution.Simple
main = defaultMain
86 changes: 86 additions & 0 deletions cabal-install-solver/cabal-install-solver.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
name: cabal-install-solver
version: 1.23.0.0
synopsis: Dependency solvers for cabal-install
description: Dependency solvers for cabal-install
homepage: http://www.haskell.org/cabal/
license: BSD3
license-file: LICENSE
author: Lemmih <[email protected]>
Paolo Martini <[email protected]>
Bjorn Bringert <[email protected]>
Isaac Potoczny-Jones <[email protected]>
Duncan Coutts <[email protected]>
maintainer: [email protected]
copyright: 2005 Lemmih <[email protected]>
2006 Paolo Martini <[email protected]>
2007 Bjorn Bringert <[email protected]>
2007 Isaac Potoczny-Jones <[email protected]>
2007-2012 Duncan Coutts <[email protected]>
category: Distribution
build-type: Simple
cabal-version: >=1.10

library
ghc-options: -Wall -fwarn-tabs
exposed-modules: Distribution.Client.Dependency
Distribution.Client.Dependency.Types,
Distribution.Client.Dependency.TopDown,
Distribution.Client.Dependency.Modular,
Distribution.Client.InstallPlan,
Distribution.Client.PlanIndex

other-modules: Distribution.Client.Dependency.TopDown.Types,
Distribution.Client.Dependency.TopDown.Constraints,
Distribution.Client.Dependency.Modular.IndexConversion,
Distribution.Client.Dependency.Modular.Configured,
Distribution.Client.Dependency.Modular.Builder,
Distribution.Client.Dependency.Modular.Dependency,
Distribution.Client.Dependency.Modular.Solver,
Distribution.Client.Dependency.Modular.Explore,
Distribution.Client.Dependency.Modular.Assignment,
Distribution.Client.Dependency.Modular.Flag,
Distribution.Client.Dependency.Modular.Version,
Distribution.Client.Dependency.Modular.Tree,
Distribution.Client.Dependency.Modular.Linking,
Distribution.Client.Dependency.Modular.ConfiguredConversion,
Distribution.Client.Dependency.Modular.PSQ,
Distribution.Client.Dependency.Modular.Message,
Distribution.Client.Dependency.Modular.Log,
Distribution.Client.Dependency.Modular.Package,
Distribution.Client.Dependency.Modular.Index,
Distribution.Client.Dependency.Modular.Preference,
Distribution.Client.Dependency.Modular.Validate

-- NOTE: when updating build-depends, don't forget to update version regexps
-- in bootstrap.sh.
build-depends: array >= 0.1 && <0.6,
base >= 4.3 && <5,
Cabal >= 1.22 && <1.24,
cabal-install-lib >= 1.22 && <1.24,
containers >= 0.1 && <0.6,
mtl >= 2.0 && <2.3,
pretty >= 1 && <1.2

default-language: Haskell2010
other-extensions: CPP, DeriveFunctor, RecordWildCards, DeriveFoldable, DeriveTraversable, GeneralizedNewtypeDeriving

Test-Suite unit-tests
type: exitcode-stdio-1.0
main-is: UnitTests.hs
hs-source-dirs: tests, .
ghc-options: -Wall -fwarn-tabs
other-modules:
UnitTests.Distribution.Client.Dependency.Modular.PSQ
build-depends:
base,
array,
Cabal,
cabal-install-lib,
containers,
mtl,
pretty,
tasty,
tasty-hunit,
tasty-quickcheck,
tagged,
QuickCheck >= 2.5
15 changes: 15 additions & 0 deletions cabal-install-solver/tests/UnitTests.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module Main
where

import Test.Tasty

import qualified UnitTests.Distribution.Client.Dependency.Modular.PSQ

tests :: TestTree
tests = testGroup "Unit Tests" [
testGroup "UnitTests.Distribution.Client.Dependency.Modular.PSQ"
UnitTests.Distribution.Client.Dependency.Modular.PSQ.tests
]

main :: IO ()
main = defaultMainWithIngredients defaultIngredients tests
1 change: 1 addition & 0 deletions cabal-install/Distribution/Client/Configure.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ module Distribution.Client.Configure (
) where

import Distribution.Client.Dependency
import Distribution.Client.Dependency.Policies
import Distribution.Client.Dependency.Types
( AllowNewer(..), isAllowNewer, ConstraintSource(..)
, LabeledPackageConstraint(..) )
Expand Down
Loading