[PATCH] D45152: [MinGW] Add option for disabling looking for a mingw gcc in PATH

Martin Storsjö via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun Apr 1 14:40:23 PDT 2018


mstorsjo created this revision.
mstorsjo added reviewers: martell, compnerd, rnk, mati865, ismail, yaron.keren.

This avoids looking for a mingw gcc to use as sysroot, preferring the clang installation itself over a similar gcc found in the path.

The option name, `--ignore-gcc`, might not be ideal - any suggestions for a better name?

Currently, I'm injecting a --sysroot parameter via a wrapper script, forcing the clang invocation to use `clang_bin/../triple` as sysroot, even if there's a similar named cross gcc elsewhere in PATH. With this option, I wouldn't need to use a wrapper script to manually set the sysroot.


Repository:
  rC Clang

https://reviews.llvm.org/D45152

Files:
  include/clang/Driver/Options.td
  lib/Driver/ToolChains/MinGW.cpp
  test/Driver/Inputs/mingw_gcc/bin/x86_64-w64-mingw32-gcc
  test/Driver/Inputs/mingw_gcc/x86_64-w64-mingw32/include/.keep
  test/Driver/mingw-gcc.c


Index: test/Driver/mingw-gcc.c
===================================================================
--- /dev/null
+++ test/Driver/mingw-gcc.c
@@ -0,0 +1,7 @@
+// RUN: env PATH=%S/Inputs/mingw_gcc/bin \
+// RUN:    %clang -target x86_64-w64-mingw32 -c -### %s 2>&1 | FileCheck -check-prefix=CHECK_MINGW_GCC %s
+// CHECK_MINGW_GCC: "{{.*}}{{/|\\\\}}Inputs{{/|\\\\}}mingw_gcc{{/|\\\\}}x86_64-w64-mingw32{{/|\\\\}}include"
+
+// RUN: env PATH=%S/Inputs/mingw_gcc/bin \
+// RUN:    %clang -target x86_64-w64-mingw32 -c -### %s --ignore-gcc 2>&1 | FileCheck -check-prefix=CHECK_NOT_MINGW_GCC %s
+// CHECK_NOT_MINGW_GCC-NOT: "{{.*}}{{/|\\\\}}Inputs{{/|\\\\}}mingw_gcc{{/|\\\\}}x86_64-w64-mingw32{{/|\\\\}}include"
Index: lib/Driver/ToolChains/MinGW.cpp
===================================================================
--- lib/Driver/ToolChains/MinGW.cpp
+++ lib/Driver/ToolChains/MinGW.cpp
@@ -309,11 +309,14 @@
 
   if (getDriver().SysRoot.size())
     Base = getDriver().SysRoot;
-  else if (llvm::ErrorOr<std::string> GPPName = findGcc())
-    Base = llvm::sys::path::parent_path(
-        llvm::sys::path::parent_path(GPPName.get()));
-  else
-    Base = llvm::sys::path::parent_path(getDriver().getInstalledDir());
+  else {
+    llvm::ErrorOr<std::string> GPPName("");
+    if (!Args.hasArg(options::OPT_ignore_gcc) && (GPPName = findGcc()))
+      Base = llvm::sys::path::parent_path(
+          llvm::sys::path::parent_path(GPPName.get()));
+    else
+      Base = llvm::sys::path::parent_path(getDriver().getInstalledDir());
+  }
 
   Base += llvm::sys::path::get_separator();
   findGccLibDir();
Index: include/clang/Driver/Options.td
===================================================================
--- include/clang/Driver/Options.td
+++ include/clang/Driver/Options.td
@@ -1732,6 +1732,8 @@
   HelpText<"Add directory to SYSTEM framework search path, "
            "absolute paths are relative to -isysroot">,
   MetaVarName<"<directory>">, Flags<[CC1Option]>;
+def ignore_gcc : Joined<["--"], "ignore-gcc">, Flags<[DriverOption]>,
+  HelpText<"Don't look for gcc for finding a suitable sysroot">;
 def imacros : JoinedOrSeparate<["-", "--"], "imacros">, Group<clang_i_Group>, Flags<[CC1Option]>,
   HelpText<"Include macros from file before parsing">, MetaVarName<"<file>">;
 def image__base : Separate<["-"], "image_base">;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D45152.140597.patch
Type: text/x-patch
Size: 2337 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180401/40fe4b60/attachment-0001.bin>


More information about the cfe-commits mailing list