Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions clang/test/Modules/reproducer-with-module-dependencies.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ void test(void) {

//--- script-expectations.txt
CHECK: CLANG:-clang-executable
CHECK: "-o" "reproducer.cache/reproducer.o"
CHECK: -fmodule-file=Test=reproducer.cache/explicitly-built-modules/Test-{{.*}}.pcm
Verify the reproducer VFS overlay is added before the existing overlay provided on a command line.
CHECK: -ivfsoverlay "reproducer.cache/vfs/vfs.yaml"
Expand Down
19 changes: 15 additions & 4 deletions clang/tools/libclang/CDependencies.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -835,7 +835,8 @@ enum CXErrorCode clang_experimental_DependencyScanner_generateReproducer(
std::string ReproExecutable = "\"${CLANG:-" + Opts.BuildArgs.front() + "}\"";
auto PrintArguments = [&ReproExecutable, &FileCacheName,
&ClangOpts](llvm::raw_fd_ostream &OS,
ArrayRef<std::string> Arguments) {
ArrayRef<std::string> Arguments,
bool RedirectOutput) {
std::vector<const char *> CharArgs(Arguments.size());
for (const std::string &Arg : Arguments)
CharArgs.push_back(Arg.c_str());
Expand All @@ -853,11 +854,19 @@ enum CXErrorCode clang_experimental_DependencyScanner_generateReproducer(
DidAddVFSOverlay = true;
}
}
bool IsOutputArg = Arg->getOption().matches(options::OPT_o);
llvm::opt::ArgStringList OutArgs;
Arg->render(ParsedArgs, OutArgs);
bool IsArgValue = false;
for (const auto &OutArg : OutArgs) {
OS << ' ';
llvm::sys::printArg(OS, OutArg, /*Quote=*/true);
if (RedirectOutput && IsOutputArg && IsArgValue) {
StringRef OutputFileName = llvm::sys::path::filename(OutArg);
OS << " \"" << FileCacheName << '/' << OutputFileName << '"';
} else {
llvm::sys::printArg(OS, OutArg, /*Quote=*/true);
}
IsArgValue = true;
}
}
if (!DidAddVFSOverlay) {
Expand All @@ -866,11 +875,13 @@ enum CXErrorCode clang_experimental_DependencyScanner_generateReproducer(
}
OS << '\n';
};
// Redirect the output to keep reproducers relocatable. But don't redirect
// modules as they are already in the appropriate place (see `LookupOutput`).
for (ModuleDeps &Dep : TU.ModuleGraph)
PrintArguments(ScriptOS, Dep.getBuildArguments());
PrintArguments(ScriptOS, Dep.getBuildArguments(), /*RedirectOutput=*/false);
ScriptOS << "\n# Translation unit:\n";
for (const Command &BuildCommand : TU.Commands)
PrintArguments(ScriptOS, BuildCommand.Arguments);
PrintArguments(ScriptOS, BuildCommand.Arguments, /*RedirectOutput=*/true);

auto RealFS = llvm::vfs::getRealFileSystem();
RealFS->setCurrentWorkingDirectory(*Opts.WorkingDirectory);
Expand Down