diff --git a/cabal-install/src/Distribution/Client/CmdConfigure.hs b/cabal-install/src/Distribution/Client/CmdConfigure.hs index 1c9eea81b85..b830b95149f 100644 --- a/cabal-install/src/Distribution/Client/CmdConfigure.hs +++ b/cabal-install/src/Distribution/Client/CmdConfigure.hs @@ -15,7 +15,7 @@ import qualified Data.Map as Map import Distribution.Client.ProjectOrchestration import Distribution.Client.ProjectConfig - ( writeProjectLocalExtraConfig ) + ( showProjectConfig, writeProjectLocalExtraConfig ) import Distribution.Client.NixStyleOptions ( NixStyleFlags (..), nixStyleOptions, defaultNixStyleFlags ) @@ -107,17 +107,24 @@ configureAction flags@NixStyleFlags {..} _extraArgs globalFlags = do if exists then firstFreeBackup' (i + 1) else return backup - - -- If cabal.project.local already exists, back up to cabal.project.local~[n] - exists <- doesFileExist localFile - when exists $ do - backup <- firstFreeBackup - notice verbosity $ - quote (takeFileName localFile) <> " already exists, backing it up to " - <> quote (takeFileName backup) <> "." - copyFile localFile backup - writeProjectLocalExtraConfig (distDirLayout baseCtx) - cliConfig + dryRun = buildSettingDryRun $ buildSettings baseCtx + + if dryRun + then notice verbosity $ unlines + [ "Would write the following configuration file:" + , showProjectConfig cliConfig + ] + else do + -- If cabal.project.local already exists, back up to cabal.project.local~[n] + exists <- doesFileExist localFile + when exists $ do + backup <- firstFreeBackup + notice verbosity $ + quote (takeFileName localFile) <> " already exists, backing it up to " + <> quote (takeFileName backup) <> "." + copyFile localFile backup + writeProjectLocalExtraConfig (distDirLayout baseCtx) + cliConfig buildCtx <- runProjectPreBuildPhase verbosity baseCtx $ \elaboratedPlan -> diff --git a/cabal-install/src/Distribution/Client/CmdExec.hs b/cabal-install/src/Distribution/Client/CmdExec.hs index 1d47222bc9a..247870532eb 100644 --- a/cabal-install/src/Distribution/Client/CmdExec.hs +++ b/cabal-install/src/Distribution/Client/CmdExec.hs @@ -35,6 +35,7 @@ import Distribution.Client.ProjectOrchestration , distDirLayout , commandLineFlagsToProjectConfig , ProjectBaseContext(..) + , buildSettingDryRun ) import Distribution.Client.ProjectPlanOutput ( updatePostBuildProjectStatus @@ -81,6 +82,7 @@ import Distribution.Simple.Utils , createDirectoryIfMissingVerbose , withTempDirectory , wrapText + , notice ) import Distribution.Verbosity ( normal @@ -91,6 +93,9 @@ import Distribution.Client.Compat.Prelude import qualified Data.Set as S import qualified Data.Map as M +import System.Process + ( showCommandForUser + ) execCommand :: CommandUI (NixStyleFlags ()) execCommand = CommandUI @@ -185,7 +190,14 @@ execAction flags@NixStyleFlags {..} extraArgs globalFlags = do argOverrides' program invocation = programInvocation program' args - runProgramInvocation verbosity invocation + dryRun = buildSettingDryRun $ buildSettings baseCtx + + if dryRun + then notice verbosity $ unlines + [ "Would have executed the following:" + , showCommandForUser (programPath program') args + ] + else runProgramInvocation verbosity invocation where verbosity = fromFlagOrDefault normal (configVerbosity configFlags) cliConfig = commandLineFlagsToProjectConfig globalFlags flags diff --git a/cabal-install/src/Distribution/Client/CmdFreeze.hs b/cabal-install/src/Distribution/Client/CmdFreeze.hs index c555daf5030..653b846b9db 100644 --- a/cabal-install/src/Distribution/Client/CmdFreeze.hs +++ b/cabal-install/src/Distribution/Client/CmdFreeze.hs @@ -16,7 +16,7 @@ import Distribution.Client.ProjectOrchestration import Distribution.Client.ProjectPlanning import Distribution.Client.ProjectConfig ( ProjectConfig(..), ProjectConfigShared(..) - , writeProjectLocalFreezeConfig ) + , showProjectConfig, writeProjectLocalFreezeConfig ) import Distribution.Client.IndexUtils (TotalIndexState, ActiveRepos, filterSkippedActiveRepos) import Distribution.Client.Targets ( UserQualifier(..), UserConstraintScope(..), UserConstraint(..) ) @@ -106,7 +106,8 @@ freezeAction flags@NixStyleFlags {..} extraArgs globalFlags = do distDirLayout, cabalDirLayout, projectConfig, - localPackages + localPackages, + buildSettings } <- establishProjectBaseContext verbosity cliConfig OtherCommand (_, elaboratedPlan, _, totalIndexState, activeRepos) <- @@ -116,9 +117,18 @@ freezeAction flags@NixStyleFlags {..} extraArgs globalFlags = do localPackages let freezeConfig = projectFreezeConfig elaboratedPlan totalIndexState activeRepos - writeProjectLocalFreezeConfig distDirLayout freezeConfig - notice verbosity $ - "Wrote freeze file: " ++ distProjectFile distDirLayout "freeze" + dryRun = buildSettingDryRun buildSettings + + if dryRun + then do + notice verbosity $ unlines + [ "Would have written the following freeze file:" + , showProjectConfig freezeConfig + ] + else do + writeProjectLocalFreezeConfig distDirLayout freezeConfig + notice verbosity $ + "Wrote freeze file: " ++ distProjectFile distDirLayout "freeze" where verbosity = fromFlagOrDefault normal (configVerbosity configFlags) diff --git a/cabal-install/src/Distribution/Client/CmdRun.hs b/cabal-install/src/Distribution/Client/CmdRun.hs index 5ff899ce4c1..1e3b68187b8 100644 --- a/cabal-install/src/Distribution/Client/CmdRun.hs +++ b/cabal-install/src/Distribution/Client/CmdRun.hs @@ -46,7 +46,7 @@ import Distribution.CabalSpecVersion (CabalSpecVersion (..), cabalSpecLatest) import Distribution.Verbosity ( normal ) import Distribution.Simple.Utils - ( wrapText, warn, die', ordNub, info + ( wrapText, warn, die', ordNub, info, notice , createTempDirectory, handleDoesNotExist ) import Distribution.Client.ProjectConfig ( ProjectConfig(..), ProjectConfigShared(..) @@ -108,6 +108,8 @@ import System.Directory ( getTemporaryDirectory, removeDirectoryRecursive, doesFileExist ) import System.FilePath ( (), isValid, isPathSeparator, takeExtension ) +import System.Process + ( showCommandForUser ) runCommand :: CommandUI (NixStyleFlags ()) @@ -284,15 +286,24 @@ runAction flags@NixStyleFlags {..} targetStrings globalFlags = do exeName exeName let args = drop 1 targetStrings - runProgramInvocation - verbosity - emptyProgramInvocation { - progInvokePath = exePath, - progInvokeArgs = args, - progInvokeEnv = dataDirsEnvironmentForPlan - (distDirLayout baseCtx) - elaboratedPlan - } + dryRun = buildSettingDryRun $ buildSettings baseCtx + + if dryRun + then notice verbosity $ unlines + [ "Would have run the following:" + , showCommandForUser exePath args + ] + else + unless dryRun $ + runProgramInvocation + verbosity + emptyProgramInvocation { + progInvokePath = exePath, + progInvokeArgs = args, + progInvokeEnv = dataDirsEnvironmentForPlan + (distDirLayout baseCtx) + elaboratedPlan + } handleDoesNotExist () (removeDirectoryRecursive tmpDir) where diff --git a/cabal-install/src/Distribution/Client/ProjectConfig.hs b/cabal-install/src/Distribution/Client/ProjectConfig.hs index 9eaacd05146..f943cd481df 100644 --- a/cabal-install/src/Distribution/Client/ProjectConfig.hs +++ b/cabal-install/src/Distribution/Client/ProjectConfig.hs @@ -28,6 +28,7 @@ module Distribution.Client.ProjectConfig ( readProjectConfig, readGlobalConfig, readProjectLocalFreezeConfig, + showProjectConfig, withProjectOrGlobalConfig, writeProjectLocalExtraConfig, writeProjectLocalFreezeConfig, diff --git a/cabal-testsuite/PackageTests/NewConfigure/ConfigFile/ConfigFile.cabal b/cabal-testsuite/PackageTests/NewConfigure/ConfigFile/ConfigFile.cabal new file mode 100644 index 00000000000..3173c99e860 --- /dev/null +++ b/cabal-testsuite/PackageTests/NewConfigure/ConfigFile/ConfigFile.cabal @@ -0,0 +1,7 @@ +name: ConfigFile +version: 0.1.0.0 +author: Foo Bar +maintainer: cabal-dev@haskell.org +build-type: Simple +cabal-version: >=1.10 + diff --git a/cabal-testsuite/PackageTests/NewConfigure/ConfigFile/Setup.hs b/cabal-testsuite/PackageTests/NewConfigure/ConfigFile/Setup.hs new file mode 100644 index 00000000000..9a994af677b --- /dev/null +++ b/cabal-testsuite/PackageTests/NewConfigure/ConfigFile/Setup.hs @@ -0,0 +1,2 @@ +import Distribution.Simple +main = defaultMain diff --git a/cabal-testsuite/PackageTests/NewConfigure/ConfigFile/cabal.out b/cabal-testsuite/PackageTests/NewConfigure/ConfigFile/cabal.out new file mode 100644 index 00000000000..3d1540223d7 --- /dev/null +++ b/cabal-testsuite/PackageTests/NewConfigure/ConfigFile/cabal.out @@ -0,0 +1,17 @@ +# cabal v2-configure +Would write the following configuration file: +store-dir: +verbose: verbose +nowrap +markoutput +builddir: /cabal.dist/work/./dist +jobs: 1 +project-file: cabal.project +ignore-project: False + +Resolving dependencies... +Build profile: -w ghc- -O1 +In order, the following would be built: + - ConfigFile-0.1.0.0 (first run) +# cabal v2-configure +Build profile: -w ghc- -O1 +In order, the following would be built: + - ConfigFile-0.1.0.0 (first run) diff --git a/cabal-testsuite/PackageTests/NewConfigure/ConfigFile/cabal.project b/cabal-testsuite/PackageTests/NewConfigure/ConfigFile/cabal.project new file mode 100644 index 00000000000..e6fdbadb439 --- /dev/null +++ b/cabal-testsuite/PackageTests/NewConfigure/ConfigFile/cabal.project @@ -0,0 +1 @@ +packages: . diff --git a/cabal-testsuite/PackageTests/NewConfigure/ConfigFile/cabal.test.hs b/cabal-testsuite/PackageTests/NewConfigure/ConfigFile/cabal.test.hs new file mode 100644 index 00000000000..3c8912952e7 --- /dev/null +++ b/cabal-testsuite/PackageTests/NewConfigure/ConfigFile/cabal.test.hs @@ -0,0 +1,17 @@ +import Test.Cabal.Prelude + +-- Test that 'cabal v2-configure' generates the config file appropriately +main = withShorterPathForNewBuildStore $ \storeDir -> + cabalTest . withSourceCopy $ do + cwd <- fmap testCurrentDir getTestEnv + let configFile = cwd "cabal.project.local" + + shouldNotExist configFile + + -- should not create config file with --dry-run + cabalG ["--store-dir=" ++ storeDir] "v2-configure" ["--dry-run"] + shouldNotExist configFile + + -- should create the config file + cabalG ["--store-dir=" ++ storeDir] "v2-configure" [] + shouldExist configFile diff --git a/cabal-testsuite/PackageTests/NewFreeze/FreezeFile/new_freeze.out b/cabal-testsuite/PackageTests/NewFreeze/FreezeFile/new_freeze.out index be573138281..04dd8b9ab7d 100644 --- a/cabal-testsuite/PackageTests/NewFreeze/FreezeFile/new_freeze.out +++ b/cabal-testsuite/PackageTests/NewFreeze/FreezeFile/new_freeze.out @@ -6,6 +6,16 @@ Build profile: -w ghc- -O1 In order, the following would be built: - my-library-dep-2.0 (lib) (requires build) - my-local-package-1.0 (exe:my-exe) (first run) +# cabal v2-freeze +Would have written the following freeze file: +active-repositories: test-local-repo:merge +constraints: any.base ==4.14.1.0, + any.ghc-prim ==0.6.1, + any.integer-gmp ==1.0.3.0, + any.my-library-dep ==2.0, + any.rts ==1.0 +index-state: HEAD + # cabal v2-freeze Resolving dependencies... Wrote freeze file: /new_freeze.dist/source/cabal.project.freeze diff --git a/cabal-testsuite/PackageTests/NewFreeze/FreezeFile/new_freeze.test.hs b/cabal-testsuite/PackageTests/NewFreeze/FreezeFile/new_freeze.test.hs index e2a3d59888b..f3fa886d3b9 100644 --- a/cabal-testsuite/PackageTests/NewFreeze/FreezeFile/new_freeze.test.hs +++ b/cabal-testsuite/PackageTests/NewFreeze/FreezeFile/new_freeze.test.hs @@ -16,6 +16,10 @@ main = withShorterPathForNewBuildStore $ \storeDir -> -- v2-build should choose the latest version for the dependency. cabalG' ["--store-dir=" ++ storeDir] "v2-build" ["--dry-run"] >>= assertUsesLatestDependency + -- should not create freeze file with --dry-run flag + cabalG' ["--store-dir=" ++ storeDir] "v2-freeze" ["--dry-run"] + shouldNotExist freezeFile + -- Freeze a dependency on the older version. cabalG ["--store-dir=" ++ storeDir] "v2-freeze" ["--constraint=my-library-dep==1.0"]