Skip to content

Commit

Permalink
Add package-db flag for v2 commands
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickdoc committed Sep 22, 2021
1 parent 3b7655f commit c5b589c
Show file tree
Hide file tree
Showing 21 changed files with 176 additions and 8 deletions.
4 changes: 2 additions & 2 deletions cabal-install/src/Distribution/Client/ProjectConfig/Legacy.hs
Original file line number Diff line number Diff line change
Expand Up @@ -352,11 +352,11 @@ convertLegacyAllPackageFlags globalFlags configFlags configExFlags installFlags
configDistPref = projectConfigDistDir,
configHcFlavor = projectConfigHcFlavor,
configHcPath = projectConfigHcPath,
configHcPkg = projectConfigHcPkg
configHcPkg = projectConfigHcPkg,
--configProgramPathExtra = projectConfigProgPathExtra DELETE ME
--configInstallDirs = projectConfigInstallDirs,
--configUserInstall = projectConfigUserInstall,
--configPackageDBs = projectConfigPackageDBs,
configPackageDBs = projectConfigPackageDBs
} = configFlags

ConfigExFlags {
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 @@ -56,7 +56,7 @@ import Distribution.System
import Distribution.PackageDescription
( FlagAssignment )
import Distribution.Simple.Compiler
( Compiler, CompilerFlavor
( Compiler, CompilerFlavor, PackageDB
, OptimisationLevel(..), ProfDetailLevel, DebugInfoLevel(..) )
import Distribution.Simple.Setup
( Flag, HaddockTarget(..), TestShowDetails(..), DumpBuildInfo (..) )
Expand Down Expand Up @@ -176,7 +176,7 @@ data ProjectConfigShared
--projectConfigInstallDirs :: InstallDirs (Flag PathTemplate),
--TODO: [required eventually] decide what to do with InstallDirs
-- currently we don't allow it to be specified in the config file
--projectConfigPackageDBs :: [Maybe PackageDB],
projectConfigPackageDBs :: [Maybe PackageDB],

-- configuration used both by the solver and other phases
projectConfigRemoteRepos :: NubList RemoteRepo, -- ^ Available Hackage servers.
Expand Down
17 changes: 13 additions & 4 deletions cabal-install/src/Distribution/Client/ProjectPlanning.hs
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,9 @@ rebuildInstallPlan verbosity
die' verbosity msg
Right plan -> return (plan, pkgConfigDB, tis, ar)
where
corePackageDbs = [GlobalPackageDB]
corePackageDbs = applyPackageDbFlags [GlobalPackageDB]
(projectConfigPackageDBs projectConfigShared)

withRepoCtx = projectConfigWithSolverRepoContext verbosity
projectConfigShared
projectConfigBuildOnly
Expand Down Expand Up @@ -983,6 +985,12 @@ getPackageSourceHashes verbosity withRepoCtx solverPlan = do
return $! hashesFromRepoMetadata
<> hashesFromTarballFiles

-- | Append the given package databases to an existing PackageDBStack.
-- A @Nothing@ entry will clear everything before it.
applyPackageDbFlags :: PackageDBStack -> [Maybe PackageDB] -> PackageDBStack
applyPackageDbFlags dbs' [] = dbs'
applyPackageDbFlags _ (Nothing:dbs) = applyPackageDbFlags [] dbs
applyPackageDbFlags dbs' (Just db:dbs) = applyPackageDbFlags (dbs' ++ [db]) dbs

-- ------------------------------------------------------------
-- * Installation planning
Expand Down Expand Up @@ -1858,7 +1866,7 @@ elaborateInstallPlan verbosity platform compiler compilerprogdb pkgConfigDB

buildAndRegisterDbs
| shouldBuildInplaceOnly pkg = inplacePackageDbs
| otherwise = storePackageDbs
| otherwise = corePackageDbs

elabPkgDescriptionOverride = descOverride

Expand Down Expand Up @@ -1971,10 +1979,11 @@ elaborateInstallPlan verbosity platform compiler compilerprogdb pkgConfigDB
= mempty
perpkg = maybe mempty f (Map.lookup (packageName pkg) perPackageConfig)

inplacePackageDbs = storePackageDbs
inplacePackageDbs = corePackageDbs
++ [ distPackageDB (compilerId compiler) ]

storePackageDbs = storePackageDBStack (compilerId compiler)
corePackageDbs = applyPackageDbFlags (storePackageDBStack (compilerId compiler))
(projectConfigPackageDBs sharedPackageConfig)

-- For this local build policy, every package that lives in a local source
-- dir (as opposed to a tarball), or depends on such a package, will be
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,7 @@ instance Arbitrary ProjectConfigShared where
projectConfigHcPath <- arbitraryFlag arbitraryShortToken
projectConfigHcPkg <- arbitraryFlag arbitraryShortToken
projectConfigHaddockIndex <- arbitrary
projectConfigPackageDBs <- arbitrary
projectConfigRemoteRepos <- arbitrary
projectConfigLocalNoIndexRepos <- arbitrary
projectConfigActiveRepos <- arbitrary
Expand Down Expand Up @@ -497,6 +498,7 @@ instance Arbitrary ProjectConfigShared where
<*> shrinkerAla (fmap NonEmpty) projectConfigHcPath
<*> shrinkerAla (fmap NonEmpty) projectConfigHcPkg
<*> shrinker projectConfigHaddockIndex
<*> shrinker projectConfigPackageDBs
<*> shrinker projectConfigRemoteRepos
<*> shrinker projectConfigLocalNoIndexRepos
<*> shrinker projectConfigActiveRepos
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import Distribution.Client.Types
import Distribution.Client.Types.OverwritePolicy (OverwritePolicy)
import Distribution.Client.Types.SourceRepo (SourceRepositoryPackage)

import Distribution.Simple.Compiler (PackageDB)

import Data.TreeDiff.Class
import Data.TreeDiff.Instances.Cabal ()
import Network.URI
Expand Down Expand Up @@ -50,6 +52,7 @@ instance ToExpr OptionalStanza
instance ToExpr Outcome
instance ToExpr OverwritePolicy
instance ToExpr PackageConfig
instance ToExpr PackageDB
instance ToExpr PackageProperty
instance ToExpr PreSolver
instance ToExpr ProjectConfig
Expand Down
16 changes: 16 additions & 0 deletions cabal-testsuite/PackageTests/PackageDB/cabal-fail-no-base.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Setup configure
Configuring p-1.0...
# Setup build
Preprocessing library for p-1.0..
Building library for p-1.0..
# Setup copy
Installing library in <PATH>
# Setup register
Registering library for p-1.0..
# cabal v2-build
Resolving dependencies...
cabal: Could not resolve dependencies:
[__0] trying: q-1.0 (user goal)
[__1] unknown package: base (dependency of q)
[__1] fail (backjumping, conflict set: base, q)
After searching the rest of the dependency tree exhaustively, these were the goals I've had most trouble fulfilling: q (2), base (1)
12 changes: 12 additions & 0 deletions cabal-testsuite/PackageTests/PackageDB/cabal-fail-no-base.test.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import Test.Cabal.Prelude
main = cabalTest $ do
withPackageDb $ do
withDirectory "p" $
setup_install []

env <- getTestEnv
let pkgDbPath = testPackageDbDir env

withDirectory "q" $ do
res <- fails $ cabal' "v2-build" ["--package-db=clear", "--package-db=" ++ pkgDbPath]
assertOutputContains "unknown package: base" res
16 changes: 16 additions & 0 deletions cabal-testsuite/PackageTests/PackageDB/cabal-fail-no-p.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Setup configure
Configuring p-1.0...
# Setup build
Preprocessing library for p-1.0..
Building library for p-1.0..
# Setup copy
Installing library in <PATH>
# Setup register
Registering library for p-1.0..
# cabal v2-build
Resolving dependencies...
cabal: Could not resolve dependencies:
[__0] trying: q-1.0 (user goal)
[__1] unknown package: p (dependency of q)
[__1] fail (backjumping, conflict set: p, q)
After searching the rest of the dependency tree exhaustively, these were the goals I've had most trouble fulfilling: q (2), p (1)
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Test.Cabal.Prelude
main = cabalTest $ do
withPackageDb $ do
withDirectory "p" $
setup_install []

withDirectory "q" $ do
res <- fails $ cabal' "v2-build" []
assertOutputContains "unknown package: p" res
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Setup configure
Configuring p-1.0...
# Setup build
Preprocessing library for p-1.0..
Building library for p-1.0..
# Setup copy
Installing library in <PATH>
# Setup register
Registering library for p-1.0..
# cabal v2-build
cabal: No package databases have been specified. If you use --package-db=clear, you must follow it with --package-db= with 'global', 'user' or a specific file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Test.Cabal.Prelude
main = cabalTest $ do
withPackageDb $ do
withDirectory "p" $
setup_install []

withDirectory "q" $ do
res <- fails $ cabal' "v2-build" ["--package-db=clear"]
assertOutputContains "No package databases have been specified." res
17 changes: 17 additions & 0 deletions cabal-testsuite/PackageTests/PackageDB/cabal-manual-packagedb.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Setup configure
Configuring p-1.0...
# Setup build
Preprocessing library for p-1.0..
Building library for p-1.0..
# Setup copy
Installing library in <PATH>
# Setup register
Registering library for p-1.0..
# cabal v2-build
Resolving dependencies...
Build profile: -w ghc-<GHCVER> -O1
In order, the following will be built:
- q-1.0 (exe:q) (first run)
Configuring executable 'q' for q-1.0..
Preprocessing executable 'q' for q-1.0..
Building executable 'q' for q-1.0..
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import Test.Cabal.Prelude
main = cabalTest $ do
withPackageDb $ do
withDirectory "p" $
setup_install []

env <- getTestEnv
let pkgDbPath = testPackageDbDir env
withDirectory "q" $
cabal "v2-build" [ "--package-db=clear"
, "--package-db=global"
, "--package-db=" ++ pkgDbPath]
17 changes: 17 additions & 0 deletions cabal-testsuite/PackageTests/PackageDB/cabal-packagedb.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Setup configure
Configuring p-1.0...
# Setup build
Preprocessing library for p-1.0..
Building library for p-1.0..
# Setup copy
Installing library in <PATH>
# Setup register
Registering library for p-1.0..
# cabal v2-build
Resolving dependencies...
Build profile: -w ghc-<GHCVER> -O1
In order, the following will be built:
- q-1.0 (exe:q) (first run)
Configuring executable 'q' for q-1.0..
Preprocessing executable 'q' for q-1.0..
Building executable 'q' for q-1.0..
10 changes: 10 additions & 0 deletions cabal-testsuite/PackageTests/PackageDB/cabal-packagedb.test.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import Test.Cabal.Prelude
main = cabalTest $ do
withPackageDb $ do
withDirectory "p" $
setup_install []

env <- getTestEnv
let pkgDbPath = testPackageDbDir env
withDirectory "q" $
cabal "v2-build" ["--package-db=" ++ pkgDbPath]
2 changes: 2 additions & 0 deletions cabal-testsuite/PackageTests/PackageDB/p/P.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module P where
p = True
1 change: 1 addition & 0 deletions cabal-testsuite/PackageTests/PackageDB/p/cabal.project
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
packages: .
9 changes: 9 additions & 0 deletions cabal-testsuite/PackageTests/PackageDB/p/p.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name: p
version: 1.0
build-type: Simple
cabal-version: >= 1.10

library
build-depends: base
exposed-modules: P
default-language: Haskell2010
3 changes: 3 additions & 0 deletions cabal-testsuite/PackageTests/PackageDB/q/Main.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module Main where
import P
main = print p
1 change: 1 addition & 0 deletions cabal-testsuite/PackageTests/PackageDB/q/cabal.project
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
packages: .
9 changes: 9 additions & 0 deletions cabal-testsuite/PackageTests/PackageDB/q/q.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name: q
version: 1.0
build-type: Simple
cabal-version: >= 1.10

executable q
build-depends: base, p
main-is: Main.hs
default-language: Haskell2010

0 comments on commit c5b589c

Please sign in to comment.