Skip to content

Commit

Permalink
Consider Installed packages when pruning the install plan
Browse files Browse the repository at this point in the history
The discussion in haskell#6952 indicated that extra-packages stanzas wouldn't
quite work yet. It turns out in order for cabal to find exes for
already installed extra-packages we need to also consider `installed`
packages when pruning the install plan.

Includes some changes to OutputNormalizer
  • Loading branch information
Alex Biehl authored and hololeap committed Apr 24, 2022
1 parent c3e8cb2 commit 4c45933
Show file tree
Hide file tree
Showing 10 changed files with 66 additions and 11 deletions.
26 changes: 16 additions & 10 deletions cabal-install/src/Distribution/Client/ProjectPlanning.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2680,16 +2680,22 @@ pruneInstallPlanPass1 pkgs =
setDocumentation
$ addOptionalStanzas elab

find_root (InstallPlan.Configured (PrunedPackage elab _)) =
if not $ and [ null (elabConfigureTargets elab)
, null (elabBuildTargets elab)
, null (elabTestTargets elab)
, null (elabBenchTargets elab)
, isNothing (elabReplTarget elab)
, null (elabHaddockTargets elab)
]
then Just (installedUnitId elab)
else Nothing
is_root :: PrunedPackage -> Maybe UnitId
is_root (PrunedPackage elab _) =
if not $ and [ null (elabConfigureTargets elab)
, null (elabBuildTargets elab)
, null (elabTestTargets elab)
, null (elabBenchTargets elab)
, isNothing (elabReplTarget elab)
, null (elabHaddockTargets elab)
]
then Just (installedUnitId elab)
else Nothing

find_root (InstallPlan.Configured pkg) = is_root pkg
-- When using the extra-packages stanza we need to
-- look at installed packages as well.
find_root (InstallPlan.Installed pkg) = is_root pkg
find_root _ = Nothing

-- Note [Sticky enabled testsuites]
Expand Down
1 change: 1 addition & 0 deletions cabal-testsuite/PackageTests/ExtraPackages/Foo.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module Foo where
12 changes: 12 additions & 0 deletions cabal-testsuite/PackageTests/ExtraPackages/cabal.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# cabal v2-update
Downloading the latest package list from test-local-repo
# cabal v2-run
Resolving dependencies...
Build profile: -w ghc-<GHCVER> -O1
In order, the following will be built:
- some-exe-0.0.1.0 (exe:some-exe) (requires build)
Configuring some-exe-0.0.1.0...
Preprocessing executable 'some-exe' for some-exe-0.0.1.0..
Building executable 'some-exe' for some-exe-0.0.1.0..
Installing executable some-exe 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.
2 changes: 2 additions & 0 deletions cabal-testsuite/PackageTests/ExtraPackages/cabal.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
packages: .
extra-packages: some-exe
3 changes: 3 additions & 0 deletions cabal-testsuite/PackageTests/ExtraPackages/cabal.test.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import Test.Cabal.Prelude
main = cabalTest $ withRepo "repo" $ do
cabal "v2-run" [ "some-exe" ]
9 changes: 9 additions & 0 deletions cabal-testsuite/PackageTests/ExtraPackages/my.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name: my
version: 0.1
license: BSD3
cabal-version: >= 1.2
build-type: Simple

library
exposed-modules: Foo
build-depends: base
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module Main where

main :: IO ()
main = putStrLn "hello world"
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name: some-exe
version: 0.0.1.0
license: BSD3
cabal-version: >= 1.2
build-type: Simple

Executable some-exe
main-is: Main.hs
build-depends: base
8 changes: 7 additions & 1 deletion cabal-testsuite/src/Test/Cabal/OutputNormalizer.hs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,13 @@ normalizeOutput nenv =
. resub "Installing (.+) in .+" "Installing \\1 in <PATH>"
-- Things that look like libraries
. resub "libHS[A-Za-z0-9.-]+\\.(so|dll|a|dynlib)" "<LIBRARY>"
-- look for PackageHash directories
. resub "/(([A-Za-z0-9_]+)(-[A-Za-z0-9\\._]+)*)-[0-9a-f]{4,64}/"
"/<PACKAGE>-<HASH>/"
-- This is dumb but I don't feel like pulling in another dep for
-- string search-replace. Make sure we do this before backslash
-- normalization!
. resub (posixRegexEscape (normalizerGblTmpDir nenv) ++ "[a-z0-9.-]+") "<GBLTMPDIR>" -- note, after TMPDIR
. resub (posixRegexEscape (normalizerGblTmpDir nenv) ++ "[a-z0-9\\.-]+") "<GBLTMPDIR>" -- note, after TMPDIR
. resub (posixRegexEscape (normalizerRoot nenv)) "<ROOT>/"
. resub (posixRegexEscape (normalizerTmpDir nenv)) "<TMPDIR>/"
. appEndo (F.fold (map (Endo . packageIdRegex) (normalizerKnownPackages nenv)))
Expand All @@ -39,6 +42,9 @@ normalizeOutput nenv =
-- Apply this before packageIdRegex, otherwise this regex doesn't match.
. resub "[0-9]+(\\.[0-9]+)*/installed-[A-Za-z0-9.+]+"
"<VERSION>/installed-<HASH>"
-- incoming directories in the store
. resub "/incoming/new-[0-9]+"
"/incoming/new-<RAND>"
-- Normalize architecture
. resub (posixRegexEscape (display (normalizerPlatform nenv))) "<ARCH>"
-- Some GHC versions are chattier than others
Expand Down
3 changes: 3 additions & 0 deletions changelog.d/pr-6972
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
synopsis: Make extra-packages work properly
packages: cabal-install
prs: #6972

0 comments on commit 4c45933

Please sign in to comment.