Skip to content

Commit aee3cb4

Browse files
author
David Ungar
committed
Try both in filelist for linker
1 parent 1f60d44 commit aee3cb4

File tree

4 files changed

+66
-47
lines changed

4 files changed

+66
-47
lines changed

include/swift/Driver/Util.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,9 @@ namespace driver {
4545
/// the Job this info is attached to.
4646
struct FilelistInfo {
4747
enum class WhichFiles : unsigned {
48-
Input,
49-
PrimaryInputs,
48+
InputJobs,
49+
SourceInputActions,
50+
InputJobsAndSourceInputActions,
5051
Output,
5152
/// Batch mode frontend invocations may have so many supplementary
5253
/// outputs that they don't comfortably fit as command-line arguments.

lib/Driver/Compilation.cpp

Lines changed: 58 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1356,6 +1356,51 @@ static void writeCompilationRecord(StringRef path, StringRef argsHash,
13561356
}
13571357
}
13581358

1359+
static void writeInputJobsToFilelist(llvm::raw_fd_ostream &out, const Job *job,
1360+
const file_types::ID infoType) {
1361+
// FIXME: Duplicated from ToolChains.cpp.
1362+
for (const Job *input : job->getInputs()) {
1363+
const CommandOutput &outputInfo = input->getOutput();
1364+
if (outputInfo.getPrimaryOutputType() == infoType) {
1365+
for (auto &output : outputInfo.getPrimaryOutputFilenames())
1366+
out << output << "\n";
1367+
} else {
1368+
auto output = outputInfo.getAnyOutputForType(infoType);
1369+
if (!output.empty())
1370+
out << output << "\n";
1371+
}
1372+
}
1373+
}
1374+
static void writeSourceInputActionsToFilelist(llvm::raw_fd_ostream &out,
1375+
const Job *job,
1376+
const ArgList &args) {
1377+
// Ensure that -index-file-path works in conjunction with
1378+
// -driver-use-filelists. It needs to be the only primary.
1379+
if (Arg *A = args.getLastArg(options::OPT_index_file_path))
1380+
out << A->getValue() << "\n";
1381+
else {
1382+
// The normal case for non-single-compile jobs.
1383+
for (const Action *A : job->getSource().getInputs()) {
1384+
// A could be a GeneratePCHJobAction
1385+
if (!isa<InputAction>(A))
1386+
continue;
1387+
const auto *IA = cast<InputAction>(A);
1388+
out << IA->getInputArg().getValue() << "\n";
1389+
}
1390+
}
1391+
}
1392+
static void writeOutputToFilelist(llvm::raw_fd_ostream &out, const Job *job,
1393+
const file_types::ID infoType) {
1394+
const CommandOutput &outputInfo = job->getOutput();
1395+
assert(outputInfo.getPrimaryOutputType() == infoType);
1396+
for (auto &output : outputInfo.getPrimaryOutputFilenames())
1397+
out << output << "\n";
1398+
}
1399+
static void writeSupplementarOutputToFilelist(llvm::raw_fd_ostream &out,
1400+
const Job *job) {
1401+
job->getOutput().writeOutputFileMap(out);
1402+
}
1403+
13591404
static bool writeFilelistIfNecessary(const Job *job, const ArgList &args,
13601405
DiagnosticEngine &diags) {
13611406
bool ok = true;
@@ -1374,46 +1419,23 @@ static bool writeFilelistIfNecessary(const Job *job, const ArgList &args,
13741419
}
13751420

13761421
switch (filelistInfo.whichFiles) {
1377-
case FilelistInfo::WhichFiles::Input:
1378-
// FIXME: Duplicated from ToolChains.cpp.
1379-
for (const Job *input : job->getInputs()) {
1380-
const CommandOutput &outputInfo = input->getOutput();
1381-
if (outputInfo.getPrimaryOutputType() == filelistInfo.type) {
1382-
for (auto &output : outputInfo.getPrimaryOutputFilenames())
1383-
out << output << "\n";
1384-
} else {
1385-
auto output = outputInfo.getAnyOutputForType(filelistInfo.type);
1386-
if (!output.empty())
1387-
out << output << "\n";
1388-
}
1389-
}
1422+
case FilelistInfo::WhichFiles::InputJobs:
1423+
writeInputJobsToFilelist(out, job, filelistInfo.type);
13901424
break;
1391-
case FilelistInfo::WhichFiles::PrimaryInputs:
1392-
// Ensure that -index-file-path works in conjunction with
1393-
// -driver-use-filelists. It needs to be the only primary.
1394-
if (Arg *A = args.getLastArg(options::OPT_index_file_path))
1395-
out << A->getValue() << "\n";
1396-
else {
1397-
// The normal case for non-single-compile jobs.
1398-
for (const Action *A : job->getSource().getInputs()) {
1399-
// A could be a GeneratePCHJobAction
1400-
if (!isa<InputAction>(A))
1401-
continue;
1402-
const auto *IA = cast<InputAction>(A);
1403-
out << IA->getInputArg().getValue() << "\n";
1404-
}
1405-
}
1425+
case FilelistInfo::WhichFiles::SourceInputActions:
1426+
writeSourceInputActionsToFilelist(out, job, args);
14061427
break;
1407-
case FilelistInfo::WhichFiles::Output: {
1408-
const CommandOutput &outputInfo = job->getOutput();
1409-
assert(outputInfo.getPrimaryOutputType() == filelistInfo.type);
1410-
for (auto &output : outputInfo.getPrimaryOutputFilenames())
1411-
out << output << "\n";
1428+
case FilelistInfo::WhichFiles::InputJobsAndSourceInputActions:
1429+
writeInputJobsToFilelist(out, job, filelistInfo.type);
1430+
writeSourceInputActionsToFilelist(out, job, args);
14121431
break;
1413-
}
1414-
case FilelistInfo::WhichFiles::SupplementaryOutput:
1415-
job->getOutput().writeOutputFileMap(out);
1432+
case FilelistInfo::WhichFiles::Output: {
1433+
writeOutputToFilelist(out, job, filelistInfo.type);
14161434
break;
1435+
}
1436+
case FilelistInfo::WhichFiles::SupplementaryOutput:
1437+
writeSupplementarOutputToFilelist(out, job);
1438+
break;
14171439
}
14181440
}
14191441
return ok;

lib/Driver/DarwinToolChains.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -230,14 +230,10 @@ toolchains::Darwin::addLinkerInputArgs(InvocationInfo &II,
230230
ArgStringList &Arguments = II.Arguments;
231231
if (context.shouldUseInputFileList()) {
232232
Arguments.push_back("-filelist");
233-
const auto whichFiles = context.Inputs.empty()
234-
? FilelistInfo::WhichFiles::PrimaryInputs
235-
: FilelistInfo::WhichFiles::Input;
236233
Arguments.push_back(context.getTemporaryFilePath("inputs", "LinkFileList"));
237234
II.FilelistInfos.push_back(
238-
{Arguments.back(), file_types::TY_Object, whichFiles});
239-
assert((context.Inputs.empty() || context.InputActions.empty()) &&
240-
"If both are non-empty the filelist won't work");
235+
{Arguments.back(), file_types::TY_Object,
236+
FilelistInfo::WhichFiles::InputJobsAndSourceInputActions});
241237
} else {
242238
addPrimaryInputsOfType(Arguments, context.Inputs, context.Args,
243239
file_types::TY_Object);
@@ -648,7 +644,7 @@ toolchains::Darwin::constructInvocation(const StaticLinkJobAction &job,
648644
Arguments.push_back("-filelist");
649645
Arguments.push_back(context.getTemporaryFilePath("inputs", "LinkFileList"));
650646
II.FilelistInfos.push_back({Arguments.back(), file_types::TY_Object,
651-
FilelistInfo::WhichFiles::Input});
647+
FilelistInfo::WhichFiles::InputJobs});
652648
} else {
653649
addPrimaryInputsOfType(Arguments, context.Inputs, context.Args,
654650
file_types::TY_Object);

lib/Driver/ToolChains.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,7 @@ void ToolChain::JobContext::addFrontendInputAndOutputArguments(
579579
Arguments.push_back("-primary-filelist");
580580
Arguments.push_back(getTemporaryFilePath("primaryInputs", ""));
581581
FilelistInfos.push_back({Arguments.back(), file_types::TY_Swift,
582-
FilelistInfo::WhichFiles::PrimaryInputs});
582+
FilelistInfo::WhichFiles::SourceInputActions});
583583
}
584584
if (!UseFileList || !UsePrimaryFileList) {
585585
addFrontendCommandLineInputArguments(MayHavePrimaryInputs, UseFileList,
@@ -876,7 +876,7 @@ ToolChain::constructInvocation(const MergeModuleJobAction &job,
876876
Arguments.push_back(context.getTemporaryFilePath("inputs", ""));
877877
II.FilelistInfos.push_back({Arguments.back(),
878878
file_types::TY_SwiftModuleFile,
879-
FilelistInfo::WhichFiles::Input});
879+
FilelistInfo::WhichFiles::InputJobs});
880880

881881
addInputsOfType(Arguments, context.InputActions,
882882
file_types::TY_SwiftModuleFile);

0 commit comments

Comments
 (0)