[cfe-commits] r116912 - in /cfe/trunk: lib/Driver/Tools.cpp test/Driver/sysroot-flags.c

Chandler Carruth chandlerc at gmail.com
Wed Oct 20 00:00:47 PDT 2010


Author: chandlerc
Date: Wed Oct 20 02:00:47 2010
New Revision: 116912

URL: http://llvm.org/viewvc/llvm-project?rev=116912&view=rev
Log:
Add support for the '--sysroot' flag, and an accompanying test of its
interactions with -isysroot and other driver commands.

Added:
    cfe/trunk/test/Driver/sysroot-flags.c
Modified:
    cfe/trunk/lib/Driver/Tools.cpp

Modified: cfe/trunk/lib/Driver/Tools.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=116912&r1=116911&r2=116912&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/Tools.cpp (original)
+++ cfe/trunk/lib/Driver/Tools.cpp Wed Oct 20 02:00:47 2010
@@ -295,6 +295,15 @@
   // -I- is a deprecated GCC feature, reject it.
   if (Arg *A = Args.getLastArg(options::OPT_I_))
     D.Diag(clang::diag::err_drv_I_dash_not_supported) << A->getAsString(Args);
+
+  // If we have a --sysroot, and don't have an explicit -isysroot flag, add an
+  // -isysroot to the CC1 invocation.
+  if (Arg *A = Args.getLastArg(options::OPT__sysroot_EQ)) {
+    if (!Args.hasArg(options::OPT_isysroot)) {
+      CmdArgs.push_back("-isysroot");
+      CmdArgs.push_back(A->getValue(Args));
+    }
+  }
 }
 
 /// getARMTargetCPU - Get the (LLVM) name of the ARM cpu we are targetting.

Added: cfe/trunk/test/Driver/sysroot-flags.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/sysroot-flags.c?rev=116912&view=auto
==============================================================================
--- cfe/trunk/test/Driver/sysroot-flags.c (added)
+++ cfe/trunk/test/Driver/sysroot-flags.c Wed Oct 20 02:00:47 2010
@@ -0,0 +1,26 @@
+// Check for proper handling of --sysroot and -isysroot flags.
+
+// RUN: %clang -### -fsyntax-only -isysroot /foo/bar %s |& \
+// RUN:   FileCheck %s -check-prefix=ISYSROOT
+// ISYSROOT: "-isysroot" "/foo/bar"
+
+// Check that we get both isysroot for headers, and pass --sysroot on to GCC to
+// produce the final binary.
+// RUN: %clang -### -triple x86_64-unknown-linux-gnu --sysroot=/foo/bar \
+// RUN:   -o /dev/null %s |& FileCheck %s -check-prefix=SYSROOT_EQ
+// SYSROOT_EQ: "-isysroot" "/foo/bar"
+// SYSROOT_EQ: "--sysroot=/foo/bar"
+
+// Check for overriding the header sysroot by providing both --sysroot and
+// -isysroot.
+// RUN: %clang -### -triple x86_64-unknown-linux-gnu -isysroot /baz \
+// RUN:   --sysroot=/foo/bar -o /dev/null %s |& FileCheck %s \
+// RUN:   -check-prefix=ISYSROOT_AND_SYSROOT
+// ISYSROOT_AND_SYSROOT: "-isysroot" "/baz"
+// ISYSROOT_AND_SYSROOT: "--sysroot=/foo/bar"
+
+// Check that omitting the equals works as well.
+// RUN: %clang -### -triple x86_64-unknown-linux-gnu --sysroot /foo/bar \
+// RUN:   -o /dev/null %s |& FileCheck %s -check-prefix=SYSROOT_SEPARATE
+// SYSROOT_SEPARATE: "-isysroot" "/foo/bar"
+// SYSROOT_SEPARATE: "--sysroot=/foo/bar"





More information about the cfe-commits mailing list