From 8ca987a99eb3ab3ebc5386f6e05106bb84d98b76 Mon Sep 17 00:00:00 2001 From: Francesco Gazzetta Date: Fri, 2 Apr 2021 21:26:32 +0200 Subject: [PATCH 1/3] Add --download-only flag --- cabal-install/src/Distribution/Client/Config.hs | 1 + .../src/Distribution/Client/ProjectBuilding.hs | 10 ++++++++-- .../src/Distribution/Client/ProjectConfig.hs | 2 ++ .../Distribution/Client/ProjectConfig/Legacy.hs | 2 ++ .../src/Distribution/Client/ProjectConfig/Types.hs | 2 ++ cabal-install/src/Distribution/Client/Setup.hs | 7 +++++++ .../UnitTests/Distribution/Client/ProjectConfig.hs | 14 +++++++++----- 7 files changed, 31 insertions(+), 7 deletions(-) diff --git a/cabal-install/src/Distribution/Client/Config.hs b/cabal-install/src/Distribution/Client/Config.hs index d5baa12629f..e7277535587 100644 --- a/cabal-install/src/Distribution/Client/Config.hs +++ b/cabal-install/src/Distribution/Client/Config.hs @@ -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, diff --git a/cabal-install/src/Distribution/Client/ProjectBuilding.hs b/cabal-install/src/Distribution/Client/ProjectBuilding.hs index 134e2249999..e2e0f3120dd 100644 --- a/cabal-install/src/Distribution/Client/ProjectBuilding.hs +++ b/cabal-install/src/Distribution/Client/ProjectBuilding.hs @@ -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 diff --git a/cabal-install/src/Distribution/Client/ProjectConfig.hs b/cabal-install/src/Distribution/Client/ProjectConfig.hs index e26d53743f5..9eaacd05146 100644 --- a/cabal-install/src/Distribution/Client/ProjectConfig.hs +++ b/cabal-install/src/Distribution/Client/ProjectConfig.hs @@ -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 @@ -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, diff --git a/cabal-install/src/Distribution/Client/ProjectConfig/Legacy.hs b/cabal-install/src/Distribution/Client/ProjectConfig/Legacy.hs index d0ef105bb8f..07f37937524 100644 --- a/cabal-install/src/Distribution/Client/ProjectConfig/Legacy.hs +++ b/cabal-install/src/Distribution/Client/ProjectConfig/Legacy.hs @@ -509,6 +509,7 @@ convertLegacyBuildOnlyFlags globalFlags configFlags InstallFlags { installDryRun = projectConfigDryRun, + installOnlyDownload = projectConfigOnlyDownload, installOnly = _, installOnlyDeps = projectConfigOnlyDeps, installRootCmd = _, @@ -612,6 +613,7 @@ convertToLegacySharedConfig installHaddockIndex = projectConfigHaddockIndex, installDest = Flag NoCopyDest, installDryRun = projectConfigDryRun, + installOnlyDownload = projectConfigOnlyDownload, installReinstall = mempty, --projectConfigReinstall, installAvoidReinstalls = mempty, --projectConfigAvoidReinstalls, installOverrideReinstall = mempty, --projectConfigOverrideReinstall, diff --git a/cabal-install/src/Distribution/Client/ProjectConfig/Types.hs b/cabal-install/src/Distribution/Client/ProjectConfig/Types.hs index aca458f6032..aaa25df9eaa 100644 --- a/cabal-install/src/Distribution/Client/ProjectConfig/Types.hs +++ b/cabal-install/src/Distribution/Client/ProjectConfig/Types.hs @@ -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, @@ -436,6 +437,7 @@ data BuildTimeSettings = BuildTimeSettings { buildSettingDryRun :: Bool, buildSettingOnlyDeps :: Bool, + buildSettingOnlyDownload :: Bool, buildSettingSummaryFile :: [PathTemplate], buildSettingLogFile :: Maybe (Compiler -> Platform -> PackageId -> UnitId diff --git a/cabal-install/src/Distribution/Client/Setup.hs b/cabal-install/src/Distribution/Client/Setup.hs index 7d8daa19eb4..59a04be4738 100644 --- a/cabal-install/src/Distribution/Client/Setup.hs +++ b/cabal-install/src/Distribution/Client/Setup.hs @@ -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, @@ -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), @@ -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 }) diff --git a/cabal-install/tests/UnitTests/Distribution/Client/ProjectConfig.hs b/cabal-install/tests/UnitTests/Distribution/Client/ProjectConfig.hs index e85f348cd2a..3681ac1d900 100644 --- a/cabal-install/tests/UnitTests/Distribution/Client/ProjectConfig.hs +++ b/cabal-install/tests/UnitTests/Distribution/Client/ProjectConfig.hs @@ -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 @@ -377,6 +378,7 @@ instance Arbitrary ProjectConfigBuildOnly where <$> arbitrary <*> arbitrary <*> arbitrary + <*> arbitrary <*> (toNubList <$> shortListOf 2 arbitrary) <*> arbitrary <*> arbitrary @@ -398,6 +400,7 @@ instance Arbitrary ProjectConfigBuildOnly where shrink ProjectConfigBuildOnly { projectConfigVerbosity = x00 , projectConfigDryRun = x01 , projectConfigOnlyDeps = x02 + , projectConfigOnlyDownload = x18 , projectConfigSummaryFile = x03 , projectConfigLogFile = x04 , projectConfigBuildReports = x05 @@ -416,6 +419,7 @@ instance Arbitrary ProjectConfigBuildOnly where [ ProjectConfigBuildOnly { projectConfigVerbosity = x00' , projectConfigDryRun = x01' , projectConfigOnlyDeps = x02' + , projectConfigOnlyDownload = x18' , projectConfigSummaryFile = x03' , projectConfigLogFile = x04' , projectConfigBuildReports = x05' @@ -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) From d71d8aa637684066b987988e7aaf241c808cf62e Mon Sep 17 00:00:00 2001 From: Francesco Gazzetta Date: Fri, 2 Apr 2021 21:28:40 +0200 Subject: [PATCH 2/3] Changelog entry for --download-only --- changelog.d/only-download | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 changelog.d/only-download diff --git a/changelog.d/only-download b/changelog.d/only-download new file mode 100644 index 00000000000..955c3a1afbd --- /dev/null +++ b/changelog.d/only-download @@ -0,0 +1,4 @@ +synopsis: Add a --only-download flag +packages: cabal-install +prs: #7347 +issues: #7323 From a7c6c018faa7cdf47470526a02f24ee24f5c5540 Mon Sep 17 00:00:00 2001 From: Francesco Gazzetta Date: Sat, 3 Apr 2021 12:37:36 +0200 Subject: [PATCH 3/3] Document phase control flags --dry-run --only-dependencies --only-configure --only-download --- doc/cabal-project.rst | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/doc/cabal-project.rst b/doc/cabal-project.rst index 6e33de68d5f..c4d47e7690c 100644 --- a/doc/cabal-project.rst +++ b/doc/cabal-project.rst @@ -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 ----------------------------