diff --git a/cabal-install-solver/src/Distribution/Solver/Types/PkgConfigDb.hs b/cabal-install-solver/src/Distribution/Solver/Types/PkgConfigDb.hs index 11e6da847f0..00bc38c28c3 100644 --- a/cabal-install-solver/src/Distribution/Solver/Types/PkgConfigDb.hs +++ b/cabal-install-solver/src/Distribution/Solver/Types/PkgConfigDb.hs @@ -70,12 +70,18 @@ readPkgConfigDb verbosity progdb = handle ioErrorHandler $ do (pkgVersions, _errs, exitCode) <- getProgramInvocationOutputAndErrors verbosity (programInvocation pkgConfig ("--modversion" : pkgNames)) - 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 + if exitCode == ExitSuccess && length pkgNames == length pkgList + then (return . pkgConfigDbFromList . zip pkgNames) (lines 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 where -- For when pkg-config invocation fails (possibly because of a -- too long command line). @@ -92,7 +98,7 @@ readPkgConfigDb verbosity progdb = handle ioErrorHandler $ do getIndividualVersion pkgConfig pkg = do (pkgVersion, _errs, exitCode) <- getProgramInvocationOutputAndErrors verbosity - (programInvocation pkgConfig ["--modversion",pkg]) + (programInvocation pkgConfig ["--modversion", pkg]) return $ case exitCode of ExitSuccess -> Just (pkg, pkgVersion) _ -> Nothing diff --git a/changelog.d/pkgconfig-once b/changelog.d/pkgconfig-once new file mode 100644 index 00000000000..c3ac3ac47e0 --- /dev/null +++ b/changelog.d/pkgconfig-once @@ -0,0 +1,8 @@ +synopsis: PkgConfig individual calls +prs: #9134 + +description: { + +- `cabal` invokes `pkg-config` individually for each lib if querying for all doesn't return the expected result + +}