Skip to content

Commit f11a4fd

Browse files
authored
Merge pull request #921 from owenv/owenv/driver-format
Correct linker file list escaping depending on the LINKER_DRIVER used
2 parents 8c8804e + 5b73823 commit f11a4fd

File tree

9 files changed

+57
-12
lines changed

9 files changed

+57
-12
lines changed

Sources/SWBCore/Settings/BuiltinMacros.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1198,6 +1198,8 @@ public final class BuiltinMacros {
11981198
public static let _WRAPPER_RESOURCES_DIR = BuiltinMacros.declareStringMacro("_WRAPPER_RESOURCES_DIR")
11991199
public static let __INPUT_FILE_LIST_PATH__ = BuiltinMacros.declarePathMacro("__INPUT_FILE_LIST_PATH__")
12001200
public static let LINKER_FILE_LIST_FORMAT = BuiltinMacros.declareEnumMacro("LINKER_FILE_LIST_FORMAT") as EnumMacroDeclaration<ResponseFileFormat>
1201+
public static let LIBTOOL_FILE_LIST_FORMAT = BuiltinMacros.declareEnumMacro("LIBTOOL_FILE_LIST_FORMAT") as EnumMacroDeclaration<ResponseFileFormat>
1202+
12011203
public static let LINKER_RESPONSE_FILE_FORMAT = BuiltinMacros.declareEnumMacro("LINKER_RESPONSE_FILE_FORMAT") as EnumMacroDeclaration<ResponseFileFormat>
12021204
public static let SWIFT_RESPONSE_FILE_PATH = BuiltinMacros.declarePathMacro("SWIFT_RESPONSE_FILE_PATH")
12031205
public static let __ARCHS__ = BuiltinMacros.declareStringListMacro("__ARCHS__")
@@ -2459,6 +2461,7 @@ public final class BuiltinMacros {
24592461
_WRAPPER_RESOURCES_DIR,
24602462
__INPUT_FILE_LIST_PATH__,
24612463
LINKER_FILE_LIST_FORMAT,
2464+
LIBTOOL_FILE_LIST_FORMAT,
24622465
LINKER_RESPONSE_FILE_FORMAT,
24632466
__ARCHS__,
24642467
__SWIFT_MODULE_ONLY_ARCHS__,

Sources/SWBCore/SpecImplementations/LinkerSpec.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,9 @@ open class LinkerSpec : CommandLineToolSpec, @unchecked Sendable {
138138
return ruleInfo
139139
}
140140

141-
public func inputFileListContents(_ cbc: CommandBuildContext) -> ByteString {
142-
return ByteString(encodingAsUTF8: ResponseFiles.responseFileContents(args: cbc.inputs.map { $0.absolutePath.strWithPosixSlashes }, format: cbc.scope.evaluate(BuiltinMacros.LINKER_FILE_LIST_FORMAT)))
141+
public func inputFileListContents(_ cbc: CommandBuildContext, lookup: ((MacroDeclaration) -> MacroExpression?)? = nil) -> ByteString {
142+
let format = cbc.scope.evaluate(BuiltinMacros.LINKER_FILE_LIST_FORMAT, lookup: lookup)
143+
return ByteString(encodingAsUTF8: ResponseFiles.responseFileContents(args: cbc.inputs.map { $0.absolutePath.strWithPosixSlashes }, format: format))
143144
}
144145

145146
open override func constructTasks(_ cbc: CommandBuildContext, _ delegate: any TaskGenerationDelegate) async {

Sources/SWBCore/SpecImplementations/PropertyDomainSpec.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ private final class EnumBuildOptionType : BuildOptionType {
118118
return try namespace.declareEnumMacro(name) as EnumMacroDeclaration<SwiftAPIDigesterMode>
119119
case "LINKER_FILE_LIST_FORMAT":
120120
return try namespace.declareEnumMacro(name) as EnumMacroDeclaration<ResponseFileFormat>
121+
case "LIBTOOL_FILE_LIST_FORMAT":
122+
return try namespace.declareEnumMacro(name) as EnumMacroDeclaration<ResponseFileFormat>
121123
case "LINKER_RESPONSE_FILE_FORMAT":
122124
return try namespace.declareEnumMacro(name) as EnumMacroDeclaration<ResponseFileFormat>
123125
case "DOCC_MINIMUM_ACCESS_LEVEL":

Sources/SWBCore/SpecImplementations/Tools/LinkerTools.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ public final class LdLinkerSpec : GenericLinkerSpec, SpecIdentifierType, @unchec
461461
let fileListPath = cbc.scope.evaluate(BuiltinMacros.__INPUT_FILE_LIST_PATH__, lookup: linkerDriverLookup)
462462
if !fileListPath.isEmpty {
463463
let fileListPath = fileListPath
464-
cbc.producer.writeFileSpec.constructFileTasks(CommandBuildContext(producer: cbc.producer, scope: cbc.scope, inputs: [], output: fileListPath), delegate, contents: inputFileListContents(cbc), permissions: nil, preparesForIndexing: false, additionalTaskOrderingOptions: [.immediate, .ignorePhaseOrdering])
464+
cbc.producer.writeFileSpec.constructFileTasks(CommandBuildContext(producer: cbc.producer, scope: cbc.scope, inputs: [], output: fileListPath), delegate, contents: inputFileListContents(cbc, lookup: linkerDriverLookup), permissions: nil, preparesForIndexing: false, additionalTaskOrderingOptions: [.immediate, .ignorePhaseOrdering])
465465
inputPaths.append(fileListPath)
466466
}
467467

@@ -1655,6 +1655,11 @@ public final class LibtoolLinkerSpec : GenericLinkerSpec, SpecIdentifierType, @u
16551655
return resolveExecutablePath(producer, lookupPath)
16561656
}
16571657

1658+
public override func inputFileListContents(_ cbc: CommandBuildContext, lookup: ((MacroDeclaration) -> MacroExpression?)? = nil) -> ByteString {
1659+
let format = cbc.scope.evaluate(BuiltinMacros.LIBTOOL_FILE_LIST_FORMAT, lookup: lookup)
1660+
return ByteString(encodingAsUTF8: ResponseFiles.responseFileContents(args: cbc.inputs.map { $0.absolutePath.strWithPosixSlashes }, format: format))
1661+
}
1662+
16581663
static func discoveredCommandLineToolSpecInfo(_ producer: any CommandProducer, _ delegate: any CoreClientTargetDiagnosticProducingDelegate, toolPath: Path) async throws -> DiscoveredLibtoolLinkerToolSpecInfo {
16591664
if toolPath.basenameWithoutSuffix == "llvm-lib" || toolPath.basenameWithoutSuffix == "ar" || toolPath.basenameWithoutSuffix.hasSuffix("-ar") {
16601665
return DiscoveredLibtoolLinkerToolSpecInfo(toolPath: toolPath, toolVersion: nil)

Sources/SWBGenericUnixPlatform/Specs/UnixLibtool.xcspec

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,11 @@
6969
DefaultValue = YES;
7070
},
7171
{
72-
Name = "LINKER_FILE_LIST_FORMAT";
72+
Name = "LIBTOOL_FILE_LIST_FORMAT";
7373
Type = Enumeration;
7474
Values = (
7575
unescapedNewlineSeparated,
76+
unixShellQuotedSpaceSeparated,
7677
unixShellQuotedNewlineSeparated,
7778
windowsShellQuotedNewlineSeparated,
7879
);

Sources/SWBUniversalPlatform/Specs/Ld.xcspec

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -831,8 +831,30 @@
831831
unixShellQuotedNewlineSeparated,
832832
windowsShellQuotedNewlineSeparated,
833833
);
834+
DefaultValue = "$(LINKER_FILE_LIST_FORMAT_$(LINKER_DRIVER))";
835+
},
836+
{
837+
Name = "LINKER_FILE_LIST_FORMAT_clang";
838+
Type = Enumeration;
839+
Values = (
840+
unescapedNewlineSeparated,
841+
unixShellQuotedSpaceSeparated,
842+
unixShellQuotedNewlineSeparated,
843+
windowsShellQuotedNewlineSeparated,
844+
);
834845
DefaultValue = unescapedNewlineSeparated;
835846
},
847+
{
848+
Name = "LINKER_FILE_LIST_FORMAT_swiftc";
849+
Type = Enumeration;
850+
Values = (
851+
unescapedNewlineSeparated,
852+
unixShellQuotedSpaceSeparated,
853+
unixShellQuotedNewlineSeparated,
854+
windowsShellQuotedNewlineSeparated,
855+
);
856+
DefaultValue = unixShellQuotedSpaceSeparated;
857+
},
836858
{
837859
Name = "LINKER_RESPONSE_FILE_FORMAT";
838860
Type = Enumeration;
@@ -843,7 +865,7 @@
843865
windowsShellQuotedNewlineSeparated,
844866
);
845867
DefaultValue = unixShellQuotedSpaceSeparated;
846-
}
868+
},
847869
);
848870
}
849871
)

