1 ------------------------------------------------------------------------------- |
2 -- Module : Distribution.Client.Fetch
3 -- Copyright : (c) David Himmelstrup 2005
7 -- Maintainer : cabal-devel@gmail.com
8 -- Stability : provisional
9 -- Portability : portable
11 -- The cabal fetch command
12 -----------------------------------------------------------------------------
13 module Distribution
.Client
.Fetch
17 import Distribution
.Client
.Compat
.Prelude
20 import Distribution
.Client
.Dependency
21 import Distribution
.Client
.FetchUtils
hiding (fetchPackage
)
22 import Distribution
.Client
.IndexUtils
as IndexUtils
23 ( getInstalledPackages
26 import Distribution
.Client
.Setup
31 import qualified Distribution
.Client
.SolverInstallPlan
as SolverInstallPlan
32 import Distribution
.Client
.Targets
33 import Distribution
.Client
.Types
35 import Distribution
.Solver
.Types
.ConstraintSource
36 import Distribution
.Solver
.Types
.LabeledPackageConstraint
37 import Distribution
.Solver
.Types
.OptionalStanza
38 import Distribution
.Solver
.Types
.PkgConfigDb
(PkgConfigDb
, readPkgConfigDb
)
39 import Distribution
.Solver
.Types
.SolverPackage
40 import Distribution
.Solver
.Types
.SourcePackage
42 import Distribution
.Client
.Errors
43 import Distribution
.Package
46 import Distribution
.Simple
.Compiler
51 import Distribution
.Simple
.PackageIndex
(InstalledPackageIndex
)
52 import Distribution
.Simple
.Program
55 import Distribution
.Simple
.Setup
59 import Distribution
.Simple
.Utils
64 import Distribution
.System
68 -- ------------------------------------------------------------
70 -- * The fetch command
72 -- ------------------------------------------------------------
76 -- * add fetch -o support
78 -- * support tarball URLs via ad-hoc download cache (or in -o mode?)
80 -- * suggest using --no-deps, unpack or fetch -o if deps cannot be satisfied
82 -- * Port various flags from install:
84 -- * --upgrade-dependencies
85 -- * --constraint and --preference
86 -- * --only-dependencies, but note it conflicts with --no-deps
88 -- | Fetch a list of packages and their dependencies.
100 fetch verbosity _ _ _ _ _ _ _
[] =
101 notice verbosity
"No packages requested. Nothing to do."
112 traverse_
(checkTarget verbosity
) userTargets
114 installedPkgIndex
<- getInstalledPackages verbosity comp packageDBs progdb
115 sourcePkgDb
<- getSourcePackages verbosity repoCtxt
116 pkgConfigDb
<- readPkgConfigDb verbosity progdb
122 (packageIndex sourcePkgDb
)
136 pkgs
' <- filterM (fmap not . isFetched
. srcpkgSource
) pkgs
138 then -- TODO: when we add support for remote tarballs then this message
139 -- will need to be changed because for remote tarballs we fetch them
140 -- at the earlier phase.
143 "No packages need to be fetched. "
144 ++ "All the requested packages are already local "
145 ++ "or cached locally."
151 "The following packages would be fetched:"
152 : map (prettyShow
. packageId
) pkgs
'
153 else traverse_
(fetchPackage verbosity repoCtxt
. srcpkgSource
) pkgs
'
155 dryRun
= fromFlag
(fetchDryRun fetchFlags
)
162 -> InstalledPackageIndex
165 -> [PackageSpecifier UnresolvedSourcePackage
]
166 -> IO [UnresolvedSourcePackage
]
176 | includeDependencies
= do
177 notice verbosity
"Resolving dependencies..."
179 foldProgress logMsg
(dieWithException verbosity
. PlanPackages
. show) return $
186 -- The packages we want to fetch are those packages the 'InstallPlan'
187 -- that are in the 'InstallPlan.Configured' state.
189 [ solverPkgSource cpkg
190 |
(SolverInstallPlan
.Configured cpkg
) <-
191 SolverInstallPlan
.toList installPlan
194 either (dieWithException verbosity
. PlanPackages
. unlines . map show) return $
195 resolveWithoutDependencies resolverParams
197 resolverParams
:: DepResolverParams
200 ( if maxBackjumps
< 0
202 else Just maxBackjumps
204 . setIndependentGoals independentGoals
205 . setReorderGoals reorderGoals
206 . setCountConflicts countConflicts
207 . setFineGrainedConflicts fineGrainedConflicts
208 . setMinimizeConflictSet minimizeConflictSet
209 . setShadowPkgs shadowPkgs
210 . setStrongFlags strongFlags
211 . setAllowBootLibInstalls allowBootLibInstalls
212 . setOnlyConstrained onlyConstrained
213 . setSolverVerbosity verbosity
217 (scopeToplevel
$ pkgSpecifierTarget pkgSpecifier
)
218 (PackagePropertyStanzas stanzas
)
219 in LabeledPackageConstraint pc ConstraintSourceConfigFlagOrTarget
220 | pkgSpecifier
<- pkgSpecifiers
222 -- Reinstall the targets given on the command line so that the dep
223 -- resolver will decide that they need fetching, even if they're
224 -- already installed. Since we want to get the source packages of
225 -- things we might have installed (but not have the sources for).
227 $ standardInstallPolicy installedPkgIndex sourcePkgDb pkgSpecifiers
229 includeDependencies
= fromFlag
(fetchDeps fetchFlags
)
230 logMsg message rest
= debug verbosity message
>> rest
233 [TestStanzas | testsEnabled
]
234 ++ [BenchStanzas | benchmarksEnabled
]
235 testsEnabled
= fromFlagOrDefault
False $ fetchTests fetchFlags
236 benchmarksEnabled
= fromFlagOrDefault
False $ fetchBenchmarks fetchFlags
238 reorderGoals
= fromFlag
(fetchReorderGoals fetchFlags
)
239 countConflicts
= fromFlag
(fetchCountConflicts fetchFlags
)
240 fineGrainedConflicts
= fromFlag
(fetchFineGrainedConflicts fetchFlags
)
241 minimizeConflictSet
= fromFlag
(fetchMinimizeConflictSet fetchFlags
)
242 independentGoals
= fromFlag
(fetchIndependentGoals fetchFlags
)
243 shadowPkgs
= fromFlag
(fetchShadowPkgs fetchFlags
)
244 strongFlags
= fromFlag
(fetchStrongFlags fetchFlags
)
245 maxBackjumps
= fromFlag
(fetchMaxBackjumps fetchFlags
)
246 allowBootLibInstalls
= fromFlag
(fetchAllowBootLibInstalls fetchFlags
)
247 onlyConstrained
= fromFlag
(fetchOnlyConstrained fetchFlags
)
249 checkTarget
:: Verbosity
-> UserTarget
-> IO ()
250 checkTarget verbosity target
= case target
of
251 UserTargetRemoteTarball _uri
->
252 dieWithException verbosity CheckTarget
255 fetchPackage
:: Verbosity
-> RepoContext
-> PackageLocation a
-> IO ()
256 fetchPackage verbosity repoCtxt pkgsrc
= case pkgsrc
of
257 LocalUnpackedPackage _dir
-> return ()
258 LocalTarballPackage _file
-> return ()
259 RemoteTarballPackage _uri _
->
260 dieWithException verbosity CheckTarget
261 RemoteSourceRepoPackage _repo _
->
262 dieWithException verbosity FetchPackage
263 RepoTarballPackage repo pkgid _
-> do
264 _
<- fetchRepoTarball verbosity repoCtxt repo pkgid