Skip to content

Commit 00173e5

Browse files
John ButeJohn Bute
authored andcommitted
only added to linker
1 parent 02be2a2 commit 00173e5

File tree

4 files changed

+40
-46
lines changed

4 files changed

+40
-46
lines changed

Sources/SWBCore/SpecImplementations/CommandLineToolSpec.swift

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -399,32 +399,8 @@ 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-
}
413402
public func commandLineForSignature(for task: any ExecutableTask) -> [ByteString]? {
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-
}
403+
nil
428404
}
429405

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

Sources/SWBCore/SpecImplementations/Tools/CCompiler.swift

Lines changed: 11 additions & 11 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 isOutputAgnosticCCompilerArgument(argAsByteString, prevArgument: previousArg) {
736+
} else if isOutputAgnosticCommandLineArgument(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 outputAgnosticCCompilerArguments = Set<ByteString>([
800+
static let outputAgnosticCompilerArguments = Set<ByteString>([
801801
// https://clang.llvm.org/docs/UsersManual.html#formatting-of-diagnostics
802802
"-fshow-column",
803803
"-fno-show-column",
@@ -818,15 +818,15 @@ public class ClangCompilerSpec : CompilerSpec, SpecIdentifierType, GCCCompatible
818818
"-fdiagnostics-parseable-fixits",
819819
"-fno-elide-type",
820820
"-fdiagnostics-show-template-tree",
821-
"-v",
821+
822822

823823
// https://clang.llvm.org/docs/ClangCommandLineReference.html
824824
"-fdiagnostics-show-note-include-stack",
825825
"-fno-diagnostics-show-note-include-stack",
826826
"-fmodules-validate-once-per-build-session",
827827
])
828828

829-
static let outputAgnosticCCompilerArgumentPrefixes = Set<ByteString>([
829+
static let outputAgnosticCompilerArgumentPrefixes = Set<ByteString>([
830830
// https://clang.llvm.org/docs/UsersManual.html#formatting-of-diagnostics
831831
"-fdiagnostics-format=",
832832
"-fdiagnostics-show-category=",
@@ -838,22 +838,22 @@ public class ClangCompilerSpec : CompilerSpec, SpecIdentifierType, GCCCompatible
838838
"-fbuild-session-timestamp=",
839839
])
840840

841-
static let outputAgnosticCCompilerArgumentsWithValues = Set<ByteString>([
841+
static let outputAgnosticCompilerArgumentsWithValues = Set<ByteString>([
842842
"-index-store-path",
843843
"-index-unit-output-path",
844844
])
845845

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

852-
if ClangCompilerSpec.outputAgnosticCCompilerArgumentPrefixes.first(where: { argument.hasPrefix($0) }) != nil {
852+
if ClangCompilerSpec.outputAgnosticCompilerArgumentPrefixes.first(where: { argument.hasPrefix($0) }) != nil {
853853
return true
854854
}
855855

856-
if let prevArgument, ClangCompilerSpec.outputAgnosticCCompilerArgumentsWithValues.contains(prevArgument) {
856+
if let prevArgument, ClangCompilerSpec.outputAgnosticCompilerArgumentsWithValues.contains(prevArgument) {
857857
return true
858858
}
859859

@@ -869,7 +869,7 @@ public class ClangCompilerSpec : CompilerSpec, SpecIdentifierType, GCCCompatible
869869
return task.commandLine.indices.compactMap { index in
870870
let arg = task.commandLine[index].asByteString
871871
let prevArg = index > task.commandLine.startIndex ? task.commandLine[index - 1].asByteString : nil
872-
if isOutputAgnosticCCompilerArgument(arg, prevArgument: prevArg) {
872+
if isOutputAgnosticCommandLineArgument(arg, prevArgument: prevArg) {
873873
return nil
874874
}
875875
return arg

Sources/SWBCore/SpecImplementations/Tools/LinkerTools.swift

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,29 @@ public final class LdLinkerSpec : GenericLinkerSpec, SpecIdentifierType, @unchec
302302
return ["ld", "libtool"]
303303
}
304304

305+
static let outputAgnosticLinkerArguments = Set<ByteString>([
306+
"-v"
307+
])
308+
309+
func isOutputAgnosticLinkerArgument(_ argument: ByteString, prevArgument: ByteString?) -> Bool {
310+
if LdLinkerSpec.outputAgnosticLinkerArguments.contains(argument) {
311+
return true
312+
}
313+
314+
return false
315+
}
316+
317+
public override func commandLineForSignature(for task: any ExecutableTask) -> [ByteString]? {
318+
return task.commandLine.indices.compactMap { index in
319+
let arg = task.commandLine[index].asByteString
320+
let prevArg = index > task.commandLine.startIndex ? task.commandLine[index - 1].asByteString : nil
321+
if isOutputAgnosticLinkerArgument(arg, prevArgument: prevArg) {
322+
return nil
323+
}
324+
return arg
325+
}
326+
}
327+
305328
public func sparseSDKSearchPathArguments(_ cbc: CommandBuildContext) -> [String] {
306329
var specialArgs = [String]()
307330

Sources/SWBCore/SpecImplementations/Tools/SwiftCompiler.swift

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

1187-
static let outputAgnosticSwiftCompilerArguments = Set<ByteString>([
1188-
"-v"
1189-
])
1190-
1191-
static let outputAgnosticSwiftCompilerArgumentsWithValues = Set<ByteString>([
1187+
static let outputAgnosticCompilerArgumentsWithValues = Set<ByteString>([
11921188
"-index-store-path",
11931189
"-index-unit-output-path",
11941190
])
11951191

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

1202-
if let prevArgument, SwiftCompilerSpec.outputAgnosticSwiftCompilerArgumentsWithValues.contains(prevArgument) {
1197+
if let prevArgument, SwiftCompilerSpec.outputAgnosticCompilerArgumentsWithValues.contains(prevArgument) {
12031198
return true
12041199
}
12051200

@@ -1216,7 +1211,7 @@ public final class SwiftCompilerSpec : CompilerSpec, SpecIdentifierType, SwiftDi
12161211
return task.commandLine.indices.compactMap { index in
12171212
let arg = task.commandLine[index].asByteString
12181213
let prevArg = index > task.commandLine.startIndex ? task.commandLine[index - 1].asByteString : nil
1219-
if isOutputAgnosticSwiftCompilerArgument(arg, prevArgument: prevArg) {
1214+
if isOutputAgnosticCommandLineArgument(arg, prevArgument: prevArg) {
12201215
return nil
12211216
}
12221217
return arg

0 commit comments

Comments
 (0)