Skip to content

Commit 1cd010d

Browse files
authored
Merge pull request #1888 from ahoppen/indexstore-relative-compdb
Interpret the `-index-store-path` relative to the command’s directory
2 parents bb13147 + b07044d commit 1cd010d

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

Sources/BuildSystemIntegration/CompilationDatabaseBuildSystem.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,10 @@ package actor CompilationDatabaseBuildSystem: BuiltInBuildSystem {
9999
let args = command.commandLine
100100
for i in args.indices.reversed() {
101101
if args[i] == "-index-store-path" && i + 1 < args.count {
102-
return URL(fileURLWithPath: args[i + 1])
102+
return URL(
103+
fileURLWithPath: args[i + 1],
104+
relativeTo: URL(fileURLWithPath: command.directory, isDirectory: true)
105+
)
103106
}
104107
}
105108
}

Tests/BuildSystemIntegrationTests/CompilationDatabaseTests.swift

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,25 @@ final class CompilationDatabaseTests: XCTestCase {
412412
)
413413
}
414414
}
415+
416+
func testIndexStorePathRelativeToWorkingDirectory() async throws {
417+
try await checkCompilationDatabaseBuildSystem(
418+
"""
419+
[
420+
{
421+
"file": "a.swift",
422+
"directory": "/a",
423+
"arguments": ["swift", "a.swift", "-index-store-path", "index-store"]
424+
}
425+
]
426+
"""
427+
) { buildSystem in
428+
assertEqual(
429+
try await buildSystem.indexStorePath?.filePath,
430+
"\(pathSeparator)a\(pathSeparator)index-store"
431+
)
432+
}
433+
}
415434
}
416435

417436
fileprivate var pathSeparator: String {

0 commit comments

Comments
 (0)