Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tell users about cabal.project.local~ #6877

Merged
merged 2 commits into from
Jun 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ ctags

# stack artifacts
/.stack-work/
stack.yaml.lock

# Shake artifacts
.shake*
Expand All @@ -60,3 +61,6 @@ register.sh

# python artifacts from documentation builds
*.pyc

# macOS folder metadata
.DS_Store
27 changes: 24 additions & 3 deletions cabal-install/Distribution/Client/CmdConfigure.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Distribution.Client.Compat.Prelude
import Prelude ()

import System.Directory
import System.FilePath
import qualified Data.Map as Map

import Distribution.Client.ProjectOrchestration
Expand All @@ -30,6 +31,9 @@ import Distribution.Simple.Command
import Distribution.Simple.Utils
( wrapText, notice )

import Distribution.Client.DistDirLayout
( DistDirLayout(..) )

configureCommand :: CommandUI (NixStyleFlags ())
configureCommand = CommandUI {
commandName = "v2-configure",
Expand Down Expand Up @@ -93,10 +97,26 @@ configureAction flags@NixStyleFlags {..} _extraArgs globalFlags = do
-- Write out the @cabal.project.local@ so it gets picked up by the
-- planning phase. If old config exists, then print the contents
-- before overwriting
exists <- doesFileExist "cabal.project.local"

let localFile = distProjectFile (distDirLayout baseCtx) "local"
-- | Chooses cabal.project.local~, or if it already exists
-- cabal.project.local~0, cabal.project.local~1 etc.
firstFreeBackup = firstFreeBackup' (0 :: Int)
firstFreeBackup' i = do
let backup = localFile <> "~" <> (if i <= 0 then "" else show (i - 1))
exists <- doesFileExist backup
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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when exists let's search for the first one of cabal.project.local~, cabal.project.local~0 cabal.project.local~1 etc. until one doesn't.

Note: we need to change this to take into account --project-file as we on it. I wonder if there's an issue about that too.

notice verbosity "'cabal.project.local' file already exists. Now overwriting it."
copyFile "cabal.project.local" "cabal.project.local~"
backup <- firstFreeBackup
notice verbosity $
quote (takeFileName localFile) <> " already exists, backing it up to "
<> quote (takeFileName backup) <> "."
copyFile localFile backup
writeProjectLocalExtraConfig (distDirLayout baseCtx)
cliConfig

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

2 changes: 1 addition & 1 deletion cabal-install/Distribution/Client/TargetProblem.hs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ data TargetProblem a
| TargetProblemNoSuchPackage PackageId
| TargetProblemNoSuchComponent PackageId ComponentName

| CustomTargetProblem a
-- | A custom target problem
| CustomTargetProblem a
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was to fix a haddock failure

deriving (Eq, Show, Functor)

-- | Type alias for a 'TargetProblem' with no user-defined problems/errors.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,31 @@
# cabal v2-configure
'cabal.project.local' file already exists. Now overwriting it.
'cabal.project.local' already exists, backing it up to 'cabal.project.local~'.
Resolving dependencies...
Build profile: -w ghc-<GHCVER> -O1
In order, the following would be built:
- NewConfigure-0.1.0.0 (lib) (first run)
# cabal v2-configure
'cabal.project.local' already exists, backing it up to 'cabal.project.local~0'.
Build profile: -w ghc-<GHCVER> -O1
In order, the following would be built:
- NewConfigure-0.1.0.0 (lib) (first run)
# cabal v2-configure
'cabal.project.local' already exists, backing it up to 'cabal.project.local~1'.
Build profile: -w ghc-<GHCVER> -O1
In order, the following would be built:
- NewConfigure-0.1.0.0 (lib) (first run)
# cabal v2-configure
'foo.project.local' already exists, backing it up to 'foo.project.local~'.
Build profile: -w ghc-<GHCVER> -O1
In order, the following would be built:
- NewConfigure-0.1.0.0 (lib) (first run)
# cabal v2-configure
'foo.project.local' already exists, backing it up to 'foo.project.local~0'.
Build profile: -w ghc-<GHCVER> -O1
In order, the following would be built:
- NewConfigure-0.1.0.0 (lib) (first run)
# cabal v2-configure
'foo.project.local' already exists, backing it up to 'foo.project.local~1'.
Build profile: -w ghc-<GHCVER> -O1
In order, the following would be built:
- NewConfigure-0.1.0.0 (lib) (first run)
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,20 @@ import Test.Cabal.Prelude

main = cabalTest $
withSourceCopy $ do
r <- cabal' "v2-configure" []
assertOutputContains "Now overwriting it" r
cabal' "v2-configure" [] >>=
assertOutputContains "backing it up to 'cabal.project.local~'"
cabal' "v2-configure" [] >>=
assertOutputContains "backing it up to 'cabal.project.local~0'"
cabal' "v2-configure" [] >>=
assertOutputContains "backing it up to 'cabal.project.local~1'"

-- With --project-file
cabal' "v2-configure" ["--project-file", "foo.project"] >>=
assertOutputContains
"'foo.project.local' already exists, backing it up to 'foo.project.local~'"
cabal' "v2-configure" ["--project-file", "foo.project"] >>=
assertOutputContains
"'foo.project.local' already exists, backing it up to 'foo.project.local~0'"
cabal' "v2-configure" ["--project-file", "foo.project"] >>=
assertOutputContains
"'foo.project.local' already exists, backing it up to 'foo.project.local~1'"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
packages: .