Skip to content

Commit 6252b97

Browse files
authored
Fix pkgconfig file parsing on Windows. (#8904)
We were not handling Windows line endings properly. It's a pretty simple one line fix to separate the lines by newlines. Re-enabling the pkgconfig tests on Windows.
1 parent 04ebe8b commit 6252b97

File tree

3 files changed

+1
-27
lines changed

3 files changed

+1
-27
lines changed

Sources/PackageLoading/PkgConfig.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ internal struct PkgConfigParser {
273273
variables["pc_sysrootdir"] = sysrootDir ?? Basics.AbsolutePath.root.pathString
274274

275275
let fileContents: String = try fileSystem.readFileContents(pcFile)
276-
for line in fileContents.components(separatedBy: "\n") {
276+
for line in fileContents.components(separatedBy: .newlines) {
277277
// Remove commented or any trailing comment from the line.
278278
let uncommentedLine = removeComment(line: line)
279279
// Ignore any empty or whitespace line.

Tests/PackageLoadingTests/PkgConfigParserTests.swift

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ import struct TSCBasic.ByteString
1919

2020
final class PkgConfigParserTests: XCTestCase {
2121
func testCircularPCFile() throws {
22-
try XCTSkipOnWindows()
23-
2422
let observability = ObservabilitySystem.makeForTesting()
2523

2624
_ = try PkgConfig(
@@ -36,8 +34,6 @@ final class PkgConfigParserTests: XCTestCase {
3634
}
3735

3836
func testGTK3PCFile() throws {
39-
try XCTSkipOnWindows()
40-
4137
try! loadPCFile("gtk+-3.0.pc") { parser in
4238
XCTAssertEqual(parser.variables, [
4339
"libdir": "/usr/local/Cellar/gtk+3/3.18.9/lib",
@@ -58,8 +54,6 @@ final class PkgConfigParserTests: XCTestCase {
5854
}
5955

6056
func testEmptyCFlags() throws {
61-
try XCTSkipOnWindows()
62-
6357
try! loadPCFile("empty_cflags.pc") { parser in
6458
XCTAssertEqual(parser.variables, [
6559
"prefix": "/usr/local/bin",
@@ -74,16 +68,12 @@ final class PkgConfigParserTests: XCTestCase {
7468
}
7569

7670
func testCFlagsCaseInsensitveKeys() throws {
77-
try XCTSkipOnWindows()
78-
7971
try! loadPCFile("case_insensitive.pc") { parser in
8072
XCTAssertEqual(parser.cFlags, ["-I/usr/local/include"])
8173
}
8274
}
8375

8476
func testVariableinDependency() throws {
85-
try XCTSkipOnWindows()
86-
8777
try! loadPCFile("deps_variable.pc") { parser in
8878
XCTAssertEqual(parser.variables, [
8979
"prefix": "/usr/local/bin",
@@ -108,8 +98,6 @@ final class PkgConfigParserTests: XCTestCase {
10898
}
10999

110100
func testEscapedSpaces() throws {
111-
try XCTSkipOnWindows()
112-
113101
try! loadPCFile("escaped_spaces.pc") { parser in
114102
XCTAssertEqual(parser.variables, [
115103
"prefix": "/usr/local/bin",
@@ -125,8 +113,6 @@ final class PkgConfigParserTests: XCTestCase {
125113
}
126114

127115
func testDummyDependency() throws {
128-
try XCTSkipOnWindows()
129-
130116
try loadPCFile("dummy_dependency.pc") { parser in
131117
XCTAssertEqual(parser.variables, [
132118
"prefix": "/usr/local/bin",
@@ -213,8 +199,6 @@ final class PkgConfigParserTests: XCTestCase {
213199
}
214200

215201
func testAbsolutePathDependency() throws {
216-
try XCTSkipOnWindows()
217-
218202
let libffiPath = "/usr/local/opt/libffi/lib/pkgconfig/libffi.pc"
219203

220204
try loadPCFile("gobject-2.0.pc") { parser in
@@ -248,8 +232,6 @@ final class PkgConfigParserTests: XCTestCase {
248232
}
249233

250234
func testUnevenQuotes() throws {
251-
try XCTSkipOnWindows()
252-
253235
do {
254236
try loadPCFile("quotes_failure.pc")
255237
XCTFail("Unexpected success")
@@ -259,8 +241,6 @@ final class PkgConfigParserTests: XCTestCase {
259241
}
260242

261243
func testSysrootDir() throws {
262-
try XCTSkipOnWindows()
263-
264244
// sysroot should be prepended to all path variables, and should therefore appear in cflags and libs.
265245
try loadPCFile("gtk+-3.0.pc", sysrootDir: "/opt/sysroot/somewhere") { parser in
266246
XCTAssertEqual(parser.variables, [

Tests/PackageLoadingTests/PkgConfigTests.swift

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,6 @@ class PkgConfigTests: XCTestCase {
8787
}
8888

8989
func testEnvVar() throws {
90-
try XCTSkipOnWindows()
91-
9290
// Pc file.
9391
try Environment.makeCustom(["PKG_CONFIG_PATH": inputsDir.pathString]) {
9492
for result in try pkgConfigArgs(
@@ -152,8 +150,6 @@ class PkgConfigTests: XCTestCase {
152150
}
153151

154152
func testExplicitPkgConfigDirectories() throws {
155-
try XCTSkipOnWindows()
156-
157153
// Pc file.
158154
for result in try pkgConfigArgs(
159155
for: SystemLibraryModule(pkgConfig: "Foo"),
@@ -212,8 +208,6 @@ class PkgConfigTests: XCTestCase {
212208
}
213209

214210
func testDependencies() throws {
215-
try XCTSkipOnWindows()
216-
217211
// Use additionalSearchPaths instead of pkgConfigArgs to test handling
218212
// of search paths when loading dependencies.
219213
let result = try PkgConfig(

0 commit comments

Comments
 (0)