Skip to content

Commit 7f0e066

Browse files
Make Setup.hs configure more CWD-independent.
Previously, we were checking the package with a hard-coded root directory of ".". This was not a problem before, but with #5372 we have started to expand globs while checking packages, which breaks if the CWD is not the directory containing the `.cabal` file and causes snowleopard/hadrian#634. Luckily, this is an easy fix: the correct directory is easy to determine. Writing a test and making sure it's tickling the failing case took longer than writing the fix! "." is hard-coded as the root directory passed to `checkPackageFiles` in a few other places, but those are (a) non-trivial to test, and (b) already in places that have other assumptions about their CWD, so I have simply documented the CWD requirement for those.
1 parent 2ce4858 commit 7f0e066

File tree

11 files changed

+53
-16
lines changed

11 files changed

+53
-16
lines changed

Cabal/ChangeLog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@
6161
path components on Windows and warn about other unsafe characters
6262
in the path to the source directory on all platforms
6363
([#5386](https://github.com/haskell/cabal/issues/5386)).
64+
* `Distribution.PackageDescription.Check.checkPackageFiles` now
65+
accepts a `Verbosity` argument.
6466

6567
----
6668

Cabal/Distribution/PackageDescription/Check.hs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1840,10 +1840,10 @@ checkDevelopmentOnlyFlags pkg =
18401840
-- | Sanity check things that requires IO. It looks at the files in the
18411841
-- package and expects to find the package unpacked in at the given file path.
18421842
--
1843-
checkPackageFiles :: PackageDescription -> FilePath -> NoCallStackIO [PackageCheck]
1844-
checkPackageFiles pkg root = do
1843+
checkPackageFiles :: Verbosity -> PackageDescription -> FilePath -> NoCallStackIO [PackageCheck]
1844+
checkPackageFiles verbosity pkg root = do
18451845
contentChecks <- checkPackageContent checkFilesIO pkg
1846-
missingFileChecks <- checkPackageMissingFiles pkg root
1846+
missingFileChecks <- checkPackageMissingFiles verbosity pkg root
18471847
-- Sort because different platforms will provide files from
18481848
-- `getDirectoryContents` in different orders, and we'd like to be
18491849
-- stable for test output.
@@ -2155,20 +2155,20 @@ checkTarPath path
21552155
-- check these on the server; these checks only make sense in the development
21562156
-- and package-creation environment. Hence we can use IO, rather than needing
21572157
-- to pass a 'CheckPackageContentOps' dictionary around.
2158-
checkPackageMissingFiles :: PackageDescription -> FilePath -> NoCallStackIO [PackageCheck]
2158+
checkPackageMissingFiles :: Verbosity -> PackageDescription -> FilePath -> NoCallStackIO [PackageCheck]
21592159
checkPackageMissingFiles = checkGlobMultiDot
21602160

21612161
-- | Before Cabal 2.4, the extensions of globs had to match the file
21622162
-- exactly. This has been relaxed in 2.4 to allow matching only the
21632163
-- suffix. This warning detects when pre-2.4 package descriptions are
21642164
-- omitting files purely because of the stricter check.
2165-
checkGlobMultiDot :: PackageDescription
2165+
checkGlobMultiDot :: Verbosity
2166+
-> PackageDescription
21662167
-> FilePath
21672168
-> NoCallStackIO [PackageCheck]
2168-
checkGlobMultiDot pkg root =
2169+
checkGlobMultiDot verbosity pkg root =
21692170
fmap concat $ for allGlobs $ \(field, dir, glob) -> do
2170-
--TODO: baked-in verbosity
2171-
results <- matchDirFileGlob' normal (specVersion pkg) (root </> dir) glob
2171+
results <- matchDirFileGlob' verbosity (specVersion pkg) (root </> dir) glob
21722172
return
21732173
[ PackageDistSuspiciousWarn $
21742174
"In '" ++ field ++ "': the pattern '" ++ glob ++ "' does not"

Cabal/Distribution/Simple/Configure.hs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -473,8 +473,10 @@ configure (pkg_descr0, pbi) cfg = do
473473
debug verbosity $ "Finalized package description:\n"
474474
++ showPackageDescription pkg_descr
475475

476+
let cabalFileDir = maybe "." takeDirectory $
477+
flagToMaybe (configCabalFilePath cfg)
476478
checkCompilerProblems verbosity comp pkg_descr enabled
477-
checkPackageProblems verbosity pkg_descr0
479+
checkPackageProblems verbosity cabalFileDir pkg_descr0
478480
(updatePackageDescription pbi pkg_descr)
479481

480482
-- The list of 'InstalledPackageInfo' recording the selected
@@ -1841,11 +1843,13 @@ checkForeignDeps pkg lbi verbosity =
18411843

18421844
-- | Output package check warnings and errors. Exit if any errors.
18431845
checkPackageProblems :: Verbosity
1846+
-> FilePath
1847+
-- ^ Path to the @.cabal@ file's directory
18441848
-> GenericPackageDescription
18451849
-> PackageDescription
18461850
-> IO ()
1847-
checkPackageProblems verbosity gpkg pkg = do
1848-
ioChecks <- checkPackageFiles pkg "."
1851+
checkPackageProblems verbosity dir gpkg pkg = do
1852+
ioChecks <- checkPackageFiles verbosity pkg dir
18491853
let pureChecks = checkPackage gpkg (Just pkg)
18501854
errors = [ e | PackageBuildImpossible e <- pureChecks ++ ioChecks ]
18511855
warnings = [ w | PackageBuildWarning w <- pureChecks ++ ioChecks ]

Cabal/Distribution/Simple/SrcDist.hs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,9 +468,11 @@ allSourcesBuildInfo verbosity bi pps modules = do
468468
++ "is autogenerated it should be added to 'autogen-modules'."
469469

470470

471+
-- | Note: must be called with the CWD set to the directory containing
472+
-- the '.cabal' file.
471473
printPackageProblems :: Verbosity -> PackageDescription -> IO ()
472474
printPackageProblems verbosity pkg_descr = do
473-
ioChecks <- checkPackageFiles pkg_descr "."
475+
ioChecks <- checkPackageFiles verbosity pkg_descr "."
474476
let pureChecks = checkConfiguredPackage pkg_descr
475477
isDistError (PackageDistSuspicious _) = False
476478
isDistError (PackageDistSuspiciousWarn _) = False

cabal-install/Distribution/Client/Check.hs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ readGenericPackageDescriptionCheck verbosity fpath = do
4545
die' verbosity $ "Failed parsing \"" ++ fpath ++ "\"."
4646
Right x -> return (warnings, x)
4747

48+
-- | Note: must be called with the CWD set to the directory containing
49+
-- the '.cabal' file.
4850
check :: Verbosity -> IO Bool
4951
check verbosity = do
5052
pdfile <- defaultPackageDesc verbosity
@@ -66,7 +68,7 @@ check verbosity = do
6668
-- Hovever, this is the same way hackage does it, so we will yield
6769
-- the exact same errors as it will.
6870
let pkg_desc = flattenPackageDescription ppd
69-
ioChecks <- checkPackageFiles pkg_desc "."
71+
ioChecks <- checkPackageFiles verbosity pkg_desc "."
7072
let packageChecks = ioChecks ++ checkPackage ppd (Just pkg_desc) ++ ws'
7173
buildImpossible = [ x | x@PackageBuildImpossible {} <- packageChecks ]
7274
buildWarning = [ x | x@PackageBuildWarning {} <- packageChecks ]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
main = putStrLn "Main.hs"
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
cabal-version: 2.2
2+
name: a
3+
version: 0
4+
extra-source-files:
5+
doc/*.html
6+
7+
executable foo
8+
main-is: Main.hs
9+
default-language: Haskell2010
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
hello.html
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Setup configure
2+
Configuring a-0...
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import Test.Cabal.Prelude
2+
import Test.Cabal.Script
3+
main = setupTest $
4+
void $ setup'' "pkg" "configure" ["--cabal-file", "pkg/a.cabal"]

0 commit comments

Comments
 (0)