From abd4ead70a3c325dbd5deed189474e7d599686f0 Mon Sep 17 00:00:00 2001 From: sheaf Date: Tue, 30 Apr 2024 15:51:03 +0200 Subject: [PATCH] Filter Setup flags: filter working dir on < 3.13 The --working-dir flag is only available for Cabal >= 3.13. This commit fixes an incorrect conditional: we only filtered out this flag for Cabal < 3.11, instead of < 3.13. Test: PackageTests/WorkingDir Fixes #9940 --- cabal-install/src/Distribution/Client/Setup.hs | 12 ++++++------ .../PackageTests/WorkingDir/Main.hs | 6 ++++++ .../PackageTests/WorkingDir/Setup.hs | 7 +++++++ .../PackageTests/WorkingDir/cabal.project | 1 + .../PackageTests/WorkingDir/dep/Dep.hs | 4 ++++ .../PackageTests/WorkingDir/dep/Setup.hs | 7 +++++++ .../PackageTests/WorkingDir/dep/dep.cabal | 18 ++++++++++++++++++ .../PackageTests/WorkingDir/setup.test.hs | 6 ++++++ .../WorkingDir/working-dir-test.cabal | 18 ++++++++++++++++++ 9 files changed, 73 insertions(+), 6 deletions(-) create mode 100644 cabal-testsuite/PackageTests/WorkingDir/Main.hs create mode 100644 cabal-testsuite/PackageTests/WorkingDir/Setup.hs create mode 100644 cabal-testsuite/PackageTests/WorkingDir/cabal.project create mode 100644 cabal-testsuite/PackageTests/WorkingDir/dep/Dep.hs create mode 100644 cabal-testsuite/PackageTests/WorkingDir/dep/Setup.hs create mode 100644 cabal-testsuite/PackageTests/WorkingDir/dep/dep.cabal create mode 100644 cabal-testsuite/PackageTests/WorkingDir/setup.test.hs create mode 100644 cabal-testsuite/PackageTests/WorkingDir/working-dir-test.cabal diff --git a/cabal-install/src/Distribution/Client/Setup.hs b/cabal-install/src/Distribution/Client/Setup.hs index c89f2a3524a..ae21e7f3799 100644 --- a/cabal-install/src/Distribution/Client/Setup.hs +++ b/cabal-install/src/Distribution/Client/Setup.hs @@ -635,22 +635,22 @@ filterCommonFlags :: CommonSetupFlags -> Version -> CommonSetupFlags filterCommonFlags flags cabalLibVersion -- NB: we expect the latest version to be the most common case, -- so test it first. - | cabalLibVersion >= mkVersion [3, 11, 0] = flags_latest + | cabalLibVersion >= mkVersion [3, 13, 0] = flags_latest | cabalLibVersion < mkVersion [1, 2, 5] = flags_1_2_5 | cabalLibVersion < mkVersion [2, 1, 0] = flags_2_1_0 - | cabalLibVersion < mkVersion [3, 11, 0] = flags_3_11_0 + | cabalLibVersion < mkVersion [3, 13, 0] = flags_3_13_0 | otherwise = error "the impossible just happened" -- see first guard where flags_latest = flags - flags_3_11_0 = + flags_3_13_0 = flags_latest { setupWorkingDir = NoFlag } - -- Cabal < 3.11 does not support the --working-dir flag. + -- Cabal < 3.13 does not support the --working-dir flag. flags_2_1_0 = - flags_3_11_0 + flags_3_13_0 { -- Cabal < 2.1 doesn't know about -v +timestamp modifier - setupVerbosity = fmap verboseNoTimestamp (setupVerbosity flags_3_11_0) + setupVerbosity = fmap verboseNoTimestamp (setupVerbosity flags_3_13_0) } flags_1_2_5 = flags_2_1_0 diff --git a/cabal-testsuite/PackageTests/WorkingDir/Main.hs b/cabal-testsuite/PackageTests/WorkingDir/Main.hs new file mode 100644 index 00000000000..2c123dd8d35 --- /dev/null +++ b/cabal-testsuite/PackageTests/WorkingDir/Main.hs @@ -0,0 +1,6 @@ +module Main where + +import Dep(foo) + +main :: IO () +main = print foo diff --git a/cabal-testsuite/PackageTests/WorkingDir/Setup.hs b/cabal-testsuite/PackageTests/WorkingDir/Setup.hs new file mode 100644 index 00000000000..e336d1360dc --- /dev/null +++ b/cabal-testsuite/PackageTests/WorkingDir/Setup.hs @@ -0,0 +1,7 @@ +module Main where + +import Distribution.Simple ( defaultMain ) + +main :: IO () +main = defaultMain + diff --git a/cabal-testsuite/PackageTests/WorkingDir/cabal.project b/cabal-testsuite/PackageTests/WorkingDir/cabal.project new file mode 100644 index 00000000000..d3728fff485 --- /dev/null +++ b/cabal-testsuite/PackageTests/WorkingDir/cabal.project @@ -0,0 +1 @@ +packages: ., dep diff --git a/cabal-testsuite/PackageTests/WorkingDir/dep/Dep.hs b/cabal-testsuite/PackageTests/WorkingDir/dep/Dep.hs new file mode 100644 index 00000000000..42677d6abf7 --- /dev/null +++ b/cabal-testsuite/PackageTests/WorkingDir/dep/Dep.hs @@ -0,0 +1,4 @@ +module Dep where + +foo :: Int +foo = 17 diff --git a/cabal-testsuite/PackageTests/WorkingDir/dep/Setup.hs b/cabal-testsuite/PackageTests/WorkingDir/dep/Setup.hs new file mode 100644 index 00000000000..e336d1360dc --- /dev/null +++ b/cabal-testsuite/PackageTests/WorkingDir/dep/Setup.hs @@ -0,0 +1,7 @@ +module Main where + +import Distribution.Simple ( defaultMain ) + +main :: IO () +main = defaultMain + diff --git a/cabal-testsuite/PackageTests/WorkingDir/dep/dep.cabal b/cabal-testsuite/PackageTests/WorkingDir/dep/dep.cabal new file mode 100644 index 00000000000..56a03ad8ec9 --- /dev/null +++ b/cabal-testsuite/PackageTests/WorkingDir/dep/dep.cabal @@ -0,0 +1,18 @@ +cabal-version: 2.4 +name: dep +version: 0.1.0.0 +synopsis: Test that we don't pass --working-dir when unsupported +license: BSD-3-Clause +author: NA +maintainer: NA +category: Testing +build-type: Custom + +custom-setup + setup-depends: base, Cabal >= 2.4 && < 3.13 + +library + build-depends: base + default-language: Haskell2010 + hs-source-dirs: . + exposed-modules: Dep diff --git a/cabal-testsuite/PackageTests/WorkingDir/setup.test.hs b/cabal-testsuite/PackageTests/WorkingDir/setup.test.hs new file mode 100644 index 00000000000..206db0e09e3 --- /dev/null +++ b/cabal-testsuite/PackageTests/WorkingDir/setup.test.hs @@ -0,0 +1,6 @@ +import Test.Cabal.Prelude + +main = cabalTest $ recordMode DoNotRecord $ do + skipUnlessAnyCabalVersion "< 3.13" + cabalWithStdin "v2-build" [] "" + return () diff --git a/cabal-testsuite/PackageTests/WorkingDir/working-dir-test.cabal b/cabal-testsuite/PackageTests/WorkingDir/working-dir-test.cabal new file mode 100644 index 00000000000..c9ef242ee61 --- /dev/null +++ b/cabal-testsuite/PackageTests/WorkingDir/working-dir-test.cabal @@ -0,0 +1,18 @@ +cabal-version: 2.4 +name: working-dir-test +version: 0.1.0.0 +synopsis: Test that we don't pass --working-dir when unsupported +license: BSD-3-Clause +author: NA +maintainer: NA +category: Testing +build-type: Custom + +custom-setup + setup-depends: base, Cabal >= 2.4 && < 3.13 + +executable Exe + default-language: Haskell2010 + build-depends: base, dep + hs-source-dirs: . + main-is: Main.hs