Skip to content

v2-sdist now respects --ignore-project #8109

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

Merged
merged 13 commits into from
May 12, 2022
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
3 changes: 1 addition & 2 deletions cabal-install/src/Distribution/Client/CmdSdist.hs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ sdistOptions showOrParseArgs =

sdistAction :: (ProjectFlags, SdistFlags) -> [String] -> GlobalFlags -> IO ()
sdistAction (ProjectFlags{..}, SdistFlags{..}) targetStrings globalFlags = do
(baseCtx, distDirLayout) <- withProjectOrGlobalConfig verbosity ignoreProject globalConfigFlag withProject withoutProject
(baseCtx, distDirLayout) <- withProjectOrGlobalConfig verbosity flagIgnoreProject globalConfigFlag withProject withoutProject

let localPkgs = localPackages baseCtx

Expand Down Expand Up @@ -187,7 +187,6 @@ sdistAction (ProjectFlags{..}, SdistFlags{..}) targetStrings globalFlags = do
listSources = fromFlagOrDefault False sdistListSources
nulSeparated = fromFlagOrDefault False sdistNulSeparated
mOutputPath = flagToMaybe sdistOutputPath
ignoreProject = flagIgnoreProject

prjConfig :: ProjectConfig
prjConfig = commandLineFlagsToProjectConfig
Expand Down
26 changes: 15 additions & 11 deletions cabal-install/src/Distribution/Client/ProjectConfig.hs
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ renderBadProjectRoot (BadProjectRootExplicitFile projectFile) =

withProjectOrGlobalConfig
:: Verbosity -- ^ verbosity
-> Flag Bool -- ^ whether to ignore local project
-> Flag Bool -- ^ whether to ignore local project (--ignore-project flag)
-> Flag FilePath -- ^ @--cabal-config@
-> IO a -- ^ with project
-> (ProjectConfig -> IO a) -- ^ without projet
Expand Down Expand Up @@ -504,16 +504,22 @@ withProjectOrGlobalConfig' verbosity globalConfigFlag with without = do
--
readProjectConfig :: Verbosity
-> HttpTransport
-> Flag Bool -- ^ @--ignore-project@
-> Flag FilePath
-> DistDirLayout
-> Rebuild ProjectConfigSkeleton
readProjectConfig verbosity httpTransport configFileFlag distDirLayout = do
readProjectConfig verbosity httpTransport ignoreProjectFlag configFileFlag distDirLayout = do
global <- singletonProjectConfigSkeleton <$> readGlobalConfig verbosity configFileFlag
local <- readProjectLocalConfigOrDefault verbosity httpTransport distDirLayout
freeze <- readProjectLocalFreezeConfig verbosity httpTransport distDirLayout
extra <- readProjectLocalExtraConfig verbosity httpTransport distDirLayout
return (global <> local <> freeze <> extra)

if ignoreProjectFlag == Flag True then return (global <> (singletonProjectConfigSkeleton defaultProject))
else return (global <> local <> freeze <> extra)
where
defaultProject :: ProjectConfig
defaultProject = mempty {
projectPackages = ["./"]
}

-- | Reads an explicit @cabal.project@ file in the given project root dir,
-- or returns the default project config for an implicitly defined project.
Expand All @@ -534,15 +540,13 @@ readProjectLocalConfigOrDefault verbosity httpTransport distDirLayout = do
where
projectFile :: FilePath
projectFile = distProjectFile distDirLayout ""

defaultImplicitProjectConfig :: ProjectConfig
defaultImplicitProjectConfig =
mempty {
-- We expect a package in the current directory.
projectPackages = [ "./*.cabal" ],
defaultImplicitProjectConfig = mempty {
-- We expect a package in the current directory.
projectPackages = [ "./*.cabal" ],

projectConfigProvenance = Set.singleton Implicit
}
projectConfigProvenance = Set.singleton Implicit
}

