From 4eb8e4f562fa0aff9e6e943b965206c17ce3b817 Mon Sep 17 00:00:00 2001 From: Hans Wennborg Date: Thu, 11 Oct 2018 10:04:15 +0000 Subject: [PATCH] clang-cl: Add /showFilenames option (PR31957) Add a /showFilenames option for users who want clang to echo the currently compiled filename. MSVC does this echoing by default, and it's useful for showing progress in build systems that doesn't otherwise provide any progress report, such as MSBuild. Differential Revision: https://reviews.llvm.org/D52773 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@344234 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Driver/CLCompatOptions.td | 4 ++++ include/clang/Driver/Job.h | 6 ++++++ lib/Driver/Job.cpp | 6 ++++++ lib/Driver/ToolChains/Clang.cpp | 7 +++++++ test/Driver/cl-showfilenames.c | 19 +++++++++++++++++++ 5 files changed, 42 insertions(+) create mode 100644 test/Driver/cl-showfilenames.c diff --git a/include/clang/Driver/CLCompatOptions.td b/include/clang/Driver/CLCompatOptions.td index 62a4497ac4..3c2bef74ed 100644 --- a/include/clang/Driver/CLCompatOptions.td +++ b/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; +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; def _SLASH_execution_charset : CLCompileJoined<"execution-charset:">, diff --git a/include/clang/Driver/Job.h b/include/clang/Driver/Job.h index 47d9e992ba..7a0b769e44 100644 --- a/include/clang/Driver/Job.h +++ b/include/clang/Driver/Job.h @@ -59,6 +59,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; @@ -128,6 +131,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/lib/Driver/Job.cpp b/lib/Driver/Job.cpp index bd1a9bd8e3..114efe1998 100644 --- a/lib/Driver/Job.cpp +++ b/lib/Driver/Job.cpp @@ -315,6 +315,12 @@ void Command::setEnvironment(llvm::ArrayRef NewEnvironment) { int Command::Execute(ArrayRef> 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 Argv; Optional> Env; diff --git a/lib/Driver/ToolChains/Clang.cpp b/lib/Driver/ToolChains/Clang.cpp index 127f806962..4d2cb14a51 100644 --- a/lib/Driver/ToolChains/Clang.cpp +++ b/lib/Driver/ToolChains/Clang.cpp @@ -5067,6 +5067,13 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, C.addCommand(llvm::make_unique(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/test/Driver/cl-showfilenames.c b/test/Driver/cl-showfilenames.c new file mode 100644 index 0000000000..39620036e1 --- /dev/null +++ b/test/Driver/cl-showfilenames.c @@ -0,0 +1,19 @@ +// RUN: %clang_cl /c /showFilenames -- %s 2>&1 | FileCheck -check-prefix=show %s +// RUN: %clang_cl /c /showFilenames -- %s %S/Inputs/wildcard*.c 2>&1 | FileCheck -check-prefix=multiple %s + +// RUN: %clang_cl /c -- %s 2>&1 | FileCheck -check-prefix=noshow %s +// RUN: %clang_cl /c /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 -- 2.40.0