From 4c4593347d517b45f0a4e09c585f64447b1a43cc Mon Sep 17 00:00:00 2001 From: Alex Biehl Date: Sun, 19 Jul 2020 17:02:47 +0200 Subject: [PATCH] Consider Installed packages when pruning the install plan The discussion in #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 --- .../Distribution/Client/ProjectPlanning.hs | 26 ++++++++++++------- .../PackageTests/ExtraPackages/Foo.hs | 1 + .../PackageTests/ExtraPackages/cabal.out | 12 +++++++++ .../PackageTests/ExtraPackages/cabal.project | 2 ++ .../PackageTests/ExtraPackages/cabal.test.hs | 3 +++ .../PackageTests/ExtraPackages/my.cabal | 9 +++++++ .../repo/some-exe-0.0.1.0/Main.hs | 4 +++ .../repo/some-exe-0.0.1.0/some-exe.cabal | 9 +++++++ .../src/Test/Cabal/OutputNormalizer.hs | 8 +++++- changelog.d/pr-6972 | 3 +++ 10 files changed, 66 insertions(+), 11 deletions(-) create mode 100644 cabal-testsuite/PackageTests/ExtraPackages/Foo.hs create mode 100644 cabal-testsuite/PackageTests/ExtraPackages/cabal.out create mode 100644 cabal-testsuite/PackageTests/ExtraPackages/cabal.project create mode 100644 cabal-testsuite/PackageTests/ExtraPackages/cabal.test.hs create mode 100644 cabal-testsuite/PackageTests/ExtraPackages/my.cabal create mode 100644 cabal-testsuite/PackageTests/ExtraPackages/repo/some-exe-0.0.1.0/Main.hs create mode 100644 cabal-testsuite/PackageTests/ExtraPackages/repo/some-exe-0.0.1.0/some-exe.cabal create mode 100644 changelog.d/pr-6972 diff --git a/cabal-install/src/Distribution/Client/ProjectPlanning.hs b/cabal-install/src/Distribution/Client/ProjectPlanning.hs index 9f63d15ecf9..52cf897c29e 100644 --- a/cabal-install/src/Distribution/Client/ProjectPlanning.hs +++ b/cabal-install/src/Distribution/Client/ProjectPlanning.hs @@ -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] diff --git a/cabal-testsuite/PackageTests/ExtraPackages/Foo.hs b/cabal-testsuite/PackageTests/ExtraPackages/Foo.hs new file mode 100644 index 00000000000..efbf93bbde8 --- /dev/null +++ b/cabal-testsuite/PackageTests/ExtraPackages/Foo.hs @@ -0,0 +1 @@ +module Foo where diff --git a/cabal-testsuite/PackageTests/ExtraPackages/cabal.out b/cabal-testsuite/PackageTests/ExtraPackages/cabal.out new file mode 100644 index 00000000000..b6a1f792e51 --- /dev/null +++ b/cabal-testsuite/PackageTests/ExtraPackages/cabal.out @@ -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- -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 +Warning: The directory /cabal.dist/home/.cabal/store/ghc-/incoming/new-/cabal.dist/home/.cabal/store/ghc-/-/bin is not in the system search path. diff --git a/cabal-testsuite/PackageTests/ExtraPackages/cabal.project b/cabal-testsuite/PackageTests/ExtraPackages/cabal.project new file mode 100644 index 00000000000..58ca1e49456 --- /dev/null +++ b/cabal-testsuite/PackageTests/ExtraPackages/cabal.project @@ -0,0 +1,2 @@ +packages: . +extra-packages: some-exe diff --git a/cabal-testsuite/PackageTests/ExtraPackages/cabal.test.hs b/cabal-testsuite/PackageTests/ExtraPackages/cabal.test.hs new file mode 100644 index 00000000000..575b067db7d --- /dev/null +++ b/cabal-testsuite/PackageTests/ExtraPackages/cabal.test.hs @@ -0,0 +1,3 @@ +import Test.Cabal.Prelude +main = cabalTest $ withRepo "repo" $ do + cabal "v2-run" [ "some-exe" ] diff --git a/cabal-testsuite/PackageTests/ExtraPackages/my.cabal b/cabal-testsuite/PackageTests/ExtraPackages/my.cabal new file mode 100644 index 00000000000..b1b36c1e620 --- /dev/null +++ b/cabal-testsuite/PackageTests/ExtraPackages/my.cabal @@ -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 diff --git a/cabal-testsuite/PackageTests/ExtraPackages/repo/some-exe-0.0.1.0/Main.hs b/cabal-testsuite/PackageTests/ExtraPackages/repo/some-exe-0.0.1.0/Main.hs new file mode 100644 index 00000000000..33581fa8421 --- /dev/null +++ b/cabal-testsuite/PackageTests/ExtraPackages/repo/some-exe-0.0.1.0/Main.hs @@ -0,0 +1,4 @@ +module Main where + +main :: IO () +main = putStrLn "hello world" diff --git a/cabal-testsuite/PackageTests/ExtraPackages/repo/some-exe-0.0.1.0/some-exe.cabal b/cabal-testsuite/PackageTests/ExtraPackages/repo/some-exe-0.0.1.0/some-exe.cabal new file mode 100644 index 00000000000..3a2e620d96e --- /dev/null +++ b/cabal-testsuite/PackageTests/ExtraPackages/repo/some-exe-0.0.1.0/some-exe.cabal @@ -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 diff --git a/cabal-testsuite/src/Test/Cabal/OutputNormalizer.hs b/cabal-testsuite/src/Test/Cabal/OutputNormalizer.hs index fd7457b3324..3be8bc6e0e5 100644 --- a/cabal-testsuite/src/Test/Cabal/OutputNormalizer.hs +++ b/cabal-testsuite/src/Test/Cabal/OutputNormalizer.hs @@ -27,10 +27,13 @@ normalizeOutput nenv = . resub "Installing (.+) in .+" "Installing \\1 in " -- Things that look like libraries . resub "libHS[A-Za-z0-9.-]+\\.(so|dll|a|dynlib)" "" + -- look for PackageHash directories + . resub "/(([A-Za-z0-9_]+)(-[A-Za-z0-9\\._]+)*)-[0-9a-f]{4,64}/" + "/-/" -- 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.-]+") "" -- note, after TMPDIR + . resub (posixRegexEscape (normalizerGblTmpDir nenv) ++ "[a-z0-9\\.-]+") "" -- note, after TMPDIR . resub (posixRegexEscape (normalizerRoot nenv)) "/" . resub (posixRegexEscape (normalizerTmpDir nenv)) "/" . appEndo (F.fold (map (Endo . packageIdRegex) (normalizerKnownPackages nenv))) @@ -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.+]+" "/installed-" + -- incoming directories in the store + . resub "/incoming/new-[0-9]+" + "/incoming/new-" -- Normalize architecture . resub (posixRegexEscape (display (normalizerPlatform nenv))) "" -- Some GHC versions are chattier than others diff --git a/changelog.d/pr-6972 b/changelog.d/pr-6972 new file mode 100644 index 00000000000..98bfb87ff68 --- /dev/null +++ b/changelog.d/pr-6972 @@ -0,0 +1,3 @@ +synopsis: Make extra-packages work properly +packages: cabal-install +prs: #6972