-- | Reads a @cabal.project.local@ file in the given project root dir,
-- or returns empty. This file gets written by @cabal configure@, or in
Expand Down
5 changes: 4 additions & 1 deletion cabal-install/src/Distribution/Client/ProjectFlags.hs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ projectFlagsOptions showOrParseArgs =
(reqArg "FILE" (succeedReadE Flag) flagToList)
, option ['z'] ["ignore-project"]
"Ignore local project configuration"
flagIgnoreProject (\v flags -> flags { flagIgnoreProject = v })
-- Flag True: --ignore-project is given and --project-file is not given
-- Flag False: --ignore-project and --project-file is given
-- NoFlag: neither --ignore-project or --project-file is given
flagIgnoreProject (\v flags -> flags { flagIgnoreProject = if v == NoFlag then NoFlag else toFlag ((flagProjectFileName flags) == NoFlag && v == Flag True) })
(yesNoOpt showOrParseArgs)
]

Expand Down
7 changes: 5 additions & 2 deletions cabal-install/src/Distribution/Client/ProjectPlanning.hs
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,9 @@ rebuildProjectConfig verbosity
ProjectConfigShared { projectConfigConfigFile } =
projectConfigShared cliConfig

ProjectConfigShared { projectConfigIgnoreProject } =
projectConfigShared cliConfig

fileMonitorProjectConfig ::
FileMonitor
(FilePath, FilePath)
Expand All @@ -364,7 +367,7 @@ rebuildProjectConfig verbosity
--
phaseReadProjectConfig :: Rebuild ProjectConfigSkeleton
phaseReadProjectConfig = do
readProjectConfig verbosity httpTransport projectConfigConfigFile distDirLayout
readProjectConfig verbosity httpTransport projectConfigIgnoreProject projectConfigConfigFile distDirLayout

-- Look for all the cabal packages in the project
-- some of which may be local src dirs, tarballs etc
Expand All @@ -375,8 +378,8 @@ rebuildProjectConfig verbosity
projectConfigShared,
projectConfigBuildOnly
} = do
pkgLocations <- findProjectPackages distDirLayout projectConfig

pkgLocations <- findProjectPackages distDirLayout projectConfig
-- Create folder only if findProjectPackages did not throw a
-- BadPackageLocations exception.
liftIO $ do
Expand Down
22 changes: 20 additions & 2 deletions cabal-install/tests/IntegrationTests2.hs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import Distribution.Simple.Setup (toFlag, HaddockFlags(..), defaultHaddockFlags)
import Distribution.Client.Setup (globalCommand)
import Distribution.Simple.Compiler
import Distribution.Simple.Command
import qualified Distribution.Simple.Flag as Flag
import Distribution.System
import Distribution.Version
import Distribution.ModuleName (ModuleName)
Expand Down Expand Up @@ -147,7 +148,8 @@ tests config =
]
, testGroup "Flag tests" $
[
testCase "Test Nix Flag" testNixFlags
testCase "Test Nix Flag" testNixFlags,
testCase "Test Ignore Project Flag" testIgnoreProjectFlag
]
]

Expand Down Expand Up @@ -1960,4 +1962,20 @@ testNixFlags = do
fromFlag NoFlag = Nothing
getFlags :: CommandUI GlobalFlags -> CommandParse (GlobalFlags -> GlobalFlags, [String]) -> Maybe GlobalFlags
getFlags cui (CommandReadyToGo (mkflags, _)) = Just . mkflags . commandDefaultFlags $ cui
getFlags _ _ = Nothing
getFlags _ _ = Nothing

testIgnoreProjectFlag :: Assertion
testIgnoreProjectFlag = do
-- Coverage flag should be false globally by default (~/.cabal folder)
(_, _, prjConfigGlobal, _, _) <- configureProject testdir ignoreSetConfig
let globalCoverageFlag = packageConfigCoverage . projectConfigLocalPackages $ prjConfigGlobal
False @=? Flag.fromFlagOrDefault False globalCoverageFlag
-- It is set to true in the cabal.project file
(_, _, prjConfigLocal, _, _) <- configureProject testdir emptyConfig
let localCoverageFlag = packageConfigCoverage . projectConfigLocalPackages $ prjConfigLocal
True @=? Flag.fromFlagOrDefault False localCoverageFlag
where
testdir = "build/ignore-project"
emptyConfig = mempty
ignoreSetConfig :: ProjectConfig
ignoreSetConfig = mempty { projectConfigShared = mempty { projectConfigIgnoreProject = Flag True } }
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module A where

