Skip to content

Commit

Permalink
Merge pull request #7347 from fgaz/download-only
Browse files Browse the repository at this point in the history
--only-download flag
  • Loading branch information
emilypi authored Apr 6, 2021
2 parents c93199f + a7c6c01 commit 00a2351
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 7 deletions.
1 change: 1 addition & 0 deletions cabal-install/src/Distribution/Client/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ instance Semigroup SavedConfig where
installDocumentation = combine installDocumentation,
installHaddockIndex = combine installHaddockIndex,
installDryRun = combine installDryRun,
installOnlyDownload = combine installOnlyDownload,
installDest = combine installDest,
installMaxBackjumps = combine installMaxBackjumps,
installReorderGoals = combine installReorderGoals,
Expand Down
10 changes: 8 additions & 2 deletions cabal-install/src/Distribution/Client/ProjectBuilding.hs
Original file line number Diff line number Diff line change
Expand Up @@ -652,8 +652,14 @@ rebuildTarget verbosity
registerLock cacheLock
sharedPackageConfig
plan rpkg@(ReadyPackage pkg)
pkgBuildStatus =

pkgBuildStatus
| buildSettingOnlyDownload buildSettings = do
case pkgBuildStatus of
BuildStatusDownload ->
void $ waitAsyncPackageDownload verbosity downloadMap pkg
_ -> return ()
return $ BuildResult DocsNotTried TestsNotTried Nothing
| otherwise =
-- We rely on the 'BuildStatus' to decide which phase to start from:
case pkgBuildStatus of
BuildStatusDownload -> downloadPhase
Expand Down
2 changes: 2 additions & 0 deletions cabal-install/src/Distribution/Client/ProjectConfig.hs
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ resolveBuildTimeSettings verbosity
where
buildSettingDryRun = fromFlag projectConfigDryRun
buildSettingOnlyDeps = fromFlag projectConfigOnlyDeps
buildSettingOnlyDownload = fromFlag projectConfigOnlyDownload
buildSettingSummaryFile = fromNubList projectConfigSummaryFile
--buildSettingLogFile -- defined below, more complicated
--buildSettingLogVerbosity -- defined below, more complicated
Expand All @@ -328,6 +329,7 @@ resolveBuildTimeSettings verbosity
defaults = mempty {
projectConfigDryRun = toFlag False,
projectConfigOnlyDeps = toFlag False,
projectConfigOnlyDownload = toFlag False,
projectConfigBuildReports = toFlag NoReports,
projectConfigReportPlanningFailure = toFlag False,
projectConfigKeepGoing = toFlag False,
Expand Down
2 changes: 2 additions & 0 deletions cabal-install/src/Distribution/Client/ProjectConfig/Legacy.hs
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,7 @@ convertLegacyBuildOnlyFlags globalFlags configFlags

InstallFlags {
installDryRun = projectConfigDryRun,
installOnlyDownload = projectConfigOnlyDownload,
installOnly = _,
installOnlyDeps = projectConfigOnlyDeps,
installRootCmd = _,
Expand Down Expand Up @@ -612,6 +613,7 @@ convertToLegacySharedConfig
installHaddockIndex = projectConfigHaddockIndex,
installDest = Flag NoCopyDest,
installDryRun = projectConfigDryRun,
installOnlyDownload = projectConfigOnlyDownload,
installReinstall = mempty, --projectConfigReinstall,
installAvoidReinstalls = mempty, --projectConfigAvoidReinstalls,
installOverrideReinstall = mempty, --projectConfigOverrideReinstall,
Expand Down
2 changes: 2 additions & 0 deletions cabal-install/src/Distribution/Client/ProjectConfig/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ data ProjectConfigBuildOnly
projectConfigVerbosity :: Flag Verbosity,
projectConfigDryRun :: Flag Bool,
projectConfigOnlyDeps :: Flag Bool,
projectConfigOnlyDownload :: Flag Bool,
projectConfigSummaryFile :: NubList PathTemplate,
projectConfigLogFile :: Flag PathTemplate,
projectConfigBuildReports :: Flag ReportLevel,
Expand Down Expand Up @@ -436,6 +437,7 @@ data BuildTimeSettings
= BuildTimeSettings {
buildSettingDryRun :: Bool,
buildSettingOnlyDeps :: Bool,
buildSettingOnlyDownload :: Bool,
buildSettingSummaryFile :: [PathTemplate],
buildSettingLogFile :: Maybe (Compiler -> Platform
-> PackageId -> UnitId
Expand Down
7 changes: 7 additions & 0 deletions cabal-install/src/Distribution/Client/Setup.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1623,6 +1623,7 @@ data InstallFlags = InstallFlags {
installHaddockIndex :: Flag PathTemplate,
installDest :: Flag Cabal.CopyDest,
installDryRun :: Flag Bool,
installOnlyDownload :: Flag Bool,
installMaxBackjumps :: Flag Int,
installReorderGoals :: Flag ReorderGoals,
installCountConflicts :: Flag CountConflicts,
Expand Down Expand Up @@ -1665,6 +1666,7 @@ defaultInstallFlags = InstallFlags {
installHaddockIndex = Flag docIndexFile,
installDest = Flag Cabal.NoCopyDest,
installDryRun = Flag False,
installOnlyDownload = Flag False,
installMaxBackjumps = Flag defaultMaxBackjumps,
installReorderGoals = Flag (ReorderGoals False),
installCountConflicts = Flag (CountConflicts True),
Expand Down Expand Up @@ -1878,6 +1880,11 @@ installOptions showOrParseArgs =
installDryRun (\v flags -> flags { installDryRun = v })
trueArg

, option [] ["only-download"]
"Do not build anything, only fetch the packages."
installOnlyDownload (\v flags -> flags { installOnlyDownload = v })
trueArg

, option "" ["target-package-db"]
"package database to install into. Required when using ${pkgroot} prefix."
installDest (\v flags -> flags { installDest = v })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,10 +201,11 @@ prop_roundtrip_printparse_buildonly config =
hackProjectConfigBuildOnly :: ProjectConfigBuildOnly -> ProjectConfigBuildOnly
hackProjectConfigBuildOnly config =
config {
-- These two fields are only command line transitory things, not
-- These fields are only command line transitory things, not
-- something to be recorded persistently in a config file
projectConfigOnlyDeps = mempty,
projectConfigDryRun = mempty
projectConfigOnlyDeps = mempty,
projectConfigOnlyDownload = mempty,
projectConfigDryRun = mempty
}

prop_roundtrip_printparse_shared :: ProjectConfigShared -> Property
Expand Down Expand Up @@ -377,6 +378,7 @@ instance Arbitrary ProjectConfigBuildOnly where
<$> arbitrary
<*> arbitrary
<*> arbitrary
<*> arbitrary
<*> (toNubList <$> shortListOf 2 arbitrary)
<*> arbitrary
<*> arbitrary
Expand All @@ -398,6 +400,7 @@ instance Arbitrary ProjectConfigBuildOnly where
shrink ProjectConfigBuildOnly { projectConfigVerbosity = x00
, projectConfigDryRun = x01
, projectConfigOnlyDeps = x02
, projectConfigOnlyDownload = x18
, projectConfigSummaryFile = x03
, projectConfigLogFile = x04
, projectConfigBuildReports = x05
Expand All @@ -416,6 +419,7 @@ instance Arbitrary ProjectConfigBuildOnly where
[ ProjectConfigBuildOnly { projectConfigVerbosity = x00'
, projectConfigDryRun = x01'
, projectConfigOnlyDeps = x02'
, projectConfigOnlyDownload = x18'
, projectConfigSummaryFile = x03'
, projectConfigLogFile = x04'
, projectConfigBuildReports = x05'
Expand All @@ -434,12 +438,12 @@ instance Arbitrary ProjectConfigBuildOnly where
| ((x00', x01', x02', x03', x04'),
(x05', x06', x07', x08', x09'),
(x10', x11', x12', x14'),
( x17' ))
( x17', x18' ))
<- shrink
((x00, x01, x02, x03, x04),
(x05, x06, x07, x08, preShrink_NumJobs x09),
(x10, x11, x12, x14),
( x17 ))
( x17, x18 ))
]
where
preShrink_NumJobs = fmap (fmap Positive)
Expand Down
4 changes: 4 additions & 0 deletions changelog.d/only-download
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
synopsis: Add a --only-download flag
packages: cabal-install
prs: #7347
issues: #7323
25 changes: 25 additions & 0 deletions doc/cabal-project.rst
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,31 @@ package, and thus apply globally:

Specifies the name of the directory of the global package store.

Phase control
-------------

The following settings apply to commands that result in build actions
(``build``, ``run``, ``repl``, ``test``...), and control which phases of the
build are executed.

.. option:: --dry-run

Do not download, build, or install anything, only print what would happen.

.. option:: --only-configure

Instead of performing a full build just run the configure step.
Only accepted by the ``build`` command.

.. option:: --only-download

Do not build anything, only fetch the packages.

.. option:: --only-dependencies

Install only the dependencies necessary to build the given packages.
Not accepted by the ``repl`` command.

Solver configuration options
----------------------------

Expand Down

0 comments on commit 00a2351

Please sign in to comment.