Skip to content

Commit 42af3e5

Browse files
committed
Fix cabal-install in the presence of extra-packages
Extra-packages listed in a cabal project are to be fetched from hackage, and will be in memory as 'NamedPackages' rather than resolved to 'SpecificSourcePackage'. On install, we need to make source-dists for all the specific source packages, and fetch other packages from hackage. Since extra-packages are already 'NamedPackages', we simply return them along the sdistize-d specific source packages and the hackage source packages -- they will be correctly fetched from Hackage from install. Previously, cabal install <tgt> on a project with extra-packages would fail because the branch of 'NamedPackage' for 'PackageSpecifier' was simply unimplemented. Fixes #8848
1 parent 656d06b commit 42af3e5

File tree

5 files changed

+27
-3
lines changed

5 files changed

+27
-3
lines changed

cabal-install/src/Distribution/Client/CmdInstall.hs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -469,8 +469,7 @@ installAction flags@NixStyleFlags{extraFlags, configFlags, installFlags, project
469469

470470
-- check for targets already in env
471471
let getPackageName :: PackageSpecifier UnresolvedSourcePackage -> PackageName
472-
getPackageName (NamedPackage pn _) = pn
473-
getPackageName (SpecificSourcePackage (SourcePackage pkgId _ _ _)) = pkgName pkgId
472+
getPackageName = pkgSpecifierTarget
474473
targetNames = S.fromList $ map getPackageName (pkgSpecs ++ uriSpecs)
475474
envNames = S.fromList $ map getPackageName envSpecs
476475
forceInstall = fromFlagOrDefault False $ installOverrideReinstall installFlags
@@ -796,7 +795,16 @@ getSpecsAndTargetSelectors verbosity reducedVerbosity sourcePkgDb targetSelector
796795
TarGzArchive
797796
(distSdistFile distDirLayout (packageId pkg))
798797
pkg
799-
NamedPackage pkgName _ -> error $ "Got NamedPackage " ++ prettyShow pkgName
798+
NamedPackage _ _ ->
799+
-- This may happen if 'extra-packages' are listed in the project file.
800+
-- We don't need to do extra work for NamedPackages since they will be
801+
-- fetched from Hackage rather than locally 'sdistize'-d. Note how,
802+
-- below, we already return the local 'sdistize'-d packages together
803+
-- with the 'hackagePkgs' (which are 'NamedPackage's), and that
804+
-- 'sdistize' is a no-op for 'NamedPackages', meaning the
805+
-- 'NamedPackage's in 'localPkgs' will be treated just like
806+
-- 'hackagePkgs' as they should.
807+
pure ()
800808

801809
if null targetsMap
802810
then return (hackagePkgs, hackageTargets)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
main = pure ()
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
packages: .
2+
extra-packages: containers
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import Test.Cabal.Prelude
2+
3+
main = cabalTest $ do
4+
cabal' "install" ["t8848"]
5+
>>= assertOutputContains "Wrote tarball sdist to"
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
name: t8848
2+
version: 1.0
3+
build-type: Simple
4+
cabal-version: >= 1.2
5+
6+
executable t8848
7+
main-is: Main.hs
8+
build-depends: base

0 commit comments

Comments
 (0)