Skip to content

Commit

Permalink
Try each pkg-config query separatedly if returned list doesn't match …
Browse files Browse the repository at this point in the history
…query length

MinGW's pkg-config returns only one version even if queried for
multiple libraries.
  • Loading branch information
jasagredo committed Sep 18, 2023
1 parent a0d815c commit 470aa2e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
20 changes: 13 additions & 7 deletions cabal-install-solver/src/Distribution/Solver/Types/PkgConfigDb.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand All @@ -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
Expand Down
8 changes: 8 additions & 0 deletions changelog.d/pkgconfig-once
Original file line number Diff line number Diff line change
@@ -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

}

0 comments on commit 470aa2e

Please sign in to comment.