Skip to content

Commit

Permalink
Fix haskell#7698: cabal sdist works when extra-packages are present
Browse files Browse the repository at this point in the history
  • Loading branch information
phadej authored and mergify-bot committed Oct 6, 2021
1 parent 2ff1535 commit e5ffabc
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 3 deletions.
13 changes: 10 additions & 3 deletions cabal-install/src/Distribution/Client/CmdSdist.hs
Original file line number Diff line number Diff line change
Expand Up @@ -273,9 +273,16 @@ reifyTargetSelectors pkgs sels =
([], sels') -> Right sels'
(errs, _) -> Left errs
where
flatten (SpecificSourcePackage pkg@SourcePackage{}) = pkg
flatten _ = error "The impossible happened: how do we not know about a local package?"
pkgs' = fmap flatten pkgs
-- there can be pkgs which are in extra-packages:
-- these are not SpecificSourcePackage
--
-- Why these packages are in localPkgs, it's confusing.
-- Anyhow, better to be lenient here.
--
flatten (SpecificSourcePackage pkg@SourcePackage{}) = Just pkg
flatten _ = Nothing

pkgs' = mapMaybe flatten pkgs

getPkg pid = case find ((== pid) . packageId) pkgs' of
Just pkg -> Right pkg
Expand Down
2 changes: 2 additions & 0 deletions cabal-testsuite/PackageTests/SDist/T7698/cabal.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# cabal v2-sdist
Wrote source list to <TMPDIR>/t7698-0.list
2 changes: 2 additions & 0 deletions cabal-testsuite/PackageTests/SDist/T7698/cabal.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
packages: pkg/*.cabal
extra-packages: lens
4 changes: 4 additions & 0 deletions cabal-testsuite/PackageTests/SDist/T7698/cabal.test.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import Test.Cabal.Prelude
main = cabalTest $ do
tmpdir <- fmap testTmpDir getTestEnv
cabal "v2-sdist" ["--ignore-project", "--list-only", "--output-directory", tmpdir, "all"]
1 change: 1 addition & 0 deletions cabal-testsuite/PackageTests/SDist/T7698/pkg/Main.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
main = putStrLn "hi"
7 changes: 7 additions & 0 deletions cabal-testsuite/PackageTests/SDist/T7698/pkg/t7698.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
cabal-version: 2.2
name: t7698
version: 0

executable foo
default-language: Haskell2010
main-is: Main.hs
3 changes: 3 additions & 0 deletions changelog.d/issue-7698
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
synopsis: `cabal sdist` works in projects with `extra-packages`
issues: #7698
packages: cabal-install

0 comments on commit e5ffabc

Please sign in to comment.