a :: Int
a = 42
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import Distribution.Simple
main = defaultMain
10 changes: 10 additions & 0 deletions cabal-install/tests/IntegrationTests2/build/ignore-project/a.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: a
version: 0.1
build-type: Simple
cabal-version: >= 1.10

library
exposed-modules: A
build-depends: base
default-language: Haskell2010
profiling: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
packages: .

coverage: true
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
packages: ./
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ import Test.Cabal.Prelude
main = cabalTest $ do
tmpdir <- fmap testTmpDir getTestEnv
let fn = tmpdir </> "empty-data-dir-0.list"
cabal "v2-sdist" ["--ignore-project", "--list-only", "--output-directory", tmpdir]
cabal "v2-sdist" ["--list-only", "--output-directory", tmpdir]
-- --list-sources outputs with slashes on posix and backslashes on Windows. 'normalise' converts our needle to the necessary format.
assertFileDoesContain fn $ normalise "foo.dat"
1 change: 1 addition & 0 deletions cabal-testsuite/PackageTests/SDist/T5195/cabal.project
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
packages: ./
2 changes: 1 addition & 1 deletion cabal-testsuite/PackageTests/SDist/T5195/cabal.test.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Test.Cabal.Prelude
main = cabalTest $ do
tmpdir <- fmap testTmpDir getTestEnv
res <- fails $ cabal' "v2-sdist" ["--ignore-project", "--list-only", "--output-directory", tmpdir]
res <- fails $ cabal' "v2-sdist" ["--list-only", "--output-directory", tmpdir]
assertOutputContains "filepath wildcard './actually-a-directory' does not match any files" res
2 changes: 1 addition & 1 deletion cabal-testsuite/PackageTests/SDist/T7028/cabal.test.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Test.Cabal.Prelude
main = cabalTest $ do
tmpdir <- fmap testTmpDir getTestEnv
cabal "v2-sdist" ["--ignore-project", "--list-only", "--output-directory", tmpdir, "t7028"]
cabal "v2-sdist" ["--list-only", "--output-directory", tmpdir, "t7028"]
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ import Test.Cabal.Prelude
main :: IO ()
main = cabalTest $ do
tmpdir <- fmap testTmpDir getTestEnv
fails $ cabal "v2-sdist" ["--ignore-project", "--list-only", "--output-directory", tmpdir, "all"]
fails $ cabal "v2-sdist" ["--list-only", "--output-directory", tmpdir, "all"]
2 changes: 1 addition & 1 deletion cabal-testsuite/PackageTests/SDist/T7124/cabal.test.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ import Test.Cabal.Prelude
main :: IO ()
main = cabalTest $ do
tmpdir <- fmap testTmpDir getTestEnv
fails $ cabal "v2-sdist" ["--ignore-project", "--output-directory", tmpdir, "all"]
fails $ cabal "v2-sdist" ["--output-directory", tmpdir, "all"]
2 changes: 1 addition & 1 deletion cabal-testsuite/PackageTests/SDist/T7698/cabal.test.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Test.Cabal.Prelude
main = cabalTest $ do
tmpdir <- fmap testTmpDir getTestEnv
cabal "v2-sdist" ["--ignore-project", "--list-only", "--output-directory", tmpdir, "all"]
cabal "v2-sdist" ["--list-only", "--output-directory", tmpdir, "all"]
5 changes: 5 additions & 0 deletions changelog.d/issue-7965
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
synopsis: Ensure that v2-sdist command respects the --ignore-project flag
-- If the "--project-file" flag is set, then this [--ignore-project] will always be false
packages: cabal-install
issues: #7965
prs: #8109
7 changes: 7 additions & 0 deletions doc/cabal-project.rst
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,13 @@ package, and thus apply globally:

This option cannot be specified via a ``cabal.project`` file.

-- option:: --ignore-project

Ignores the local ``cabal.project`` file and uses the default
configuration with the local ``foo.cabal`` file. Note that
if this flag is set while the ``--project-file`` flag is also
set then this flag will be ignored.

.. option:: --store-dir=DIR

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