Skip to content

Commit 8de7061

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 2acae63 commit 8de7061

File tree

6 files changed

+43
-5
lines changed

6 files changed

+43
-5
lines changed

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

Lines changed: 13 additions & 5 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
@@ -570,7 +569,7 @@ withProject verbosity cliConfig targetStrings installLibs = do
570569
if null unresolvedTargetStrings
571570
then return (parsedPkgSpecs, parsedTargets)
572571
else do
573-
-- Anything that could not be parsed as a packageId (e.g. a pacakge name with not version or
572+
-- Anything that could not be parsed as a packageId (e.g. a package name without a version or
574573
-- a target syntax using colons) must be resolved inside the project context.
575574
(resolvedPkgSpecs, resolvedTargets) <-
576575
resolveTargetSelectorsInProjectBaseContext verbosity baseCtx unresolvedTargetStrings targetFilter
@@ -579,7 +578,7 @@ withProject verbosity cliConfig targetStrings installLibs = do
579578
-- Apply the local configuration (e.g. cli flags) to all direct targets of install command, see note
580579
-- in 'installAction'.
581580
--
582-
-- NOTE: If a target string had to be resolved inside the project conterxt, then pkgSpecs will include
581+
-- NOTE: If a target string had to be resolved inside the project context, then pkgSpecs will include
583582
-- the project packages turned into source distributions (getSpecsAndTargetSelectors does this).
584583
-- We want to apply the local configuration only to the actual targets.
585584
let config =
@@ -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: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# cabal install
2+
Wrote tarball sdist to <ROOT>/cabal.dist/work/./dist/sdist/t8848-1.0.tar.gz
3+
Resolving dependencies...
4+
Build profile: -w ghc-<GHCVER> -O1
5+
In order, the following will be built:
6+
- t8848-1.0 (exe:t8848) (requires build)
7+
Warning: installdir is not defined. Set it in your cabal config file or use --installdir=<path>. Using default installdir: "<ROOT>/cabal.dist/home/.cabal/bin"
8+
Configuring t8848-1.0...
9+
Preprocessing executable 't8848' for t8848-1.0...
10+
Building executable 't8848' for t8848-1.0...
11+
Installing executable t8848 in <PATH>
12+
Warning: The directory <ROOT>/cabal.dist/home/.cabal/store/ghc-<GHCVER>/incoming/new-<RAND><ROOT>/cabal.dist/home/.cabal/store/ghc-<GHCVER>/<PACKAGE>-<HASH>/bin is not in the system search path.
13+
Warning: installdir is not defined. Set it in your cabal config file or use --installdir=<path>. Using default installdir: "<ROOT>/cabal.dist/home/.cabal/bin"
14+
Symlinking 't8848' to '<ROOT>/cabal.dist/home/.cabal/bin/t8848'
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)