Skip to content

Commit 6595cd2

Browse files
authored
[PkgConfig] Avoid creating dummy dependency (#5741)
* [PkgConfig] Avoid creating blank dependency name This can be seen in some awkwardly generated .pc files and it can crash SwiftPM silently at least on Windows. * [PkgConfig] Add test case for dummy dependency
1 parent 7186666 commit 6595cd2

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

Sources/PackageLoading/PkgConfig.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ internal struct PkgConfigParser {
271271
\(pcFile)
272272
""")
273273
}
274-
} else {
274+
} else if !arg.isEmpty {
275275
// Otherwise it is a dependency.
276276
deps.append(arg)
277277
}

Tests/PackageLoadingTests/PkgConfigParserTests.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,20 @@ final class PkgConfigParserTests: XCTestCase {
105105
}
106106
}
107107

108+
func testDummyDependency() throws {
109+
try loadPCFile("dummy_dependency.pc") { parser in
110+
XCTAssertEqual(parser.variables, [
111+
"prefix": "/usr/local/bin",
112+
"exec_prefix": "/usr/local/bin",
113+
"pcfiledir": parser.pcFile.parentDirectory.pathString,
114+
"pc_sysrootdir": AbsolutePath.root.pathString
115+
])
116+
XCTAssertEqual(parser.dependencies, ["pango", "fontconfig"])
117+
XCTAssertEqual(parser.cFlags, [])
118+
XCTAssertEqual(parser.libs, ["-L/usr/local/bin", "-lpangoft2-1.0"])
119+
}
120+
}
121+
108122
/// Test custom search path get higher priority for locating pc files.
109123
func testCustomPcFileSearchPath() throws {
110124
let observability = ObservabilitySystem.makeForTesting()
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
prefix=/usr/local/bin
2+
exec_prefix=${prefix}
3+
4+
#some comment
5+
6+
Requires: pango, , fontconfig >= 2.13.0
7+
Libs:-L${prefix} -lpangoft2-1.0

0 commit comments

Comments
 (0)