From e5ffabc4c09f83ec46f156116878987bf91506d0 Mon Sep 17 00:00:00 2001 From: Oleg Grenrus Date: Mon, 4 Oct 2021 15:28:42 +0300 Subject: [PATCH] Fix #7698: cabal sdist works when extra-packages are present --- cabal-install/src/Distribution/Client/CmdSdist.hs | 13 ++++++++++--- cabal-testsuite/PackageTests/SDist/T7698/cabal.out | 2 ++ .../PackageTests/SDist/T7698/cabal.project | 2 ++ .../PackageTests/SDist/T7698/cabal.test.hs | 4 ++++ .../PackageTests/SDist/T7698/pkg/Main.hs | 1 + .../PackageTests/SDist/T7698/pkg/t7698.cabal | 7 +++++++ changelog.d/issue-7698 | 3 +++ 7 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 cabal-testsuite/PackageTests/SDist/T7698/cabal.out create mode 100644 cabal-testsuite/PackageTests/SDist/T7698/cabal.project create mode 100644 cabal-testsuite/PackageTests/SDist/T7698/cabal.test.hs create mode 100644 cabal-testsuite/PackageTests/SDist/T7698/pkg/Main.hs create mode 100644 cabal-testsuite/PackageTests/SDist/T7698/pkg/t7698.cabal create mode 100644 changelog.d/issue-7698 diff --git a/cabal-install/src/Distribution/Client/CmdSdist.hs b/cabal-install/src/Distribution/Client/CmdSdist.hs index 24d38f19b68..d4f87074a2a 100644 --- a/cabal-install/src/Distribution/Client/CmdSdist.hs +++ b/cabal-install/src/Distribution/Client/CmdSdist.hs @@ -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 diff --git a/cabal-testsuite/PackageTests/SDist/T7698/cabal.out b/cabal-testsuite/PackageTests/SDist/T7698/cabal.out new file mode 100644 index 00000000000..f04864ea871 --- /dev/null +++ b/cabal-testsuite/PackageTests/SDist/T7698/cabal.out @@ -0,0 +1,2 @@ +# cabal v2-sdist +Wrote source list to /t7698-0.list diff --git a/cabal-testsuite/PackageTests/SDist/T7698/cabal.project b/cabal-testsuite/PackageTests/SDist/T7698/cabal.project new file mode 100644 index 00000000000..9c5b1f14c54 --- /dev/null +++ b/cabal-testsuite/PackageTests/SDist/T7698/cabal.project @@ -0,0 +1,2 @@ +packages: pkg/*.cabal +extra-packages: lens diff --git a/cabal-testsuite/PackageTests/SDist/T7698/cabal.test.hs b/cabal-testsuite/PackageTests/SDist/T7698/cabal.test.hs new file mode 100644 index 00000000000..acd42461a38 --- /dev/null +++ b/cabal-testsuite/PackageTests/SDist/T7698/cabal.test.hs @@ -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"] diff --git a/cabal-testsuite/PackageTests/SDist/T7698/pkg/Main.hs b/cabal-testsuite/PackageTests/SDist/T7698/pkg/Main.hs new file mode 100644 index 00000000000..4233a67ecdd --- /dev/null +++ b/cabal-testsuite/PackageTests/SDist/T7698/pkg/Main.hs @@ -0,0 +1 @@ +main = putStrLn "hi" diff --git a/cabal-testsuite/PackageTests/SDist/T7698/pkg/t7698.cabal b/cabal-testsuite/PackageTests/SDist/T7698/pkg/t7698.cabal new file mode 100644 index 00000000000..eed041d7ef2 --- /dev/null +++ b/cabal-testsuite/PackageTests/SDist/T7698/pkg/t7698.cabal @@ -0,0 +1,7 @@ +cabal-version: 2.2 +name: t7698 +version: 0 + +executable foo + default-language: Haskell2010 + main-is: Main.hs diff --git a/changelog.d/issue-7698 b/changelog.d/issue-7698 new file mode 100644 index 00000000000..4e136cabfcf --- /dev/null +++ b/changelog.d/issue-7698 @@ -0,0 +1,3 @@ +synopsis: `cabal sdist` works in projects with `extra-packages` +issues: #7698 +packages: cabal-install