@@ -12,14 +12,14 @@ import TSCBasic
1212import Foundation
1313
1414public enum PkgConfigError : Swift . Error , CustomStringConvertible {
15- case couldNotFindConfigFile
15+ case couldNotFindConfigFile( name : String )
1616 case parsingError( String )
1717 case nonWhitelistedFlags( String )
1818
1919 public var description : String {
2020 switch self {
21- case . couldNotFindConfigFile:
22- return " couldn't find pc file "
21+ case . couldNotFindConfigFile( let name ) :
22+ return " couldn't find pc file for \( name ) "
2323 case . parsingError( let error) :
2424 return " parsing error(s): \( error) "
2525 case . nonWhitelistedFlags( let flags) :
@@ -89,7 +89,7 @@ public struct PCFileFinder {
8989 PCFileFinder . shouldEmitPkgConfigPathsDiagnostic = false
9090 diagnostics. emit ( warning: " failed to retrieve search paths with pkg-config; maybe pkg-config is not installed " )
9191 }
92- throw PkgConfigError . couldNotFindConfigFile
92+ throw PkgConfigError . couldNotFindConfigFile ( name : name )
9393 }
9494}
9595
@@ -110,9 +110,6 @@ public struct PkgConfig {
110110 /// DiagnosticsEngine to emit diagnostics
111111 let diagnostics : DiagnosticsEngine
112112
113- /// Helper to query `pkg-config` for library locations
114- private let pkgFileFinder : PCFileFinder
115-
116113 /// Load the information for the named package.
117114 ///
118115 /// It will search `fileSystem` for the pkg config file in the following order:
@@ -132,12 +129,19 @@ public struct PkgConfig {
132129 fileSystem: FileSystem = localFileSystem,
133130 brewPrefix: AbsolutePath ?
134131 ) throws {
135- self . name = name
136- self . pkgFileFinder = PCFileFinder ( diagnostics: diagnostics, brewPrefix: brewPrefix)
137- self . pcFile = try pkgFileFinder. locatePCFile (
138- name: name,
139- customSearchPaths: PkgConfig . envSearchPaths + additionalSearchPaths,
140- fileSystem: fileSystem)
132+
133+ if let path = try ? AbsolutePath ( validating: name) {
134+ guard fileSystem. isFile ( path) else { throw PkgConfigError . couldNotFindConfigFile ( name: name) }
135+ self . name = path. basenameWithoutExt
136+ self . pcFile = path
137+ } else {
138+ self . name = name
139+ let pkgFileFinder = PCFileFinder ( diagnostics: diagnostics, brewPrefix: brewPrefix)
140+ self . pcFile = try pkgFileFinder. locatePCFile (
141+ name: name,
142+ customSearchPaths: PkgConfig . envSearchPaths + additionalSearchPaths,
143+ fileSystem: fileSystem)
144+ }
141145
142146 self . diagnostics = diagnostics
143147 var parser = PkgConfigParser ( pcFile: pcFile, fileSystem: fileSystem)
@@ -153,6 +157,7 @@ public struct PkgConfig {
153157 name: dep,
154158 additionalSearchPaths: additionalSearchPaths,
155159 diagnostics: diagnostics,
160+ fileSystem: fileSystem,
156161 brewPrefix: brewPrefix
157162 )
158163
0 commit comments