Skip to content

Commit f7828e1

Browse files
authored
Merge pull request #6877 from bubba/cabalprojectlocal-copy-message
Tell users about cabal.project.local~
2 parents 65d7cc6 + f9bf6b0 commit f7828e1

File tree

7 files changed

+73
-7
lines changed

7 files changed

+73
-7
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ ctags
5050

5151
# stack artifacts
5252
/.stack-work/
53+
stack.yaml.lock
5354

5455
# Shake artifacts
5556
.shake*
@@ -60,3 +61,6 @@ register.sh
6061

6162
# python artifacts from documentation builds
6263
*.pyc
64+
65+
# macOS folder metadata
66+
.DS_Store

cabal-install/Distribution/Client/CmdConfigure.hs

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import Distribution.Client.Compat.Prelude
1010
import Prelude ()
1111

1212
import System.Directory
13+
import System.FilePath
1314
import qualified Data.Map as Map
1415

1516
import Distribution.Client.ProjectOrchestration
@@ -30,6 +31,9 @@ import Distribution.Simple.Command
3031
import Distribution.Simple.Utils
3132
( wrapText, notice )
3233

34+
import Distribution.Client.DistDirLayout
35+
( DistDirLayout(..) )
36+
3337
configureCommand :: CommandUI (NixStyleFlags ())
3438
configureCommand = CommandUI {
3539
commandName = "v2-configure",
@@ -93,10 +97,26 @@ configureAction flags@NixStyleFlags {..} _extraArgs globalFlags = do
9397
-- Write out the @cabal.project.local@ so it gets picked up by the
9498
-- planning phase. If old config exists, then print the contents
9599
-- before overwriting
96-
exists <- doesFileExist "cabal.project.local"
100+
101+
let localFile = distProjectFile (distDirLayout baseCtx) "local"
102+
-- | Chooses cabal.project.local~, or if it already exists
103+
-- cabal.project.local~0, cabal.project.local~1 etc.
104+
firstFreeBackup = firstFreeBackup' (0 :: Int)
105+
firstFreeBackup' i = do
106+
let backup = localFile <> "~" <> (if i <= 0 then "" else show (i - 1))
107+
exists <- doesFileExist backup
108+
if exists
109+
then firstFreeBackup' (i + 1)
110+
else return backup
111+
112+
-- If cabal.project.local already exists, back up to cabal.project.local~[n]
113+
exists <- doesFileExist localFile
97114
when exists $ do
98-
notice verbosity "'cabal.project.local' file already exists. Now overwriting it."
99-
copyFile "cabal.project.local" "cabal.project.local~"
115+
backup <- firstFreeBackup
116+
notice verbosity $
117+
quote (takeFileName localFile) <> " already exists, backing it up to "
118+
<> quote (takeFileName backup) <> "."
119+
copyFile localFile backup
100120
writeProjectLocalExtraConfig (distDirLayout baseCtx)
101121
cliConfig
102122

@@ -125,4 +145,5 @@ configureAction flags@NixStyleFlags {..} _extraArgs globalFlags = do
125145
verbosity = fromFlagOrDefault normal (configVerbosity configFlags)
126146
cliConfig = commandLineFlagsToProjectConfig globalFlags flags
127147
mempty -- ClientInstallFlags, not needed here
148+
quote s = "'" <> s <> "'"
128149

cabal-install/Distribution/Client/TargetProblem.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ data TargetProblem a
4545
| TargetProblemNoSuchPackage PackageId
4646
| TargetProblemNoSuchComponent PackageId ComponentName
4747

48-
| CustomTargetProblem a
4948
-- | A custom target problem
49+
| CustomTargetProblem a
5050
deriving (Eq, Show, Functor)
5151

5252
-- | Type alias for a 'TargetProblem' with no user-defined problems/errors.
Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,31 @@
11
# cabal v2-configure
2-
'cabal.project.local' file already exists. Now overwriting it.
2+
'cabal.project.local' already exists, backing it up to 'cabal.project.local~'.
33
Resolving dependencies...
44
Build profile: -w ghc-<GHCVER> -O1
55
In order, the following would be built:
66
- NewConfigure-0.1.0.0 (lib) (first run)
7+
# cabal v2-configure
8+
'cabal.project.local' already exists, backing it up to 'cabal.project.local~0'.
9+
Build profile: -w ghc-<GHCVER> -O1
10+
In order, the following would be built:
11+
- NewConfigure-0.1.0.0 (lib) (first run)
12+
# cabal v2-configure
13+
'cabal.project.local' already exists, backing it up to 'cabal.project.local~1'.
14+
Build profile: -w ghc-<GHCVER> -O1
15+
In order, the following would be built:
16+
- NewConfigure-0.1.0.0 (lib) (first run)
17+
# cabal v2-configure
18+
'foo.project.local' already exists, backing it up to 'foo.project.local~'.
19+
Build profile: -w ghc-<GHCVER> -O1
20+
In order, the following would be built:
21+
- NewConfigure-0.1.0.0 (lib) (first run)
22+
# cabal v2-configure
23+
'foo.project.local' already exists, backing it up to 'foo.project.local~0'.
24+
Build profile: -w ghc-<GHCVER> -O1
25+
In order, the following would be built:
26+
- NewConfigure-0.1.0.0 (lib) (first run)
27+
# cabal v2-configure
28+
'foo.project.local' already exists, backing it up to 'foo.project.local~1'.
29+
Build profile: -w ghc-<GHCVER> -O1
30+
In order, the following would be built:
31+
- NewConfigure-0.1.0.0 (lib) (first run)

cabal-testsuite/PackageTests/NewConfigure/LocalConfigOverwrite/cabal.test.hs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,20 @@ import Test.Cabal.Prelude
22

33
main = cabalTest $
44
withSourceCopy $ do
5-
r <- cabal' "v2-configure" []
6-
assertOutputContains "Now overwriting it" r
5+
cabal' "v2-configure" [] >>=
6+
assertOutputContains "backing it up to 'cabal.project.local~'"
7+
cabal' "v2-configure" [] >>=
8+
assertOutputContains "backing it up to 'cabal.project.local~0'"
9+
cabal' "v2-configure" [] >>=
10+
assertOutputContains "backing it up to 'cabal.project.local~1'"
11+
12+
-- With --project-file
13+
cabal' "v2-configure" ["--project-file", "foo.project"] >>=
14+
assertOutputContains
15+
"'foo.project.local' already exists, backing it up to 'foo.project.local~'"
16+
cabal' "v2-configure" ["--project-file", "foo.project"] >>=
17+
assertOutputContains
18+
"'foo.project.local' already exists, backing it up to 'foo.project.local~0'"
19+
cabal' "v2-configure" ["--project-file", "foo.project"] >>=
20+
assertOutputContains
21+
"'foo.project.local' already exists, backing it up to 'foo.project.local~1'"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
packages: .

cabal-testsuite/PackageTests/NewConfigure/LocalConfigOverwrite/foo.project.local

Whitespace-only changes.

0 commit comments

Comments
 (0)