Skip to content

Commit

Permalink
Fix cabal-install in the presence of extra-packages
Browse files Browse the repository at this point in the history
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
  • Loading branch information
alt-romes committed Feb 16, 2024
1 parent 656d06b commit c58174b
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 3 deletions.
14 changes: 11 additions & 3 deletions cabal-install/src/Distribution/Client/CmdInstall.hs
Original file line number Diff line number Diff line change
Expand Up @@ -469,8 +469,7 @@ installAction flags@NixStyleFlags{extraFlags, configFlags, installFlags, project

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

if null targetsMap
then return (hackagePkgs, hackageTargets)
Expand Down
1 change: 1 addition & 0 deletions cabal-testsuite/PackageTests/Install/T8848/Main.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
main = pure ()
14 changes: 14 additions & 0 deletions cabal-testsuite/PackageTests/Install/T8848/cabal.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# cabal install
Wrote tarball sdist to <ROOT>/cabal.dist/work/./dist/sdist/t8848-1.0.tar.gz
Resolving dependencies...
Build profile: -w ghc-<GHCVER> -O1
In order, the following will be built:
- t8848-1.0 (exe:t8848) (requires build)
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"
Configuring t8848-1.0...
Preprocessing executable 't8848' for t8848-1.0...
Building executable 't8848' for t8848-1.0...
Installing executable t8848 in <PATH>
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.
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"
Symlinking 't8848' to '<ROOT>/cabal.dist/home/.cabal/bin/t8848'
2 changes: 2 additions & 0 deletions cabal-testsuite/PackageTests/Install/T8848/cabal.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
packages: .
extra-packages: containers
5 changes: 5 additions & 0 deletions cabal-testsuite/PackageTests/Install/T8848/cabal.test.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import Test.Cabal.Prelude

main = cabalTest $ do
cabal' "install" ["t8848"]
>>= assertOutputContains "Wrote tarball sdist to"
8 changes: 8 additions & 0 deletions cabal-testsuite/PackageTests/Install/T8848/t8848.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
name: t8848
version: 1.0
build-type: Simple
cabal-version: >= 1.2

executable t8848
main-is: Main.hs
build-depends: base

0 comments on commit c58174b

Please sign in to comment.