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">;


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">;
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to