@@ -67,15 +67,22 @@ readPkgConfigDb verbosity progdb = handle ioErrorHandler $ do
6767 -- The output of @pkg-config --list-all@ also includes a description
6868 -- for each package, which we do not need.
6969 let pkgNames = map (takeWhile (not . isSpace)) pkgList
70- (pkgVersions , _errs, exitCode) <-
70+ (outs , _errs, exitCode) <-
7171 getProgramInvocationOutputAndErrors verbosity
7272 (programInvocation pkgConfig (" --modversion" : pkgNames))
73- case exitCode of
74- ExitSuccess -> (return . pkgConfigDbFromList . zip pkgNames) (lines pkgVersions)
75- -- if there's a single broken pc file the above fails, so we fall back into calling it individually
76- _ -> do
77- info verbosity (" call to pkg-config --modversion on all packages failed. Falling back to querying pkg-config individually on each package" )
78- pkgConfigDbFromList . catMaybes <$> mapM (getIndividualVersion pkgConfig) pkgNames
73+ let pkgVersions = lines outs
74+ if exitCode == ExitSuccess && length pkgVersions == length pkgNames
75+ then (return . pkgConfigDbFromList . zip pkgNames) pkgVersions
76+ else
77+ -- if there's a single broken pc file the above fails, so we fall back
78+ -- into calling it individually
79+ --
80+ -- Also some implementations of @pkg-config@ do not provide more than
81+ -- one package version, so if the returned list is shorter than the
82+ -- requested one, we fall back to querying one by one.
83+ do
84+ info verbosity (" call to pkg-config --modversion on all packages failed. Falling back to querying pkg-config individually on each package" )
85+ pkgConfigDbFromList . catMaybes <$> mapM (getIndividualVersion pkgConfig) pkgNames
7986 where
8087 -- For when pkg-config invocation fails (possibly because of a
8188 -- too long command line).
0 commit comments