From bcf1661b3dd5eb272091f6e2cd2bd47f8d521314 Mon Sep 17 00:00:00 2001 From: quasicomputational Date: Thu, 26 Apr 2018 13:55:49 +0100 Subject: [PATCH] sdist: don't fall over when data-dir has * in it. Also includes some tests for sdist. --- Cabal/Distribution/PackageDescription/Check.hs | 9 +++++++++ Cabal/Distribution/Simple/SrcDist.hs | 4 ++-- cabal-install/changelog | 4 ++++ .../PackageTests/SDist/ListSources/Main.hs | 1 + .../PackageTests/SDist/ListSources/data/blah/a.dat | 1 + .../SDist/ListSources/extra-doc/blah/a.tex | 1 + .../SDist/ListSources/extra-src/blah/a.html | 1 + .../SDist/ListSources/list-sources.cabal | 11 +++++++++++ .../SDist/ListSources/list-sources.cabal.out | 3 +++ .../PackageTests/SDist/ListSources/list-sources.out | 3 +++ .../SDist/ListSources/list-sources.test.hs | 10 ++++++++++ .../PackageTests/SDist/StarInDataDir/*/a.dat | 1 + .../PackageTests/SDist/StarInDataDir/Main.hs | 1 + .../PackageTests/SDist/StarInDataDir/a/a.dat | 1 + .../SDist/StarInDataDir/included-in-sdist.cabal.out | 3 +++ .../SDist/StarInDataDir/included-in-sdist.out | 3 +++ .../SDist/StarInDataDir/included-in-sdist.test.hs | 7 +++++++ .../SDist/StarInDataDir/star-in-data-dir.cabal | 9 +++++++++ .../SDist/StarInDataDir/warning-issued.cabal.out | 12 ++++++++++++ .../SDist/StarInDataDir/warning-issued.out | 12 ++++++++++++ .../SDist/StarInDataDir/warning-issued.test.hs | 4 ++++ cabal-testsuite/cabal-testsuite.cabal | 1 + 22 files changed, 100 insertions(+), 2 deletions(-) create mode 100644 cabal-testsuite/PackageTests/SDist/ListSources/Main.hs create mode 100644 cabal-testsuite/PackageTests/SDist/ListSources/data/blah/a.dat create mode 100644 cabal-testsuite/PackageTests/SDist/ListSources/extra-doc/blah/a.tex create mode 100644 cabal-testsuite/PackageTests/SDist/ListSources/extra-src/blah/a.html create mode 100644 cabal-testsuite/PackageTests/SDist/ListSources/list-sources.cabal create mode 100644 cabal-testsuite/PackageTests/SDist/ListSources/list-sources.cabal.out create mode 100644 cabal-testsuite/PackageTests/SDist/ListSources/list-sources.out create mode 100644 cabal-testsuite/PackageTests/SDist/ListSources/list-sources.test.hs create mode 100644 cabal-testsuite/PackageTests/SDist/StarInDataDir/*/a.dat create mode 100644 cabal-testsuite/PackageTests/SDist/StarInDataDir/Main.hs create mode 100644 cabal-testsuite/PackageTests/SDist/StarInDataDir/a/a.dat create mode 100644 cabal-testsuite/PackageTests/SDist/StarInDataDir/included-in-sdist.cabal.out create mode 100644 cabal-testsuite/PackageTests/SDist/StarInDataDir/included-in-sdist.out create mode 100644 cabal-testsuite/PackageTests/SDist/StarInDataDir/included-in-sdist.test.hs create mode 100644 cabal-testsuite/PackageTests/SDist/StarInDataDir/star-in-data-dir.cabal create mode 100644 cabal-testsuite/PackageTests/SDist/StarInDataDir/warning-issued.cabal.out create mode 100644 cabal-testsuite/PackageTests/SDist/StarInDataDir/warning-issued.out create mode 100644 cabal-testsuite/PackageTests/SDist/StarInDataDir/warning-issued.test.hs diff --git a/Cabal/Distribution/PackageDescription/Check.hs b/Cabal/Distribution/PackageDescription/Check.hs index 58bff466717..ae9be86ae75 100644 --- a/Cabal/Distribution/PackageDescription/Check.hs +++ b/Cabal/Distribution/PackageDescription/Check.hs @@ -1064,6 +1064,15 @@ checkPaths pkg = | pat <- extraDocFiles pkg , Left err <- [parseFileGlob (specVersion pkg) pat] ] + ++ + [ PackageBuildWarning $ + "Using a '*' character in 'data-dir', like " ++ path ++ ", can behave" + ++ " erratically with prior versions of Cabal. It is recommended that you" + ++ " set 'cabal-version: 3.0' to exclude old versions." + | path <- [dataDir pkg] + , specVersion pkg < mkVersion [3,0] + , '*' `elem` path + ] where isOutsideTree path = case splitDirectories path of "..":_ -> True diff --git a/Cabal/Distribution/Simple/SrcDist.hs b/Cabal/Distribution/Simple/SrcDist.hs index a9271031986..0cf6fdfb7d1 100644 --- a/Cabal/Distribution/Simple/SrcDist.hs +++ b/Cabal/Distribution/Simple/SrcDist.hs @@ -208,8 +208,8 @@ listPackageSourcesOrdinary verbosity pkg_descr pps = -- Data files. , fmap concat - . for (dataFiles pkg_descr) $ \filename -> - matchFileGlob verbosity (specVersion pkg_descr) (dataDir pkg_descr filename) + . for (dataFiles pkg_descr) $ \ filename -> fmap (fmap (dataDir pkg_descr )) $ + matchDirFileGlob verbosity (specVersion pkg_descr) (dataDir pkg_descr) filename -- Extra doc files. , fmap concat diff --git a/cabal-install/changelog b/cabal-install/changelog index 4cf826f8761..0bfc548ad18 100644 --- a/cabal-install/changelog +++ b/cabal-install/changelog @@ -1,5 +1,9 @@ -*-change-log-*- +2.3.0.0 (current development version) + * `cabal sdist` would error out when `data-dir` included `*` + characters. These are now correctly treated as inert. + 2.2.0.0 (current development version) * '--with-PROG' and '--PROG-options' are applied to all packages and not local packages only (#5019). diff --git a/cabal-testsuite/PackageTests/SDist/ListSources/Main.hs b/cabal-testsuite/PackageTests/SDist/ListSources/Main.hs new file mode 100644 index 00000000000..b3549c2fe3d --- /dev/null +++ b/cabal-testsuite/PackageTests/SDist/ListSources/Main.hs @@ -0,0 +1 @@ +main = return () diff --git a/cabal-testsuite/PackageTests/SDist/ListSources/data/blah/a.dat b/cabal-testsuite/PackageTests/SDist/ListSources/data/blah/a.dat new file mode 100644 index 00000000000..907b308167f --- /dev/null +++ b/cabal-testsuite/PackageTests/SDist/ListSources/data/blah/a.dat @@ -0,0 +1 @@ +blah diff --git a/cabal-testsuite/PackageTests/SDist/ListSources/extra-doc/blah/a.tex b/cabal-testsuite/PackageTests/SDist/ListSources/extra-doc/blah/a.tex new file mode 100644 index 00000000000..907b308167f --- /dev/null +++ b/cabal-testsuite/PackageTests/SDist/ListSources/extra-doc/blah/a.tex @@ -0,0 +1 @@ +blah diff --git a/cabal-testsuite/PackageTests/SDist/ListSources/extra-src/blah/a.html b/cabal-testsuite/PackageTests/SDist/ListSources/extra-src/blah/a.html new file mode 100644 index 00000000000..907b308167f --- /dev/null +++ b/cabal-testsuite/PackageTests/SDist/ListSources/extra-src/blah/a.html @@ -0,0 +1 @@ +blah diff --git a/cabal-testsuite/PackageTests/SDist/ListSources/list-sources.cabal b/cabal-testsuite/PackageTests/SDist/ListSources/list-sources.cabal new file mode 100644 index 00000000000..c0c0abfb781 --- /dev/null +++ b/cabal-testsuite/PackageTests/SDist/ListSources/list-sources.cabal @@ -0,0 +1,11 @@ +cabal-version: 2.2 +name: list-sources +version: 0 +data-dir: data +data-files: blah/*.dat +extra-source-files: extra-src/blah/*.html +extra-doc-files: extra-doc/blah/*.tex + +executable dummy + default-language: Haskell2010 + main-is: Main.hs diff --git a/cabal-testsuite/PackageTests/SDist/ListSources/list-sources.cabal.out b/cabal-testsuite/PackageTests/SDist/ListSources/list-sources.cabal.out new file mode 100644 index 00000000000..ebcbe2d50c8 --- /dev/null +++ b/cabal-testsuite/PackageTests/SDist/ListSources/list-sources.cabal.out @@ -0,0 +1,3 @@ +# cabal sdist +List of package sources written to file '/tmp/cabal-testsuite.included-in-sdist-c1023f76/sources' +List of package sources written to file '/tmp/cabal-testsuite.included-in-sdist-c1023f76/sources' diff --git a/cabal-testsuite/PackageTests/SDist/ListSources/list-sources.out b/cabal-testsuite/PackageTests/SDist/ListSources/list-sources.out new file mode 100644 index 00000000000..86c7854f2ed --- /dev/null +++ b/cabal-testsuite/PackageTests/SDist/ListSources/list-sources.out @@ -0,0 +1,3 @@ +# cabal sdist +List of package sources written to file '/tmp/cabal-testsuite.included-in-sdist-cfee5f8f/sources' +List of package sources written to file '/tmp/cabal-testsuite.included-in-sdist-cfee5f8f/sources' diff --git a/cabal-testsuite/PackageTests/SDist/ListSources/list-sources.test.hs b/cabal-testsuite/PackageTests/SDist/ListSources/list-sources.test.hs new file mode 100644 index 00000000000..031d47fc86b --- /dev/null +++ b/cabal-testsuite/PackageTests/SDist/ListSources/list-sources.test.hs @@ -0,0 +1,10 @@ +import Control.Monad.IO.Class +import System.IO.Temp (withSystemTempDirectory) +import Test.Cabal.Prelude +main = setupAndCabalTest $ withSystemTempDirectory "cabal-testsuite.included-in-sdist" $ \dir -> do + let fn = dir "sources" + cabal "sdist" ["--list-sources=" ++ fn] + liftIO $ putStrLn =<< readFile fn + assertFileDoesContain fn "data/blah/a.dat" + assertFileDoesContain fn "extra-src/blah/a.html" + assertFileDoesContain fn "extra-doc/blah/a.tex" diff --git a/cabal-testsuite/PackageTests/SDist/StarInDataDir/*/a.dat b/cabal-testsuite/PackageTests/SDist/StarInDataDir/*/a.dat new file mode 100644 index 00000000000..907b308167f --- /dev/null +++ b/cabal-testsuite/PackageTests/SDist/StarInDataDir/*/a.dat @@ -0,0 +1 @@ +blah diff --git a/cabal-testsuite/PackageTests/SDist/StarInDataDir/Main.hs b/cabal-testsuite/PackageTests/SDist/StarInDataDir/Main.hs new file mode 100644 index 00000000000..b3549c2fe3d --- /dev/null +++ b/cabal-testsuite/PackageTests/SDist/StarInDataDir/Main.hs @@ -0,0 +1 @@ +main = return () diff --git a/cabal-testsuite/PackageTests/SDist/StarInDataDir/a/a.dat b/cabal-testsuite/PackageTests/SDist/StarInDataDir/a/a.dat new file mode 100644 index 00000000000..907b308167f --- /dev/null +++ b/cabal-testsuite/PackageTests/SDist/StarInDataDir/a/a.dat @@ -0,0 +1 @@ +blah diff --git a/cabal-testsuite/PackageTests/SDist/StarInDataDir/included-in-sdist.cabal.out b/cabal-testsuite/PackageTests/SDist/StarInDataDir/included-in-sdist.cabal.out new file mode 100644 index 00000000000..e357cf5db51 --- /dev/null +++ b/cabal-testsuite/PackageTests/SDist/StarInDataDir/included-in-sdist.cabal.out @@ -0,0 +1,3 @@ +# cabal sdist +List of package sources written to file '/tmp/cabal-testsuite.included-in-sdist-dfad8f7a/sources' +List of package sources written to file '/tmp/cabal-testsuite.included-in-sdist-dfad8f7a/sources' diff --git a/cabal-testsuite/PackageTests/SDist/StarInDataDir/included-in-sdist.out b/cabal-testsuite/PackageTests/SDist/StarInDataDir/included-in-sdist.out new file mode 100644 index 00000000000..99e910eb536 --- /dev/null +++ b/cabal-testsuite/PackageTests/SDist/StarInDataDir/included-in-sdist.out @@ -0,0 +1,3 @@ +# cabal sdist +List of package sources written to file '/tmp/cabal-testsuite.included-in-sdist-2540730b/sources' +List of package sources written to file '/tmp/cabal-testsuite.included-in-sdist-2540730b/sources' diff --git a/cabal-testsuite/PackageTests/SDist/StarInDataDir/included-in-sdist.test.hs b/cabal-testsuite/PackageTests/SDist/StarInDataDir/included-in-sdist.test.hs new file mode 100644 index 00000000000..698db67d83b --- /dev/null +++ b/cabal-testsuite/PackageTests/SDist/StarInDataDir/included-in-sdist.test.hs @@ -0,0 +1,7 @@ +import System.IO.Temp (withSystemTempDirectory) +import Test.Cabal.Prelude +main = setupAndCabalTest $ withSystemTempDirectory "cabal-testsuite.included-in-sdist" $ \dir -> do + let fn = dir "sources" + cabal "sdist" ["--list-sources=" ++ fn] + assertFileDoesContain fn "*/a.dat" + assertFileDoesNotContain fn "a/a.dat" diff --git a/cabal-testsuite/PackageTests/SDist/StarInDataDir/star-in-data-dir.cabal b/cabal-testsuite/PackageTests/SDist/StarInDataDir/star-in-data-dir.cabal new file mode 100644 index 00000000000..3429629b2b1 --- /dev/null +++ b/cabal-testsuite/PackageTests/SDist/StarInDataDir/star-in-data-dir.cabal @@ -0,0 +1,9 @@ +cabal-version: 2.2 +name: star-in-data-dir +version: 0 +data-dir: * +data-files: *.dat + +executable dummy + default-language: Haskell2010 + main-is: Main.hs diff --git a/cabal-testsuite/PackageTests/SDist/StarInDataDir/warning-issued.cabal.out b/cabal-testsuite/PackageTests/SDist/StarInDataDir/warning-issued.cabal.out new file mode 100644 index 00000000000..2f594958dda --- /dev/null +++ b/cabal-testsuite/PackageTests/SDist/StarInDataDir/warning-issued.cabal.out @@ -0,0 +1,12 @@ +# cabal sdist +Distribution quality errors: +No 'synopsis' or 'description' field. +The 'license' field is missing or is NONE. +Using a '*' character in 'data-dir', like *, can behave erratically with prior versions of Cabal. It is recommended that you set 'cabal-version: 3.0' to exclude old versions. +Distribution quality warnings: +No 'category' field. +No 'maintainer' field. +Note: the public hackage server would reject this package. +Warning: Cannot run preprocessors. Run 'configure' command first. +Building source dist for star-in-data-dir-0... +Source tarball created: /warning-issued.cabal.dist/work/./dist/star-in-data-dir-0.tar.gz diff --git a/cabal-testsuite/PackageTests/SDist/StarInDataDir/warning-issued.out b/cabal-testsuite/PackageTests/SDist/StarInDataDir/warning-issued.out new file mode 100644 index 00000000000..6216a966eb2 --- /dev/null +++ b/cabal-testsuite/PackageTests/SDist/StarInDataDir/warning-issued.out @@ -0,0 +1,12 @@ +# cabal sdist +Distribution quality errors: +No 'synopsis' or 'description' field. +The 'license' field is missing or is NONE. +Using a '*' character in 'data-dir', like *, can behave erratically with prior versions of Cabal. It is recommended that you set 'cabal-version: 3.0' to exclude old versions. +Distribution quality warnings: +No 'category' field. +No 'maintainer' field. +Note: the public hackage server would reject this package. +Warning: Cannot run preprocessors. Run 'configure' command first. +Building source dist for star-in-data-dir-0... +Source tarball created: /warning-issued.dist/work/./dist/star-in-data-dir-0.tar.gz diff --git a/cabal-testsuite/PackageTests/SDist/StarInDataDir/warning-issued.test.hs b/cabal-testsuite/PackageTests/SDist/StarInDataDir/warning-issued.test.hs new file mode 100644 index 00000000000..68fe11b6dda --- /dev/null +++ b/cabal-testsuite/PackageTests/SDist/StarInDataDir/warning-issued.test.hs @@ -0,0 +1,4 @@ +import Test.Cabal.Prelude +main = setupAndCabalTest $ do + output <- cabal' "sdist" [] + assertOutputContains "Using a '*' character in 'data-dir'" output diff --git a/cabal-testsuite/cabal-testsuite.cabal b/cabal-testsuite/cabal-testsuite.cabal index 05604c69e19..bcbe695b7e3 100644 --- a/cabal-testsuite/cabal-testsuite.cabal +++ b/cabal-testsuite/cabal-testsuite.cabal @@ -45,6 +45,7 @@ library filepath, regex-compat-tdfa, regex-tdfa, + temporary, text, Cabal >= 2.3 ghc-options: -Wall -fwarn-tabs