Skip to content

Commit

Permalink
Make Setup.hs copy/install work when data-files uses **. (#6127)
Browse files Browse the repository at this point in the history
Treating globs like filenames was always illegitimate, but this code
was broken further by the addition of recursive globs.

I had a look around for other dubious code along these lines, and it
looks like this site is the only problematic one.

Fixes #6125.
  • Loading branch information
quasicomputational authored Jul 3, 2019
1 parent ed3ae13 commit 7fec503
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 7 deletions.
3 changes: 3 additions & 0 deletions Cabal/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
* Uniformly provide 'Semigroup' instances for `base < 4.9` via `semigroups` package
* Setting `debug-info` now implies `library-stripping: False` and
`executable-stripping: False) ([#2702](https://github.com/haskell/cabal/issues/2702))
* `Setup.hs copy` and `install` now work in the presence of
`data-files` that use `**` syntax
([#6125](https://github.com/haskell/cabal/issues/6125)).

----

Expand Down
14 changes: 7 additions & 7 deletions Cabal/Distribution/Simple/Install.hs
Original file line number Diff line number Diff line change
Expand Up @@ -223,17 +223,17 @@ copyComponent _ _ _ (CTest _) _ _ = return ()
--
installDataFiles :: Verbosity -> PackageDescription -> FilePath -> IO ()
installDataFiles verbosity pkg_descr destDataDir =
flip traverse_ (dataFiles pkg_descr) $ \ file -> do
flip traverse_ (dataFiles pkg_descr) $ \ glob -> do
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)
sequence_ [ installOrdinaryFile verbosity (srcDataDir </> file')
(destDataDir </> file')
| file' <- files ]
files <- matchDirFileGlob verbosity (specVersion pkg_descr) srcDataDir glob
for_ files $ \ file' -> do
let src = srcDataDir </> file'
dst = destDataDir </> file'
createDirectoryIfMissingVerbose verbosity True (takeDirectory dst)
installOrdinaryFile verbosity src dst

-- | Install the files listed in install-includes for a library
--
Expand Down
1 change: 1 addition & 0 deletions cabal-testsuite/PackageTests/Regression/T6125/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 @@
<!DOCTYPE html>Some random data.
9 changes: 9 additions & 0 deletions cabal-testsuite/PackageTests/Regression/T6125/myprog.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
cabal-version: 2.4
name: myprog
version: 0
data-files: data/**/*.html

executable myprog
build-depends: base
main-is: Main.hs
default-language: Haskell2010
9 changes: 9 additions & 0 deletions cabal-testsuite/PackageTests/Regression/T6125/setup.cabal.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Setup configure
Resolving dependencies...
Configuring myprog-0...
# Setup build
Preprocessing executable 'myprog' for myprog-0..
Building executable 'myprog' for myprog-0..
# Setup copy
Installing executable myprog in <PATH>
Warning: The directory <ROOT>/setup.cabal.dist/usr/bin is not in the system search path.
8 changes: 8 additions & 0 deletions cabal-testsuite/PackageTests/Regression/T6125/setup.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Setup configure
Configuring myprog-0...
# Setup build
Preprocessing executable 'myprog' for myprog-0..
Building executable 'myprog' for myprog-0..
# Setup copy
Installing executable myprog in <PATH>
Warning: The directory <ROOT>/setup.dist/usr/bin is not in the system search path.
6 changes: 6 additions & 0 deletions cabal-testsuite/PackageTests/Regression/T6125/setup.test.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import Test.Cabal.Prelude
main = setupAndCabalTest $ do
withPackageDb $ do
setup "configure" []
setup "build" ["myprog"]
setup "copy" ["myprog"]

4 comments on commit 7fec503

@phadej
Copy link
Collaborator

@phadej phadej commented on 7fec503 Jul 3, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that pushing directly to master when one adds test should be prohibited.

I reverted this commit. Make a PR and make the CI spin.

@phadej
Copy link
Collaborator

@phadej phadej commented on 7fec503 Jul 3, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Argh, I reverted my revert. Why there weren't merge commit? It's very confusing.

@quasicomputational
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh. I just pressed the default merge button, which was to squash. If we don't want to allow that, it can be turned off somewhere in the settings. (Maybe it was previously?)

@23Skidoo
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Squash is sometimes useful, but merge should be the default. I think GitHub remembers the last type of merge action you used.

Please sign in to comment.