Skip to content

Commit 508c083

Browse files
committed
[pkg-config] Fix when value of a key-value pair in pc file is empty
1 parent 0466fe9 commit 508c083

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

Sources/Build/PkgConfig.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ struct PkgConfigParser {
100100
// Remove any trailing comment from the line.
101101
let line = removeComment(line: line)
102102

103-
if let colonIndex = line.characters.index(of: ":") where line[colonIndex.successor()] == " " {
103+
if let colonIndex = line.characters.index(of: ":") where
104+
line.endIndex == colonIndex.successor() || line[colonIndex.successor()] == " " {
104105
// Found a key-value pair.
105106
try parseKeyValue(line: line)
106107
} else if let equalsIndex = line.characters.index(of: "=") {

Tests/Build/PkgConfigParserTests.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,15 @@ final class PkgConfigParserTests: XCTestCase {
2323
}
2424
}
2525

26+
func testEmptyCFlags() {
27+
loadPCFile("empty_cflags.pc") { parser in
28+
XCTAssertEqual(parser.variables, ["prefix": "/usr/local/bin", "exec_prefix": "/usr/local/bin"])
29+
XCTAssertEqual(parser.dependencies, ["gdk-3.0", "atk"])
30+
XCTAssertEqual(parser.cFlags, "")
31+
XCTAssertEqual(parser.libs, "-L/usr/local/bin -lgtk-3 ")
32+
}
33+
}
34+
2635
private func loadPCFile(_ inputName: String, line: UInt = #line, body: (PkgConfigParser) -> Void) {
2736
do {
2837
let input = Path.join(#file, "../pkgconfigInputs", inputName).normpath
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
prefix=/usr/local/bin
2+
exec_prefix=${prefix}
3+
4+
#some comment
5+
6+
Requires: gdk-3.0 atk
7+
Libs: -L${prefix} -lgtk-3
8+
Cflags:

0 commit comments

Comments
 (0)