Skip to content

Commit 44bd97b

Browse files
committed
Fix Windows test failures
1 parent 0c89669 commit 44bd97b

File tree

3 files changed

+23
-11
lines changed

3 files changed

+23
-11
lines changed

Sources/BuildSystemIntegration/CompilationDatabaseBuildSystem.swift

+6
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,12 @@ package actor CompilationDatabaseBuildSystem: BuiltInBuildSystem {
107107

108108
package let configPath: URL
109109

110+
// Watch for all all changes to `compile_commands.json` and `compile_flags.txt` instead of just the one at
111+
// `configPath` so that we cover the following semi-common scenario:
112+
// The user has a build that stores `compile_commands.json` in `mybuild`. In order to pick it up, they create a
113+
// symlink from `<project root>/compile_commands.json` to `mybuild/compile_commands.json`. We want to get notified
114+
// about the change to `mybuild/compile_commands.json` because it effectively changes the contents of
115+
// `<project root>/compile_commands.json`.
110116
package let fileWatchers: [FileSystemWatcher] = [
111117
FileSystemWatcher(globPattern: "**/compile_commands.json", kind: [.create, .change, .delete]),
112118
FileSystemWatcher(globPattern: "**/compile_flags.txt", kind: [.create, .change, .delete]),

Sources/SKTestSupport/MultiFileTestProject.swift

+4
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@ package class MultiFileTestProject {
9696
let markedText =
9797
markedText
9898
.replacingOccurrences(of: "$TEST_DIR_URL", with: testDirUrl)
99+
.replacingOccurrences(
100+
of: "$TEST_DIR_BACKSLASH_ESCAPED",
101+
with: try scratchDirectory.filePath.replacing(#"\"#, with: #"\\"#)
102+
)
99103
.replacingOccurrences(of: "$TEST_DIR", with: try scratchDirectory.filePath)
100104
let fileURL = fileLocation.url(relativeTo: scratchDirectory)
101105
try FileManager.default.createDirectory(

Tests/SourceKitLSPTests/WorkspaceTests.swift

+13-11
Original file line numberDiff line numberDiff line change
@@ -985,10 +985,10 @@ final class WorkspaceTests: XCTestCase {
985985
"build/compile_commands.json": """
986986
[
987987
{
988-
"directory": "$TEST_DIR",
989-
"command": "swiftc $TEST_DIR/src/Foo.swift -DHAVE_SETTINGS \(defaultSDKArgs)",
988+
"directory": "$TEST_DIR_BACKSLASH_ESCAPED",
989+
"command": "swiftc $TEST_DIR_BACKSLASH_ESCAPED/src/Foo.swift -DHAVE_SETTINGS \(defaultSDKArgs)",
990990
"file": "src/Foo.swift",
991-
"output": "$TEST_DIR/build/Foo.swift.o"
991+
"output": "$TEST_DIR_BACKSLASH_ESCAPED/build/Foo.swift.o"
992992
}
993993
]
994994
""",
@@ -1031,10 +1031,10 @@ final class WorkspaceTests: XCTestCase {
10311031
"projA/build/compile_commands.json": """
10321032
[
10331033
{
1034-
"directory": "$TEST_DIR/projA",
1035-
"command": "swiftc $TEST_DIR/projA/src/Foo.swift -DHAVE_SETTINGS \(defaultSDKArgs)",
1034+
"directory": "$TEST_DIR_BACKSLASH_ESCAPED/projA",
1035+
"command": "swiftc $TEST_DIR_BACKSLASH_ESCAPED/projA/src/Foo.swift -DHAVE_SETTINGS \(defaultSDKArgs)",
10361036
"file": "src/Foo.swift",
1037-
"output": "$TEST_DIR/projA/build/Foo.swift.o"
1037+
"output": "$TEST_DIR_BACKSLASH_ESCAPED/projA/build/Foo.swift.o"
10381038
}
10391039
]
10401040
""",
@@ -1078,10 +1078,10 @@ final class WorkspaceTests: XCTestCase {
10781078
"otherbuild/compile_commands.json": """
10791079
[
10801080
{
1081-
"directory": "$TEST_DIR",
1082-
"command": "swiftc $TEST_DIR/src/Foo.swift -DHAVE_SETTINGS \(defaultSDKArgs)",
1081+
"directory": "$TEST_DIR_BACKSLASH_ESCAPED",
1082+
"command": "swiftc $TEST_DIR_BACKSLASH_ESCAPED/src/Foo.swift -DHAVE_SETTINGS \(defaultSDKArgs)",
10831083
"file": "src/Foo.swift",
1084-
"output": "$TEST_DIR/otherbuild/Foo.swift.o"
1084+
"output": "$TEST_DIR_BACKSLASH_ESCAPED/otherbuild/Foo.swift.o"
10851085
}
10861086
]
10871087
""",
@@ -1112,10 +1112,12 @@ final class WorkspaceTests: XCTestCase {
11121112

11131113
fileprivate let defaultSDKArgs: String = {
11141114
if let defaultSDKPath {
1115-
let escapedPath = defaultSDKPath.replacing(#"\"#, with: #"\\"#)
1115+
let escapedPath = defaultSDKPath
11161116
return """
1117-
-sdk '\(escapedPath)'
1117+
-sdk "\(escapedPath)"
11181118
"""
1119+
.replacing(#"\"#, with: #"\\"#)
1120+
.replacing("\"", with: #"\""#)
11191121
}
11201122
return ""
11211123
}()

0 commit comments

Comments
 (0)