Skip to content

Commit 28b29f3

Browse files
committed
Add a LIBTOOL_USE_RESPONSE_FILE build setting
This will be used to control whether response files are used when invoking libtool, as some platforms' implementations (like FreeBSD) may not support response files.
1 parent 0fca2ee commit 28b29f3

File tree

5 files changed

+27
-7
lines changed

5 files changed

+27
-7
lines changed

Sources/SWBCore/Settings/BuiltinMacros.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -809,6 +809,7 @@ public final class BuiltinMacros {
809809
public static let LIBRARY_SEARCH_PATHS = BuiltinMacros.declarePathListMacro("LIBRARY_SEARCH_PATHS")
810810
public static let LIBTOOL = BuiltinMacros.declarePathMacro("LIBTOOL")
811811
public static let LIBTOOL_DEPENDENCY_INFO_FILE = BuiltinMacros.declarePathMacro("LIBTOOL_DEPENDENCY_INFO_FILE")
812+
public static let LIBTOOL_USE_RESPONSE_FILE = BuiltinMacros.declareBooleanMacro("LIBTOOL_USE_RESPONSE_FILE")
812813
public static let LINKER = BuiltinMacros.declareStringMacro("LINKER")
813814
public static let ALTERNATE_LINKER = BuiltinMacros.declareStringMacro("ALTERNATE_LINKER")
814815
public static let LINK_OBJC_RUNTIME = BuiltinMacros.declareBooleanMacro("LINK_OBJC_RUNTIME")
@@ -1863,6 +1864,7 @@ public final class BuiltinMacros {
18631864
LIBRARY_SEARCH_PATHS,
18641865
LIBTOOL,
18651866
LIBTOOL_DEPENDENCY_INFO_FILE,
1867+
LIBTOOL_USE_RESPONSE_FILE,
18661868
LINKER,
18671869
LINK_OBJC_RUNTIME,
18681870
LINK_WITH_STANDARD_LIBRARIES,

Sources/SWBCore/Specs/Tools/LinkerTools.swift

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1379,17 +1379,22 @@ public final class LibtoolLinkerSpec : GenericLinkerSpec, SpecIdentifierType, @u
13791379

13801380
override public func constructLinkerTasks(_ cbc: CommandBuildContext, _ delegate: any TaskGenerationDelegate, libraries: [LibrarySpecifier], usedTools: [CommandLineToolSpec: Set<FileTypeSpec>]) async {
13811381
var inputPaths = cbc.inputs.map({ $0.absolutePath })
1382+
var specialArgs = [String]()
13821383

1383-
// Define the linker file list.
1384-
let fileListPath = cbc.scope.evaluate(BuiltinMacros.__INPUT_FILE_LIST_PATH__)
1385-
if !fileListPath.isEmpty {
1386-
let contents = cbc.inputs.map({ return $0.absolutePath.strWithPosixSlashes + "\n" }).joined(separator: "")
1387-
cbc.producer.writeFileSpec.constructFileTasks(CommandBuildContext(producer: cbc.producer, scope: cbc.scope, inputs: [], output: fileListPath), delegate, contents: ByteString(encodingAsUTF8: contents), permissions: nil, preparesForIndexing: false, additionalTaskOrderingOptions: [.immediate, .ignorePhaseOrdering])
1388-
inputPaths.append(fileListPath)
1384+
if cbc.scope.evaluate(BuiltinMacros.LIBTOOL_USE_RESPONSE_FILE) {
1385+
// Define the linker file list.
1386+
let fileListPath = cbc.scope.evaluate(BuiltinMacros.__INPUT_FILE_LIST_PATH__)
1387+
if !fileListPath.isEmpty {
1388+
let contents = cbc.inputs.map({ return $0.absolutePath.strWithPosixSlashes + "\n" }).joined(separator: "")
1389+
cbc.producer.writeFileSpec.constructFileTasks(CommandBuildContext(producer: cbc.producer, scope: cbc.scope, inputs: [], output: fileListPath), delegate, contents: ByteString(encodingAsUTF8: contents), permissions: nil, preparesForIndexing: false, additionalTaskOrderingOptions: [.immediate, .ignorePhaseOrdering])
1390+
inputPaths.append(fileListPath)
1391+
}
1392+
} else {
1393+
specialArgs.append(contentsOf: cbc.inputs.map { $0.absolutePath.str })
1394+
inputPaths.append(contentsOf: cbc.inputs.map { $0.absolutePath })
13891395
}
13901396

13911397
// Add arguments for the contents of the Link Binaries build phase.
1392-
var specialArgs = [String]()
13931398
specialArgs.append(contentsOf: libraries.flatMap { specifier -> [String] in
13941399
let basename = specifier.path.basename
13951400

Sources/SWBGenericUnixPlatform/UnixLibtool.xcspec

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,18 @@
5656
Name = __INPUT_FILE_LIST_PATH__;
5757
Type = Path;
5858
// this is set up for us as a read-only property
59+
Condition = "$(LIBTOOL_USE_RESPONSE_FILE)";
5960
DefaultValue = "$(LINK_FILE_LIST_$(variant)_$(arch))";
6061
CommandLineArgs = (
6162
"@$(value)",
6263
);
6364
IsInputDependency = Yes;
6465
},
66+
{
67+
Name = "LIBTOOL_USE_RESPONSE_FILE";
68+
Type = Boolean;
69+
DefaultValue = YES;
70+
},
6571
);
6672
},
6773
)

Sources/SWBUniversalPlatform/Specs/Libtool.xcspec

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
// Input file lists
6262
{ Name = __INPUT_FILE_LIST_PATH__;
6363
Type = Path;
64+
Condition = "$(LIBTOOL_USE_RESPONSE_FILE)";
6465
DefaultValue = "$(LINK_FILE_LIST_$(variant)_$(arch))"; // this is set up for us as a read-only property
6566
CommandLineFlag = "-filelist";
6667
IsInputDependency = Yes;
@@ -104,6 +105,11 @@
104105
DefaultValue = "$(OBJECT_FILE_DIR_$(CURRENT_VARIANT))/$(CURRENT_ARCH)/$(PRODUCT_NAME)_libtool_dependency_info.dat";
105106
},
106107

108+
{
109+
Name = "LIBTOOL_USE_RESPONSE_FILE";
110+
Type = Boolean;
111+
DefaultValue = YES;
112+
},
107113
);
108114
}
109115
)

Tests/SWBCoreTests/CommandLineSpecTests.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1472,6 +1472,7 @@ import SWBMacro
14721472
// Create the mock table.
14731473
var table = MacroValueAssignmentTable(namespace: core.specRegistry.internalMacroNamespace)
14741474
table.push(try #require(core.specRegistry.internalMacroNamespace.lookupMacroDeclaration("LIBTOOL") as? PathMacroDeclaration), literal: "libtool")
1475+
table.push(BuiltinMacros.LIBTOOL_USE_RESPONSE_FILE, literal: true)
14751476
table.push(BuiltinMacros.arch, literal: "x86_64")
14761477
table.push(BuiltinMacros.variant, literal: "normal")
14771478

0 commit comments

Comments
 (0)