Skip to content

Commit

Permalink
sdist: don't fall over when data-dir has * in it.
Browse files Browse the repository at this point in the history
Also includes some tests for sdist.
  • Loading branch information
quasicomputational committed Apr 26, 2018
1 parent cb36882 commit bcf1661
Show file tree
Hide file tree
Showing 22 changed files with 100 additions and 2 deletions.
9 changes: 9 additions & 0 deletions Cabal/Distribution/PackageDescription/Check.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions Cabal/Distribution/Simple/SrcDist.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions cabal-install/changelog
Original file line number Diff line number Diff line change
@@ -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).
Expand Down
1 change: 1 addition & 0 deletions cabal-testsuite/PackageTests/SDist/ListSources/Main.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
main = return ()
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
blah
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
blah
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
blah
11 changes: 11 additions & 0 deletions cabal-testsuite/PackageTests/SDist/ListSources/list-sources.cabal
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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'
Original file line number Diff line number Diff line change
@@ -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'
Original file line number Diff line number Diff line change
@@ -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"
1 change: 1 addition & 0 deletions cabal-testsuite/PackageTests/SDist/StarInDataDir/*/a.dat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
blah
1 change: 1 addition & 0 deletions cabal-testsuite/PackageTests/SDist/StarInDataDir/Main.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
main = return ()
1 change: 1 addition & 0 deletions cabal-testsuite/PackageTests/SDist/StarInDataDir/a/a.dat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
blah
Original file line number Diff line number Diff line change
@@ -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'
Original file line number Diff line number Diff line change
@@ -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'
Original file line number Diff line number Diff line change
@@ -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"
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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: <ROOT>/warning-issued.cabal.dist/work/./dist/star-in-data-dir-0.tar.gz
Original file line number Diff line number Diff line change
@@ -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: <ROOT>/warning-issued.dist/work/./dist/star-in-data-dir-0.tar.gz
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import Test.Cabal.Prelude
main = setupAndCabalTest $ do
output <- cabal' "sdist" []
assertOutputContains "Using a '*' character in 'data-dir'" output
1 change: 1 addition & 0 deletions cabal-testsuite/cabal-testsuite.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ library
filepath,
regex-compat-tdfa,
regex-tdfa,
temporary,
text,
Cabal >= 2.3
ghc-options: -Wall -fwarn-tabs
Expand Down

0 comments on commit bcf1661

Please sign in to comment.