Skip to content

Commit 51fa0ae

Browse files
authored
Merge pull request #903 from ahoppen/no-compress-if-index-disabled
Do not pass index store options if indexing is disabled
2 parents 9268518 + 2c69a82 commit 51fa0ae

File tree

6 files changed

+147
-6
lines changed

6 files changed

+147
-6
lines changed

Sources/SWBApplePlatform/Specs/MetalCompiler.xcspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@
239239
Name = "METAL_INDEX_STORE_ONLY_PROJECT_FILES";
240240
Type = Boolean;
241241
DefaultValue = "$(INDEX_STORE_ONLY_PROJECT_FILES)";
242-
Condition = "$(MTL_ENABLE_INDEX_STORE)";
242+
Condition = "$(MTL_ENABLE_INDEX_STORE) && ( $(COMPILER_INDEX_STORE_ENABLE) == YES || ( $(COMPILER_INDEX_STORE_ENABLE) == Default && $(MTL_ENABLE_DEBUG_INFO) != NO ) )";
243243
CommandLineArgs = {
244244
YES = (
245245
// See corresponding definition in Clang.xcspec

Sources/SWBUniversalPlatform/Specs/Clang.xcspec

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3189,7 +3189,7 @@
31893189
Name = "CLANG_INDEX_STORE_ONLY_PROJECT_FILES";
31903190
Type = Boolean;
31913191
DefaultValue = "$(INDEX_STORE_ONLY_PROJECT_FILES)";
3192-
Condition = "$(CLANG_INDEX_STORE_ENABLE)";
3192+
Condition = "$(CLANG_INDEX_STORE_ENABLE) && ( $(COMPILER_INDEX_STORE_ENABLE) || ( $(COMPILER_INDEX_STORE_ENABLE) == Default && $(GCC_OPTIMIZATION_LEVEL) == 0 ) )";
31933193
CommandLineArgs = {
31943194
YES = (
31953195
"-index-ignore-system-symbols",
@@ -3203,7 +3203,7 @@
32033203
Name = "CLANG_INDEX_STORE_COMPRESS";
32043204
Type = Boolean;
32053205
DefaultValue = "$(INDEX_STORE_COMPRESS)";
3206-
Condition = "$(CLANG_INDEX_STORE_ENABLE)";
3206+
Condition = "$(CLANG_INDEX_STORE_ENABLE) && ( $(COMPILER_INDEX_STORE_ENABLE) || ( $(COMPILER_INDEX_STORE_ENABLE) == Default && $(GCC_OPTIMIZATION_LEVEL) == 0 ) )";
32073207
CommandLineArgs = {
32083208
YES = (
32093209
"-index-store-compress",
@@ -3215,7 +3215,7 @@
32153215
Name = "CLANG_INDEX_STORE_IGNORE_MACROS";
32163216
Type = Boolean;
32173217
DefaultValue = NO;
3218-
Condition = "$(CLANG_INDEX_STORE_ENABLE)";
3218+
Condition = "$(CLANG_INDEX_STORE_ENABLE) && ( $(COMPILER_INDEX_STORE_ENABLE) || ( $(COMPILER_INDEX_STORE_ENABLE) == Default && $(GCC_OPTIMIZATION_LEVEL) == 0 ) )";
32193219
DisplayName = "Do not index C macros";
32203220
Description = "Do not emit entries for C macros into the Index Store.";
32213221
CommandLineArgs = {

Sources/SWBUniversalPlatform/Specs/Swift.xcspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1343,7 +1343,7 @@
13431343
Name = "SWIFT_INDEX_STORE_ONLY_PROJECT_FILES";
13441344
Type = Boolean;
13451345
DefaultValue = "$(INDEX_STORE_ONLY_PROJECT_FILES)";
1346-
Condition = "$(SWIFT_INDEX_STORE_ENABLE)";
1346+
Condition = "$(SWIFT_INDEX_STORE_ENABLE) && ( $(COMPILER_INDEX_STORE_ENABLE) || ( $(COMPILER_INDEX_STORE_ENABLE) == Default && $(SWIFT_OPTIMIZATION_LEVEL) == '-Onone' ) )";
13471347
CommandLineArgs = {
13481348
YES = (
13491349
// Assume that clang modules are getting indexed by a clang file within them. While this is technically not correct, since you could have a clang module that only consists of header files and is only included from Swift, such scenarios are rare.
@@ -1357,7 +1357,7 @@
13571357
Name = "SWIFT_INDEX_STORE_COMPRESS";
13581358
Type = Boolean;
13591359
DefaultValue = "$(INDEX_STORE_COMPRESS)";
1360-
Condition = "$(SWIFT_INDEX_STORE_ENABLE)";
1360+
Condition = "$(SWIFT_INDEX_STORE_ENABLE) && ( $(COMPILER_INDEX_STORE_ENABLE) || ( $(COMPILER_INDEX_STORE_ENABLE) == Default && $(SWIFT_OPTIMIZATION_LEVEL) == '-Onone' ) )";
13611361
CommandLineArgs = {
13621362
YES = (
13631363
"-Xfrontend",

Tests/SWBTaskConstructionTests/ClangTests.swift

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,4 +388,52 @@ fileprivate struct ClangTests: CoreBasedTests {
388388
}
389389
}
390390
}
391+
392+
@Test(.requireSDKs(.host))
393+
func indexOptionsNotAddedIfIndexingIsDisabled() async throws {
394+
try await withTemporaryDirectory { tmpDir in
395+
let testProject = TestProject(
396+
"ProjectName",
397+
sourceRoot: tmpDir,
398+
groupTree: TestGroup(
399+
"SomeFiles",
400+
children: [
401+
TestFile("File1.c")
402+
]),
403+
targets: [
404+
TestStandardTarget(
405+
"Test",
406+
type: .dynamicLibrary,
407+
buildConfigurations: [
408+
TestBuildConfiguration(
409+
"Debug",
410+
buildSettings: [
411+
"COMPILER_INDEX_STORE_ENABLE": "NO",
412+
"INDEX_DATA_STORE_DIR": tmpDir.join("index").str,
413+
"INDEX_STORE_COMPRESS": "YES",
414+
"INDEX_STORE_ONLY_PROJECT_FILES": "YES",
415+
"CLANG_INDEX_STORE_IGNORE_MACROS": "YES",
416+
"OTHER_CFLAGS": "-DCLANG_INDEX_STORE_ENABLE=$(CLANG_INDEX_STORE_ENABLE) -DCOMPILER_INDEX_STORE_ENABLE=$(COMPILER_INDEX_STORE_ENABLE)"
417+
]
418+
),
419+
],
420+
buildPhases: [
421+
TestSourcesBuildPhase(["File1.c"]),
422+
]
423+
)
424+
])
425+
426+
let core = try await getCore()
427+
let tester = try TaskConstructionTester(core, testProject)
428+
await tester.checkBuild(BuildParameters(configuration: "Debug", commandLineOverrides: ["INDEX_ENABLE_DATA_STORE": "YES"]), runDestination: .host) { results in
429+
results.checkTask(.matchRuleType("CompileC")) { compileTask in
430+
compileTask.checkCommandLineDoesNotContain("-index-store-path")
431+
compileTask.checkCommandLineDoesNotContain("-index-store-compress")
432+
compileTask.checkCommandLineDoesNotContain("-index-ignore-system-symbols")
433+
compileTask.checkCommandLineDoesNotContain("-index-ignore-pcms")
434+
compileTask.checkCommandLineDoesNotContain("-index-ignore-macros")
435+
}
436+
}
437+
}
438+
}
391439
}

Tests/SWBTaskConstructionTests/MetalTests.swift

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,50 @@ fileprivate struct MetalTests: CoreBasedTests {
7272
}
7373
}
7474
}
75+
76+
@Test(.requireSDKs(.macOS), .skipInGitHubActions("Metal toolchain is not installed on GitHub runners"))
77+
func indexOptionsNotAddedIfIndexingIsDisabled() async throws {
78+
try await withTemporaryDirectory { tmpDir in
79+
let testProject = TestProject(
80+
"ProjectName",
81+
sourceRoot: tmpDir,
82+
groupTree: TestGroup(
83+
"SomeFiles",
84+
children: [
85+
TestFile("File1.metal")
86+
]),
87+
targets: [
88+
TestStandardTarget(
89+
"Test",
90+
type: .staticLibrary,
91+
buildConfigurations: [
92+
TestBuildConfiguration(
93+
"Debug",
94+
buildSettings: [
95+
"COMPILER_INDEX_STORE_ENABLE": "NO",
96+
"INDEX_DATA_STORE_DIR": tmpDir.join("index").str,
97+
"INDEX_STORE_COMPRESS": "YES",
98+
"INDEX_STORE_ONLY_PROJECT_FILES": "YES",
99+
"CLANG_INDEX_STORE_IGNORE_MACROS": "YES",
100+
]
101+
),
102+
],
103+
buildPhases: [
104+
TestSourcesBuildPhase(["File1.metal"]),
105+
]
106+
)
107+
])
108+
109+
let core = try await getCore()
110+
let tester = try TaskConstructionTester(core, testProject)
111+
await tester.checkBuild(BuildParameters(configuration: "Debug", commandLineOverrides: ["INDEX_ENABLE_DATA_STORE": "YES"]), runDestination: .macOS) { results in
112+
results.checkTask(.matchRuleType("CompileMetalFile")) { compileTask in
113+
compileTask.checkCommandLineDoesNotContain("-index-store-path")
114+
compileTask.checkCommandLineDoesNotContain("-index-store-compress")
115+
compileTask.checkCommandLineDoesNotContain("-index-ignore-system-symbols")
116+
compileTask.checkCommandLineDoesNotContain("-index-ignore-pcms")
117+
}
118+
}
119+
}
120+
}
75121
}

Tests/SWBTaskConstructionTests/SwiftTaskConstructionTests.swift

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4572,6 +4572,53 @@ fileprivate struct SwiftTaskConstructionTests: CoreBasedTests {
45724572
}
45734573
}
45744574
}
4575+
4576+
@Test(.requireSDKs(.host))
4577+
func indexOptionsNotAddedIfIndexingIsDisabled() async throws {
4578+
try await withTemporaryDirectory { tmpDir in
4579+
let testProject = try await TestProject(
4580+
"ProjectName",
4581+
sourceRoot: tmpDir,
4582+
groupTree: TestGroup(
4583+
"SomeFiles",
4584+
children: [
4585+
TestFile("File1.swift")
4586+
]),
4587+
targets: [
4588+
TestStandardTarget(
4589+
"Test",
4590+
type: .dynamicLibrary,
4591+
buildConfigurations: [
4592+
TestBuildConfiguration(
4593+
"Debug",
4594+
buildSettings: [
4595+
"SWIFT_EXEC": swiftCompilerPath.str,
4596+
"SWIFT_VERSION": swiftVersion,
4597+
"COMPILER_INDEX_STORE_ENABLE": "NO",
4598+
"INDEX_DATA_STORE_DIR": tmpDir.join("index").str,
4599+
"INDEX_STORE_COMPRESS": "YES",
4600+
"INDEX_STORE_ONLY_PROJECT_FILES": "YES"
4601+
]
4602+
),
4603+
],
4604+
buildPhases: [
4605+
TestSourcesBuildPhase(["File1.swift"]),
4606+
]
4607+
)
4608+
])
4609+
4610+
let core = try await getCore()
4611+
let tester = try TaskConstructionTester(core, testProject)
4612+
await tester.checkBuild(BuildParameters(configuration: "Debug", commandLineOverrides: ["INDEX_ENABLE_DATA_STORE": "YES"]), runDestination: .host) { results in
4613+
results.checkTask(.matchRuleType("SwiftDriver Compilation")) { compileTask in
4614+
compileTask.checkCommandLineDoesNotContain("-index-store-path")
4615+
compileTask.checkCommandLineDoesNotContain("-index-store-compress")
4616+
compileTask.checkCommandLineDoesNotContain("-index-ignore-clang-modules")
4617+
compileTask.checkCommandLineDoesNotContain("-index-ignore-system-modules")
4618+
}
4619+
}
4620+
}
4621+
}
45754622
}
45764623

45774624
private func XCTAssertEqual(_ lhs: EnvironmentBindings, _ rhs: [String: String], file: StaticString = #filePath, line: UInt = #line) {

0 commit comments

Comments
 (0)