Skip to content

Commit 02be2a2

Browse files
John ButeJohn Bute
authored andcommitted
refactored to add verbosity flag to output agnostic flags for clang ld and swift
1 parent 53d3d12 commit 02be2a2

File tree

4 files changed

+48
-27
lines changed

4 files changed

+48
-27
lines changed

Sources/SWBCore/BuildParameters.swift

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ public struct BuildParameters: Hashable, SerializableCodable, Sendable {
191191
try container.encodeIfPresent(activeRunDestination, forKey: .activeRunDestination)
192192
try container.encodeIfPresent(activeArchitecture, forKey: .activeArchitecture)
193193
try container.encodeIfPresent(arena, forKey: .arena)
194-
try container.encode(filterOverrides(overrides), forKey: .overrides)
194+
try container.encode(overrides, forKey: .overrides)
195195
try container.encode(commandLineOverrides, forKey: .commandLineOverrides)
196196
try container.encodeIfPresent(commandLineConfigOverridesPath, forKey: .commandLineConfigOverridesPath)
197197
try container.encode(commandLineConfigOverrides, forKey: .commandLineConfigOverrides)
@@ -228,7 +228,7 @@ public struct BuildParameters: Hashable, SerializableCodable, Sendable {
228228
hasher.combine(activeRunDestination)
229229
hasher.combine(activeArchitecture)
230230
hasher.combine(arena)
231-
hasher.combine(filterOverrides(overrides))
231+
hasher.combine(overrides)
232232
hasher.combine(commandLineOverrides)
233233
hasher.combine(commandLineConfigOverridesPath)
234234
hasher.combine(commandLineConfigOverrides)
@@ -237,15 +237,6 @@ public struct BuildParameters: Hashable, SerializableCodable, Sendable {
237237
hasher.combine(toolchainOverride)
238238
return hasher.finalize()
239239
}
240-
241-
private func filterOverrides(_ overrides: [String: String]) -> [String: String] {
242-
overrides.mapValues { value in
243-
// Remove -v flag from the value to avoid rebuild
244-
value.split(separator: " ")
245-
.filter { $0 != "-v" }
246-
.joined(separator: " ")
247-
}
248-
}
249240
}
250241

251242
extension BuildParameters {

Sources/SWBCore/SpecImplementations/CommandLineToolSpec.swift

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,8 +399,32 @@ open class CommandLineToolSpec : PropertyDomainSpec, SpecType, TaskTypeDescripti
399399
return false
400400
}
401401

402+
static let outputAgnosticCompilerArguments = Set<ByteString>([
403+
"-v"
404+
])
405+
406+
func isOutputAgnosticCommandLineArgument(_ argument: ByteString, prevArgument: ByteString?) -> Bool {
407+
if CommandLineToolSpec.outputAgnosticCompilerArguments.contains(argument) {
408+
return true
409+
}
410+
411+
return false
412+
}
402413
public func commandLineForSignature(for task: any ExecutableTask) -> [ByteString]? {
403-
return nil
414+
// TODO: We should probably allow the specs themselves to mark options
415+
// as output agnostic, rather than always postprocessing the command
416+
// line. In some cases we will have to postprocess, because of settings
417+
// like OTHER_SWIFT_FLAGS where the user can't possibly add this
418+
// metadata to the values, but those settings be handled on a
419+
// case-by-case basis.
420+
return task.commandLine.indices.compactMap { index in
421+
let arg = task.commandLine[index].asByteString
422+
let prevArg = index > task.commandLine.startIndex ? task.commandLine[index - 1].asByteString : nil
423+
if isOutputAgnosticCommandLineArgument(arg, prevArgument: prevArg) {
424+
return nil
425+
}
426+
return arg
427+
}
404428
}
405429

406430
static func parseCommandLineTemplate(_ parser: SpecParser, _ components: [String]) -> [CommandLineTemplateArg] {

Sources/SWBCore/SpecImplementations/Tools/CCompiler.swift

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -733,7 +733,7 @@ public class ClangCompilerSpec : CompilerSpec, SpecIdentifierType, GCCCompatible
733733
} else if ClangSourceFileIndexingInfo.skippedArgsWithoutValues.contains(argAsByteString) || arg.starts(with: "-fbuild-session-file=") {
734734
// Relevant to indexing, so exclude arg from response file.
735735
regularCommandLine.append(arg)
736-
} else if isOutputAgnosticCommandLineArgument(argAsByteString, prevArgument: previousArg) {
736+
} else if isOutputAgnosticCCompilerArgument(argAsByteString, prevArgument: previousArg) {
737737
// Output agnostic, so exclude from response file.
738738
regularCommandLine.append(arg)
739739
} else if precompNeutralFlagPatterns.map({ $0.matches(arg) }).reduce(false, { $0 || $1 }) && !(previousArg ?? "").hasPrefix("-X") {
@@ -797,7 +797,7 @@ public class ClangCompilerSpec : CompilerSpec, SpecIdentifierType, GCCCompatible
797797
return fileType
798798
}
799799

800-
static let outputAgnosticCompilerArguments = Set<ByteString>([
800+
static let outputAgnosticCCompilerArguments = Set<ByteString>([
801801
// https://clang.llvm.org/docs/UsersManual.html#formatting-of-diagnostics
802802
"-fshow-column",
803803
"-fno-show-column",
@@ -818,14 +818,15 @@ public class ClangCompilerSpec : CompilerSpec, SpecIdentifierType, GCCCompatible
818818
"-fdiagnostics-parseable-fixits",
819819
"-fno-elide-type",
820820
"-fdiagnostics-show-template-tree",
821+
"-v",
821822

822823
// https://clang.llvm.org/docs/ClangCommandLineReference.html
823824
"-fdiagnostics-show-note-include-stack",
824825
"-fno-diagnostics-show-note-include-stack",
825826
"-fmodules-validate-once-per-build-session",
826827
])
827828

828-
static let outputAgnosticCompilerArgumentPrefixes = Set<ByteString>([
829+
static let outputAgnosticCCompilerArgumentPrefixes = Set<ByteString>([
829830
// https://clang.llvm.org/docs/UsersManual.html#formatting-of-diagnostics
830831
"-fdiagnostics-format=",
831832
"-fdiagnostics-show-category=",
@@ -837,22 +838,22 @@ public class ClangCompilerSpec : CompilerSpec, SpecIdentifierType, GCCCompatible
837838
"-fbuild-session-timestamp=",
838839
])
839840

840-
static let outputAgnosticCompilerArgumentsWithValues = Set<ByteString>([
841+
static let outputAgnosticCCompilerArgumentsWithValues = Set<ByteString>([
841842
"-index-store-path",
842843
"-index-unit-output-path",
843844
])
844845

845-
func isOutputAgnosticCommandLineArgument(_ argument: ByteString, prevArgument: ByteString?) -> Bool {
846-
if ClangCompilerSpec.outputAgnosticCompilerArguments.contains(argument) ||
847-
ClangCompilerSpec.outputAgnosticCompilerArgumentsWithValues.contains(argument) {
846+
func isOutputAgnosticCCompilerArgument(_ argument: ByteString, prevArgument: ByteString?) -> Bool {
847+
if ClangCompilerSpec.outputAgnosticCCompilerArguments.contains(argument) ||
848+
ClangCompilerSpec.outputAgnosticCCompilerArgumentsWithValues.contains(argument) {
848849
return true
849850
}
850851

851-
if ClangCompilerSpec.outputAgnosticCompilerArgumentPrefixes.first(where: { argument.hasPrefix($0) }) != nil {
852+
if ClangCompilerSpec.outputAgnosticCCompilerArgumentPrefixes.first(where: { argument.hasPrefix($0) }) != nil {
852853
return true
853854
}
854855

855-
if let prevArgument, ClangCompilerSpec.outputAgnosticCompilerArgumentsWithValues.contains(prevArgument) {
856+
if let prevArgument, ClangCompilerSpec.outputAgnosticCCompilerArgumentsWithValues.contains(prevArgument) {
856857
return true
857858
}
858859

@@ -868,7 +869,7 @@ public class ClangCompilerSpec : CompilerSpec, SpecIdentifierType, GCCCompatible
868869
return task.commandLine.indices.compactMap { index in
869870
let arg = task.commandLine[index].asByteString
870871
let prevArg = index > task.commandLine.startIndex ? task.commandLine[index - 1].asByteString : nil
871-
if isOutputAgnosticCommandLineArgument(arg, prevArgument: prevArg) {
872+
if isOutputAgnosticCCompilerArgument(arg, prevArgument: prevArg) {
872873
return nil
873874
}
874875
return arg

Sources/SWBCore/SpecImplementations/Tools/SwiftCompiler.swift

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1184,17 +1184,22 @@ public final class SwiftCompilerSpec : CompilerSpec, SpecIdentifierType, SwiftDi
11841184
case invalid
11851185
}
11861186

1187-
static let outputAgnosticCompilerArgumentsWithValues = Set<ByteString>([
1187+
static let outputAgnosticSwiftCompilerArguments = Set<ByteString>([
1188+
"-v"
1189+
])
1190+
1191+
static let outputAgnosticSwiftCompilerArgumentsWithValues = Set<ByteString>([
11881192
"-index-store-path",
11891193
"-index-unit-output-path",
11901194
])
11911195

1192-
func isOutputAgnosticCommandLineArgument(_ argument: ByteString, prevArgument: ByteString?) -> Bool {
1193-
if SwiftCompilerSpec.outputAgnosticCompilerArgumentsWithValues.contains(argument) {
1196+
func isOutputAgnosticSwiftCompilerArgument(_ argument: ByteString, prevArgument: ByteString?) -> Bool {
1197+
if SwiftCompilerSpec.outputAgnosticSwiftCompilerArguments.contains(argument) ||
1198+
SwiftCompilerSpec.outputAgnosticSwiftCompilerArgumentsWithValues.contains(argument) {
11941199
return true
11951200
}
11961201

1197-
if let prevArgument, SwiftCompilerSpec.outputAgnosticCompilerArgumentsWithValues.contains(prevArgument) {
1202+
if let prevArgument, SwiftCompilerSpec.outputAgnosticSwiftCompilerArgumentsWithValues.contains(prevArgument) {
11981203
return true
11991204
}
12001205

@@ -1211,7 +1216,7 @@ public final class SwiftCompilerSpec : CompilerSpec, SpecIdentifierType, SwiftDi
12111216
return task.commandLine.indices.compactMap { index in
12121217
let arg = task.commandLine[index].asByteString
12131218
let prevArg = index > task.commandLine.startIndex ? task.commandLine[index - 1].asByteString : nil
1214-
if isOutputAgnosticCommandLineArgument(arg, prevArgument: prevArg) {
1219+
if isOutputAgnosticSwiftCompilerArgument(arg, prevArgument: prevArg) {
12151220
return nil
12161221
}
12171222
return arg

0 commit comments

Comments
 (0)