[PATCH] D52773: clang-cl: Add /showFilenames option (PR31957)

Hans Wennborg via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Oct 2 02:09:17 PDT 2018


hans created this revision.
hans added reviewers: rnk, thakis, zturner, steveire.

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.


https://reviews.llvm.org/D52773

Files:
  include/clang/Driver/CC1Options.td
  include/clang/Driver/CLCompatOptions.td
  lib/Driver/ToolChains/Clang.cpp
  lib/Frontend/CompilerInvocation.cpp
  test/CodeGen/echo-main-filename.c
  test/Driver/cl-options.c


Index: test/Driver/cl-options.c
===================================================================
--- test/Driver/cl-options.c
+++ test/Driver/cl-options.c
@@ -294,6 +294,9 @@
 // RUN: %clang_cl /d1PP -### -- %s 2>&1 | FileCheck -check-prefix=d1PP %s
 // d1PP: -dD
 
+// RUN: %clang_cl /showFilenames -### -- %s 2>&1 | FileCheck -check-prefix=showFilenames %s
+// showFilenames: -echo-main-file-name
+
 // We forward any unrecognized -W diagnostic options to cc1.
 // RUN: %clang_cl -Wunused-pragmas -### -- %s 2>&1 | FileCheck -check-prefix=WJoined %s
 // WJoined: "-cc1"
Index: test/CodeGen/echo-main-filename.c
===================================================================
--- /dev/null
+++ test/CodeGen/echo-main-filename.c
@@ -0,0 +1,3 @@
+// RUN: %clang_cc1 -main-file-name foobar -echo-main-file-name %s -emit-llvm -o - | FileCheck %s
+
+// CHECK: foobar
Index: lib/Frontend/CompilerInvocation.cpp
===================================================================
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -789,6 +789,9 @@
   Opts.PreferVectorWidth = Args.getLastArgValue(OPT_mprefer_vector_width_EQ);
 
   Opts.MainFileName = Args.getLastArgValue(OPT_main_file_name);
+  if (Args.hasArg(OPT_echo_main_file_name))
+    llvm::outs() << Opts.MainFileName << "\n";
+
   Opts.VerifyModule = !Args.hasArg(OPT_disable_llvm_verifier);
 
   Opts.ControlFlowGuard = Args.hasArg(OPT_cfguard);
Index: lib/Driver/ToolChains/Clang.cpp
===================================================================
--- lib/Driver/ToolChains/Clang.cpp
+++ lib/Driver/ToolChains/Clang.cpp
@@ -3530,6 +3530,8 @@
   // -save-temps.
   CmdArgs.push_back("-main-file-name");
   CmdArgs.push_back(getBaseInputName(Args, Input));
+  if (Arg *A = Args.getLastArg(options::OPT_echo_main_file_name))
+    A->render(Args, CmdArgs);
 
   // Some flags which affect the language (via preprocessor
   // defines).
Index: include/clang/Driver/CLCompatOptions.td
===================================================================
--- include/clang/Driver/CLCompatOptions.td
+++ include/clang/Driver/CLCompatOptions.td
@@ -158,6 +158,9 @@
 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">,
+  Alias<echo_main_file_name>;
 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:">,
Index: include/clang/Driver/CC1Options.td
===================================================================
--- include/clang/Driver/CC1Options.td
+++ include/clang/Driver/CC1Options.td
@@ -636,6 +636,8 @@
 
 }
 
+def echo_main_file_name : Flag<["-"], "echo-main-file-name">,
+  HelpText<"Echo the main file name">;
 def fblocks_runtime_optional : Flag<["-"], "fblocks-runtime-optional">,
   HelpText<"Weakly link in the blocks runtime">;
 def fexternc_nounwind : Flag<["-"], "fexternc-nounwind">,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D52773.167893.patch
Type: text/x-patch
Size: 3141 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20181002/d50634ad/attachment-0001.bin>


More information about the cfe-commits mailing list