Skip to content

Commit b5ac2f7

Browse files
authored
Merge pull request #9875 from haskell/mergify/bp/3.12/pr-9719
Fix cabal install in the presence of extra-packages (backport #9719)
2 parents 5ab8bf8 + f5e8e60 commit b5ac2f7

File tree

5 files changed

+30
-5
lines changed

5 files changed

+30
-5
lines changed

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

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -470,8 +470,7 @@ installAction flags@NixStyleFlags{extraFlags, configFlags, installFlags, project
470470

471471
-- check for targets already in env
472472
let getPackageName :: PackageSpecifier UnresolvedSourcePackage -> PackageName
473-
getPackageName (NamedPackage pn _) = pn
474-
getPackageName (SpecificSourcePackage (SourcePackage pkgId _ _ _)) = pkgName pkgId
473+
getPackageName = pkgSpecifierTarget
475474
targetNames = S.fromList $ map getPackageName (pkgSpecs ++ uriSpecs)
476475
envNames = S.fromList $ map getPackageName envSpecs
477476
forceInstall = fromFlagOrDefault False $ installOverrideReinstall installFlags
@@ -571,7 +570,7 @@ withProject verbosity cliConfig targetStrings installLibs = do
571570
if null unresolvedTargetStrings
572571
then return (parsedPkgSpecs, parsedTargets)
573572
else do
574-
-- Anything that could not be parsed as a packageId (e.g. a pacakge name with not version or
573+
-- Anything that could not be parsed as a packageId (e.g. a package name without a version or
575574
-- a target syntax using colons) must be resolved inside the project context.
576575
(resolvedPkgSpecs, resolvedTargets) <-
577576
resolveTargetSelectorsInProjectBaseContext verbosity baseCtx unresolvedTargetStrings targetFilter
@@ -580,7 +579,7 @@ withProject verbosity cliConfig targetStrings installLibs = do
580579
-- Apply the local configuration (e.g. cli flags) to all direct targets of install command, see note
581580
-- in 'installAction'.
582581
--
583-
-- NOTE: If a target string had to be resolved inside the project conterxt, then pkgSpecs will include
582+
-- NOTE: If a target string had to be resolved inside the project context, then pkgSpecs will include
584583
-- the project packages turned into source distributions (getSpecsAndTargetSelectors does this).
585584
-- We want to apply the local configuration only to the actual targets.
586585
let config =
@@ -797,7 +796,16 @@ getSpecsAndTargetSelectors verbosity reducedVerbosity sourcePkgDb targetSelector
797796
TarGzArchive
798797
(distSdistFile distDirLayout (packageId pkg))
799798
pkg
800-
NamedPackage pkgName _ -> error $ "Got NamedPackage " ++ prettyShow pkgName
799+
NamedPackage _ _ ->
800+
-- This may happen if 'extra-packages' are listed in the project file.
801+
-- We don't need to do extra work for NamedPackages since they will be
802+
-- fetched from Hackage rather than locally 'sdistize'-d. Note how,
803+
-- below, we already return the local 'sdistize'-d packages together
804+
-- with the 'hackagePkgs' (which are 'NamedPackage's), and that
805+
-- 'sdistize' is a no-op for 'NamedPackages', meaning the
806+
-- 'NamedPackage's in 'localPkgs' will be treated just like
807+
-- 'hackagePkgs' as they should.
808+
pure ()
801809

802810
if null targetsMap
803811
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: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import Test.Cabal.Prelude
2+
3+
main = cabalTest $ do
4+
recordMode DoNotRecord $
5+
cabal' "install" ["t8848"]
6+
>>= 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)