Sources/SWBUniversalPlatform/Specs/Libtool.xcspec

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,17 @@
111111
Type = Boolean;
112112
DefaultValue = YES;
113113
},
114+
{
115+
Name = "LIBTOOL_FILE_LIST_FORMAT";
116+
Type = Enumeration;
117+
Values = (
118+
unescapedNewlineSeparated,
119+
unixShellQuotedSpaceSeparated,
120+
unixShellQuotedNewlineSeparated,
121+
windowsShellQuotedNewlineSeparated,
122+
);
123+
DefaultValue = unescapedNewlineSeparated;
124+
},
114125
);
115126
}
116127
)

Sources/SWBWindowsPlatform/Specs/WindowsLibtool.xcspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
IsInputDependency = Yes;
6565
},
6666
{
67-
Name = "LINKER_FILE_LIST_FORMAT";
67+
Name = "LIBTOOL_FILE_LIST_FORMAT";
6868
Type = Enumeration;
6969
Values = (
7070
unescapedNewlineSeparated,

Tests/SWBBuildSystemTests/BuildOperationTests.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ fileprivate struct BuildOperationTests: CoreBasedTests {
4040
"SomeFiles",
4141
children: [
4242
TestFile("main.swift"),
43-
TestFile("dynamic.swift"),
44-
TestFile("static.swift"),
43+
TestFile("dynamic library.swift"),
44+
TestFile("static library.swift"),
4545
]),
4646
buildConfigurations: [
4747
TestBuildConfiguration("Debug", buildSettings: [
@@ -93,7 +93,7 @@ fileprivate struct BuildOperationTests: CoreBasedTests {
9393
])
9494
],
9595
buildPhases: [
96-
TestSourcesBuildPhase(["dynamic.swift"]),
96+
TestSourcesBuildPhase(["dynamic library.swift"]),
9797
]
9898
),
9999
TestStandardTarget(
@@ -107,7 +107,7 @@ fileprivate struct BuildOperationTests: CoreBasedTests {
107107
])
108108
],
109109
buildPhases: [
110-
TestSourcesBuildPhase(["static.swift"]),
110+
TestSourcesBuildPhase(["static library.swift"]),
111111
]
112112
),
113113
])
@@ -125,11 +125,11 @@ fileprivate struct BuildOperationTests: CoreBasedTests {
125125
stream <<< "print(\"Hello world\")\n"
126126
}
127127

128-
try await tester.fs.writeFileContents(projectDir.join("dynamic.swift")) { stream in
128+
try await tester.fs.writeFileContents(projectDir.join("dynamic library.swift")) { stream in
129129
stream <<< "public func dynamicLib() { }"
130130
}
131131

132-
try await tester.fs.writeFileContents(projectDir.join("static.swift")) { stream in
132+
try await tester.fs.writeFileContents(projectDir.join("static library.swift")) { stream in
133133
stream <<< "public func staticLib() { }"
134134
}
135135

0 commit comments

Comments
 (0)