From 5247a6e540945f769e7d070b783888111d4fe1a7 Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Mon, 30 Nov 2020 11:39:07 -0800 Subject: [PATCH] SKSwiftPMWorkspace: make `testBasicCXXArgs` pass on Windows We would previously fail to correctly build the GNU dependency outputs on Windows since we were checking the file system representation of the path against the internal path representation. This fixes the generation of that command as well as the additional checks in the test case to allow the test case to succeed on Windows. --- .../SKSwiftPMWorkspace/SwiftPMWorkspace.swift | 6 ++++- .../SwiftPMWorkspaceTests.swift | 23 ++++++++++++++----- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/Sources/SKSwiftPMWorkspace/SwiftPMWorkspace.swift b/Sources/SKSwiftPMWorkspace/SwiftPMWorkspace.swift index ff200a94..60130fa8 100644 --- a/Sources/SKSwiftPMWorkspace/SwiftPMWorkspace.swift +++ b/Sources/SKSwiftPMWorkspace/SwiftPMWorkspace.swift @@ -378,7 +378,11 @@ extension SwiftPMWorkspace { var args = td.basicArguments() - let compilePath = td.compilePaths().first(where: { $0.source == path }) + let nativePath: AbsolutePath = + URL(fileURLWithPath: path.pathString).withUnsafeFileSystemRepresentation { + AbsolutePath(String(cString: $0!)) + } + let compilePath = td.compilePaths().first(where: { $0.source == nativePath }) if let compilePath = compilePath { args += [ "-MD", diff --git a/Tests/SKSwiftPMWorkspaceTests/SwiftPMWorkspaceTests.swift b/Tests/SKSwiftPMWorkspaceTests/SwiftPMWorkspaceTests.swift index 8b318d4b..eb182158 100644 --- a/Tests/SKSwiftPMWorkspaceTests/SwiftPMWorkspaceTests.swift +++ b/Tests/SKSwiftPMWorkspaceTests/SwiftPMWorkspaceTests.swift @@ -365,16 +365,27 @@ final class SwiftPMWorkspaceTests: XCTestCase { let args = ws.settings(for: acxx.asURI, .cpp)!.compilerArguments checkArgsCommon(args) - check("-MD", "-MT", "dependencies", - "-MF", build.appending(components: "lib.build", "a.cpp.d").pathString, - arguments: args) - check("-c", acxx.pathString, arguments: args) - check("-o", build.appending(components: "lib.build", "a.cpp.o").pathString, arguments: args) + + URL(fileURLWithPath: build.appending(components: "lib.build", "a.cpp.d").pathString) + .withUnsafeFileSystemRepresentation { + check("-MD", "-MT", "dependencies", "-MF", String(cString: $0!), arguments: args) + } + + URL(fileURLWithPath: acxx.pathString).withUnsafeFileSystemRepresentation { + check("-c", String(cString: $0!), arguments: args) + } + + URL(fileURLWithPath: build.appending(components: "lib.build", "a.cpp.o").pathString) + .withUnsafeFileSystemRepresentation { + check("-o", String(cString: $0!), arguments: args) + } let header = packageRoot.appending(components: "Sources", "lib", "include", "a.h") let headerArgs = ws.settings(for: header.asURI, .cpp)!.compilerArguments checkArgsCommon(headerArgs) - check("-c", "-x", "c++-header", header.pathString, arguments: headerArgs) + + check("-c", "-x", "c++-header", URL(fileURLWithPath: header.pathString).path, + arguments: headerArgs) } }