diff options
| author | Hans Wennborg <hans@hanshq.net> | 2018-10-13 19:13:14 +0000 |
|---|---|---|
| committer | Hans Wennborg <hans@hanshq.net> | 2018-10-13 19:13:14 +0000 |
| commit | 2fe010473dec3d67579b20fb4bd8d27bc063c3b4 (patch) | |
| tree | 1dc39829c502d2341a3acedbb2e286646e8c0df4 | |
| parent | 28a143f7389be7044430727cdf95f134caadd1b5 (diff) | |
| download | bcm5719-llvm-2fe010473dec3d67579b20fb4bd8d27bc063c3b4.tar.gz bcm5719-llvm-2fe010473dec3d67579b20fb4bd8d27bc063c3b4.zip | |
Re-commit r344234 "clang-cl: Add /showFilenames option (PR31957)"
The test was failing on e.g. PPC which can't target Windows. Fix by
requiring X86 target in the test. Also, make sure the output goes to a
temporary directory, since CWD may not be writable.
llvm-svn: 344462
| -rw-r--r-- | clang/include/clang/Driver/CLCompatOptions.td | 4 | ||||
| -rw-r--r-- | clang/include/clang/Driver/Job.h | 6 | ||||
| -rw-r--r-- | clang/lib/Driver/Job.cpp | 6 | ||||
| -rw-r--r-- | clang/lib/Driver/ToolChains/Clang.cpp | 7 | ||||
| -rw-r--r-- | clang/test/Driver/cl-showfilenames.c | 23 |
5 files changed, 46 insertions, 0 deletions
diff --git a/clang/include/clang/Driver/CLCompatOptions.td b/clang/include/clang/Driver/CLCompatOptions.td index 62a4497ac42..3c2bef74ed0 100644 --- a/clang/include/clang/Driver/CLCompatOptions.td +++ b/clang/include/clang/Driver/CLCompatOptions.td @@ -158,6 +158,10 @@ def _SLASH_Qvec_ : CLFlag<"Qvec-">, def _SLASH_showIncludes : CLFlag<"showIncludes">, HelpText<"Print info about included files to stderr">, Alias<show_includes>; +def _SLASH_showFilenames : CLFlag<"showFilenames">, + HelpText<"Print the name of each compiled file">; +def _SLASH_showFilenames_ : CLFlag<"showFilenames-">, + HelpText<"Don't print the name of each compiled file (default)">; def _SLASH_source_charset : CLCompileJoined<"source-charset:">, HelpText<"Source encoding, supports only UTF-8">, Alias<finput_charset_EQ>; def _SLASH_execution_charset : CLCompileJoined<"execution-charset:">, diff --git a/clang/include/clang/Driver/Job.h b/clang/include/clang/Driver/Job.h index 10b97b98a2c..870a31c5209 100644 --- a/clang/include/clang/Driver/Job.h +++ b/clang/include/clang/Driver/Job.h @@ -56,6 +56,9 @@ class Command { /// The list of program arguments which are inputs. llvm::opt::ArgStringList InputFilenames; + /// Whether to print the input filenames when executing. + bool PrintInputFilenames = false; + /// Response file name, if this command is set to use one, or nullptr /// otherwise const char *ResponseFile = nullptr; @@ -125,6 +128,9 @@ public: /// Print a command argument, and optionally quote it. static void printArg(llvm::raw_ostream &OS, StringRef Arg, bool Quote); + + /// Set whether to print the input filenames when executing. + void setPrintInputFilenames(bool P) { PrintInputFilenames = P; } }; /// Like Command, but with a fallback which is executed in case diff --git a/clang/lib/Driver/Job.cpp b/clang/lib/Driver/Job.cpp index b6322b6ce2b..8d1dfbe12d7 100644 --- a/clang/lib/Driver/Job.cpp +++ b/clang/lib/Driver/Job.cpp @@ -316,6 +316,12 @@ void Command::setEnvironment(llvm::ArrayRef<const char *> NewEnvironment) { int Command::Execute(ArrayRef<llvm::Optional<StringRef>> Redirects, std::string *ErrMsg, bool *ExecutionFailed) const { + if (PrintInputFilenames) { + for (const char *Arg : InputFilenames) + llvm::outs() << llvm::sys::path::filename(Arg) << "\n"; + llvm::outs().flush(); + } + SmallVector<const char*, 128> Argv; Optional<ArrayRef<StringRef>> Env; diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index 127f8069622..4d2cb14a51b 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -5067,6 +5067,13 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, C.addCommand(llvm::make_unique<Command>(JA, *this, Exec, CmdArgs, Inputs)); } + // Make the compile command echo its inputs for /showFilenames. + if (Output.getType() == types::TY_Object && + Args.hasFlag(options::OPT__SLASH_showFilenames, + options::OPT__SLASH_showFilenames_, false)) { + C.getJobs().getJobs().back()->setPrintInputFilenames(true); + } + if (Arg *A = Args.getLastArg(options::OPT_pg)) if (!shouldUseFramePointer(Args, Triple)) D.Diag(diag::err_drv_argument_not_allowed_with) << "-fomit-frame-pointer" diff --git a/clang/test/Driver/cl-showfilenames.c b/clang/test/Driver/cl-showfilenames.c new file mode 100644 index 00000000000..5defcd1523a --- /dev/null +++ b/clang/test/Driver/cl-showfilenames.c @@ -0,0 +1,23 @@ +// We have to run the compilation step to see the output, so we must be able to +// target Windows. +// REQUIRES: x86-registered-target + +// RUN: %clang_cl /c /Fo%T/ /showFilenames -- %s 2>&1 | FileCheck -check-prefix=show %s +// RUN: %clang_cl /c /Fo%T/ /showFilenames -- %s %S/Inputs/wildcard*.c 2>&1 | FileCheck -check-prefix=multiple %s + +// RUN: %clang_cl /c /Fo%T/ -- %s 2>&1 | FileCheck -check-prefix=noshow %s +// RUN: %clang_cl /c /Fo%T/ /showFilenames /showFilenames- -- %s 2>&1 | FileCheck -check-prefix=noshow %s + + +#pragma message "Hello" + +// show: cl-showfilenames.c +// show-NEXT: warning: Hello + +// multiple: cl-showfilenames.c +// multiple-NEXT: warning: Hello +// multiple: wildcard1.c +// multiple-NEXT: wildcard2.c + +// noshow: warning: Hello +// noshow-NOT: cl-showfilenames.c |

