From d0c3defe64b1c9938ce57e4f858847a72d626423 Mon Sep 17 00:00:00 2001 From: quasicomputational Date: Sun, 13 May 2018 14:27:50 +0100 Subject: [PATCH] Don't break when data-dir is null. PR #5284 changed things around, and now matchDirFileGlob will break if it's passed a null directory, which happens to be the default value for data-dir. Its call sites have been fixed to check for this and to substitute '.' for an empty path, which is the desired behaviour; in addition, matchDirFileGlob itself will now warn about this if it's detected, so that new broken call sites can't sneak in. Fixes #5318. --- Cabal/Distribution/Simple/Glob.hs | 12 +++++++++++- Cabal/Distribution/Simple/Install.hs | 5 ++++- Cabal/Distribution/Simple/SrcDist.hs | 8 ++++++-- .../PackageTests/Regression/T5318/Main.hs | 1 + .../Regression/T5318/empty-data-dir.cabal | 10 ++++++++++ .../PackageTests/Regression/T5318/foo.dat | 1 + .../PackageTests/Regression/T5318/install.out | 8 ++++++++ .../PackageTests/Regression/T5318/install.test.hs | 3 +++ .../Regression/T5318/sdist-list-sources.out | 3 +++ .../Regression/T5318/sdist-list-sources.test.hs | 7 +++++++ 10 files changed, 54 insertions(+), 4 deletions(-) create mode 100644 cabal-testsuite/PackageTests/Regression/T5318/Main.hs create mode 100644 cabal-testsuite/PackageTests/Regression/T5318/empty-data-dir.cabal create mode 100644 cabal-testsuite/PackageTests/Regression/T5318/foo.dat create mode 100644 cabal-testsuite/PackageTests/Regression/T5318/install.out create mode 100644 cabal-testsuite/PackageTests/Regression/T5318/install.test.hs create mode 100644 cabal-testsuite/PackageTests/Regression/T5318/sdist-list-sources.out create mode 100644 cabal-testsuite/PackageTests/Regression/T5318/sdist-list-sources.test.hs diff --git a/Cabal/Distribution/Simple/Glob.hs b/Cabal/Distribution/Simple/Glob.hs index ad62f71b6b3..820696e2ef7 100644 --- a/Cabal/Distribution/Simple/Glob.hs +++ b/Cabal/Distribution/Simple/Glob.hs @@ -142,9 +142,19 @@ matchFileGlob verbosity version = matchDirFileGlob verbosity version "." -- The returned values do not include the supplied @dir@ prefix. matchDirFileGlob :: Verbosity -> Version -> FilePath -> FilePath -> IO [FilePath] -matchDirFileGlob verbosity version dir filepath = case parseFileGlob version filepath of +matchDirFileGlob verbosity version rawDir filepath = case parseFileGlob version filepath of Left err -> die' verbosity $ explainGlobSyntaxError filepath err Right pat -> do + -- The default data-dir is null. Our callers -should- be + -- converting that to '.' themselves, but it's a certainty that + -- some future call-site will forget and trigger a really + -- hard-to-debug failure if we don't check for that here. + when (null rawDir) $ + warn verbosity $ + "Null dir passed to matchDirFileGlob; interpreting it " + ++ "as '.'. This is probably an internal error." + let dir = if null rawDir then "." else rawDir + debug verbosity $ "Expanding glob '" ++ filepath ++ "' in directory '" ++ dir ++ "'." -- This function might be called from the project root with dir as -- ".". Walking the tree starting there involves going into .git/ -- and dist-newstyle/, which is a lot of work for no reward, so diff --git a/Cabal/Distribution/Simple/Install.hs b/Cabal/Distribution/Simple/Install.hs index ce9a2d9fba0..30ae881a045 100644 --- a/Cabal/Distribution/Simple/Install.hs +++ b/Cabal/Distribution/Simple/Install.hs @@ -235,7 +235,10 @@ copyComponent _ _ _ (CTest _) _ _ = return () installDataFiles :: Verbosity -> PackageDescription -> FilePath -> IO () installDataFiles verbosity pkg_descr destDataDir = flip traverse_ (dataFiles pkg_descr) $ \ file -> do - let srcDataDir = dataDir pkg_descr + let srcDataDirRaw = dataDir pkg_descr + srcDataDir = if null srcDataDirRaw + then "." + else srcDataDirRaw files <- matchDirFileGlob verbosity (specVersion pkg_descr) srcDataDir file let dir = takeDirectory file createDirectoryIfMissingVerbose verbosity True (destDataDir dir) diff --git a/Cabal/Distribution/Simple/SrcDist.hs b/Cabal/Distribution/Simple/SrcDist.hs index 862a68e3be2..74098e37d0e 100644 --- a/Cabal/Distribution/Simple/SrcDist.hs +++ b/Cabal/Distribution/Simple/SrcDist.hs @@ -209,8 +209,12 @@ listPackageSourcesOrdinary verbosity pkg_descr pps = -- Data files. , fmap concat . for (dataFiles pkg_descr) $ \filename -> - fmap (fmap (dataDir pkg_descr )) $ - matchDirFileGlob verbosity (specVersion pkg_descr) (dataDir pkg_descr) filename + let srcDataDirRaw = dataDir pkg_descr + srcDataDir = if null srcDataDirRaw + then "." + else srcDataDirRaw + in fmap (fmap (srcDataDir )) $ + matchDirFileGlob verbosity (specVersion pkg_descr) srcDataDir filename -- Extra doc files. , fmap concat diff --git a/cabal-testsuite/PackageTests/Regression/T5318/Main.hs b/cabal-testsuite/PackageTests/Regression/T5318/Main.hs new file mode 100644 index 00000000000..4233a67ecdd --- /dev/null +++ b/cabal-testsuite/PackageTests/Regression/T5318/Main.hs @@ -0,0 +1 @@ +main = putStrLn "hi" diff --git a/cabal-testsuite/PackageTests/Regression/T5318/empty-data-dir.cabal b/cabal-testsuite/PackageTests/Regression/T5318/empty-data-dir.cabal new file mode 100644 index 00000000000..27965693d9c --- /dev/null +++ b/cabal-testsuite/PackageTests/Regression/T5318/empty-data-dir.cabal @@ -0,0 +1,10 @@ +cabal-version: 2.0 +name: empty-data-dir +version: 0 +build-type: Simple +data-files: foo.dat + +executable foo + default-language: Haskell2010 + build-depends: base + main-is: Main.hs diff --git a/cabal-testsuite/PackageTests/Regression/T5318/foo.dat b/cabal-testsuite/PackageTests/Regression/T5318/foo.dat new file mode 100644 index 00000000000..10ddd6d257e --- /dev/null +++ b/cabal-testsuite/PackageTests/Regression/T5318/foo.dat @@ -0,0 +1 @@ +Hello! diff --git a/cabal-testsuite/PackageTests/Regression/T5318/install.out b/cabal-testsuite/PackageTests/Regression/T5318/install.out new file mode 100644 index 00000000000..d4deda38608 --- /dev/null +++ b/cabal-testsuite/PackageTests/Regression/T5318/install.out @@ -0,0 +1,8 @@ +# cabal install +Resolving dependencies... +Configuring empty-data-dir-0... +Preprocessing executable 'foo' for empty-data-dir-0.. +Building executable 'foo' for empty-data-dir-0.. +Installing executable foo in +Warning: The directory /install.dist/home/.cabal/bin is not in the system search path. +Installed empty-data-dir-0 diff --git a/cabal-testsuite/PackageTests/Regression/T5318/install.test.hs b/cabal-testsuite/PackageTests/Regression/T5318/install.test.hs new file mode 100644 index 00000000000..b0286555018 --- /dev/null +++ b/cabal-testsuite/PackageTests/Regression/T5318/install.test.hs @@ -0,0 +1,3 @@ +import Test.Cabal.Prelude +main = cabalTest $ + cabal "install" [] diff --git a/cabal-testsuite/PackageTests/Regression/T5318/sdist-list-sources.out b/cabal-testsuite/PackageTests/Regression/T5318/sdist-list-sources.out new file mode 100644 index 00000000000..2482a13d897 --- /dev/null +++ b/cabal-testsuite/PackageTests/Regression/T5318/sdist-list-sources.out @@ -0,0 +1,3 @@ +# cabal sdist +List of package sources written to file '/sources' +List of package sources written to file '/sources' diff --git a/cabal-testsuite/PackageTests/Regression/T5318/sdist-list-sources.test.hs b/cabal-testsuite/PackageTests/Regression/T5318/sdist-list-sources.test.hs new file mode 100644 index 00000000000..1bc26616628 --- /dev/null +++ b/cabal-testsuite/PackageTests/Regression/T5318/sdist-list-sources.test.hs @@ -0,0 +1,7 @@ +import Test.Cabal.Prelude +main = cabalTest $ do + tmpdir <- fmap testTmpDir getTestEnv + let fn = tmpdir "sources" + cabal "sdist" ["--list-sources=" ++ fn] + -- --list-sources outputs with slashes on posix and backslashes on Windows. 'normalise' converts our needle to the necessary format. + assertFileDoesContain fn $ normalise "foo.dat"