From 84b22e1133bb911a6dd57c8c592f6f063297f76c Mon Sep 17 00:00:00 2001 From: Jens Petersen Date: Fri, 3 Nov 2023 16:30:40 +0800 Subject: [PATCH] cabal-install-solver: fix pkgconf 1.9 --modversion regression Check that the numbers of *versions* output is equal to the number of pkgconf's fixes #8923 The pkgconf behavior was reverted upstream in 2.0 (this should cover the case too of checking that equal pkgList lines are output also) (cherry picked from commit 3832beaf50b9ec7d07111ce0f673de95577f48a9) # Conflicts: # cabal-install-solver/src/Distribution/Solver/Types/PkgConfigDb.hs --- .../Distribution/Solver/Types/PkgConfigDb.hs | 18 +++++++++++++++++- changelog.d/pr-9391 | 4 ++++ 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 changelog.d/pr-9391 diff --git a/cabal-install-solver/src/Distribution/Solver/Types/PkgConfigDb.hs b/cabal-install-solver/src/Distribution/Solver/Types/PkgConfigDb.hs index 11e6da847f0..80469c4738a 100644 --- a/cabal-install-solver/src/Distribution/Solver/Types/PkgConfigDb.hs +++ b/cabal-install-solver/src/Distribution/Solver/Types/PkgConfigDb.hs @@ -67,15 +67,31 @@ readPkgConfigDb verbosity progdb = handle ioErrorHandler $ do -- The output of @pkg-config --list-all@ also includes a description -- for each package, which we do not need. let pkgNames = map (takeWhile (not . isSpace)) pkgList - (pkgVersions, _errs, exitCode) <- + (outs, _errs, exitCode) <- getProgramInvocationOutputAndErrors verbosity (programInvocation pkgConfig ("--modversion" : pkgNames)) +<<<<<<< HEAD case exitCode of ExitSuccess -> (return . pkgConfigDbFromList . zip pkgNames) (lines pkgVersions) -- if there's a single broken pc file the above fails, so we fall back into calling it individually _ -> do info verbosity ("call to pkg-config --modversion on all packages failed. Falling back to querying pkg-config individually on each package") pkgConfigDbFromList . catMaybes <$> mapM (getIndividualVersion pkgConfig) pkgNames +======= + let pkgVersions = lines outs + if exitCode == ExitSuccess && length pkgVersions == length pkgNames + then (return . pkgConfigDbFromList . zip pkgNames) pkgVersions + else + -- if there's a single broken pc file the above fails, so we fall back + -- into calling it individually + -- + -- Also some implementations of @pkg-config@ do not provide more than + -- one package version, so if the returned list is shorter than the + -- requested one, we fall back to querying one by one. + do + info verbosity ("call to pkg-config --modversion on all packages failed. Falling back to querying pkg-config individually on each package") + pkgConfigDbFromList . catMaybes <$> mapM (getIndividualVersion pkgConfig) pkgNames +>>>>>>> 3832beaf5 (cabal-install-solver: fix pkgconf 1.9 --modversion regression) where -- For when pkg-config invocation fails (possibly because of a -- too long command line). diff --git a/changelog.d/pr-9391 b/changelog.d/pr-9391 new file mode 100644 index 00000000000..517c94ed127 --- /dev/null +++ b/changelog.d/pr-9391 @@ -0,0 +1,4 @@ +synopsis: fix pkgconfig-depends for pkgconf-1.9 +packages: cabal-install-solver +prs: #9391 +issues: #8923