diff --git a/Cabal/Distribution/Simple/Glob.hs b/Cabal/Distribution/Simple/Glob.hs index ad62f71b6b3..6236a8ca1de 100644 --- a/Cabal/Distribution/Simple/Glob.hs +++ b/Cabal/Distribution/Simple/Glob.hs @@ -145,6 +145,16 @@ matchDirFileGlob :: Verbosity -> Version -> FilePath -> FilePath -> IO [FilePath matchDirFileGlob verbosity version dir 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 dir) $ + warn verbosity $ + "Null dir passed to matchDirFileGlob; interpreting it " + ++ "as '.'. This is probably an internal error." + let dir' = if null dir then "." else dir + 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 @@ -154,7 +164,7 @@ matchDirFileGlob verbosity version dir filepath = case parseFileGlob version fil -- for! let (prefixSegments, pat') = splitConstantPrefix pat joinedPrefix = joinPath prefixSegments - files <- getDirectoryContentsRecursive (dir joinedPrefix) + files <- getDirectoryContentsRecursive (dir' joinedPrefix) case filter (fileGlobMatches pat') files of [] -> die' verbosity $ "filepath wildcard '" ++ filepath diff --git a/Cabal/Distribution/Simple/Install.hs b/Cabal/Distribution/Simple/Install.hs index ce9a2d9fba0..f5c1ab9eb0c 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 "" 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..c214ab62e0b 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 "" + 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"