Skip to content

Commit

Permalink
[5.7][PkgConfig] Avoid creating dummy dependency (#5749)
Browse files Browse the repository at this point in the history
This can be seen in some awkwardly generated .pc files and it can crash SwiftPM silently at least on Windows.
  • Loading branch information
stevapple authored Sep 1, 2022
1 parent c5da466 commit 63c14b8
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Sources/PackageLoading/PkgConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ internal struct PkgConfigParser {
\(pcFile)
""")
}
} else {
} else if !arg.isEmpty {
// Otherwise it is a dependency.
deps.append(arg)
}
Expand Down
14 changes: 14 additions & 0 deletions Tests/PackageLoadingTests/PkgConfigParserTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,20 @@ final class PkgConfigParserTests: XCTestCase {
}
}

func testDummyDependency() throws {
try loadPCFile("dummy_dependency.pc") { parser in
XCTAssertEqual(parser.variables, [
"prefix": "/usr/local/bin",
"exec_prefix": "/usr/local/bin",
"pcfiledir": parser.pcFile.parentDirectory.pathString,
"pc_sysrootdir": AbsolutePath.root.pathString
])
XCTAssertEqual(parser.dependencies, ["pango", "fontconfig"])
XCTAssertEqual(parser.cFlags, [])
XCTAssertEqual(parser.libs, ["-L/usr/local/bin", "-lpangoft2-1.0"])
}
}

/// Test custom search path get higher priority for locating pc files.
func testCustomPcFileSearchPath() throws {
let observability = ObservabilitySystem.makeForTesting()
Expand Down
7 changes: 7 additions & 0 deletions Tests/PackageLoadingTests/pkgconfigInputs/dummy_dependency.pc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
prefix=/usr/local/bin
exec_prefix=${prefix}

#some comment

Requires: pango, , fontconfig >= 2.13.0
Libs:-L${prefix} -lpangoft2-1.0

0 comments on commit 63c14b8

Please sign in to comment.