From 3ef3a30e7b28d29f8e33150111d49503192f6d3e Mon Sep 17 00:00:00 2001
From: Nehal J Wani <nehaljw.kkd1@gmail.com>
Date: Sat, 25 Aug 2018 09:20:04 -0500
Subject: [PATCH 3/8] clang: add conda specific env var CONDA_BUILD_SYSROOT

---
 clang/lib/Driver/Driver.cpp        | 9 +++++++--
 clang/lib/Lex/InitHeaderSearch.cpp | 6 +++++-
 2 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 3bfddeefc7b2..6f06900ed18a 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -1208,8 +1208,13 @@ Compilation *Driver::BuildCompilation(ArrayRef<const char *> ArgList) {
       CompilerPath = Split.second;
     }
   }
-  if (const Arg *A = Args.getLastArg(options::OPT__sysroot_EQ))
-    SysRoot = A->getValue();
+  if (Optional<std::string> CondaBuildSysrootValue =
+          llvm::sys::Process::GetEnv("CONDA_BUILD_SYSROOT")) {
+    SysRoot = *CondaBuildSysrootValue;
+  } else {
+    if (const Arg *A = Args.getLastArg(options::OPT__sysroot_EQ))
+      SysRoot = A->getValue();
+  }
   if (const Arg *A = Args.getLastArg(options::OPT__dyld_prefix_EQ))
     DyldPrefix = A->getValue();
 
diff --git a/clang/lib/Lex/InitHeaderSearch.cpp b/clang/lib/Lex/InitHeaderSearch.cpp
index ec7b1505c7bf..2996c41af5f0 100644
--- a/clang/lib/Lex/InitHeaderSearch.cpp
+++ b/clang/lib/Lex/InitHeaderSearch.cpp
@@ -25,6 +25,7 @@
 #include "llvm/ADT/Twine.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/Path.h"
+#include "llvm/Support/Process.h"
 #include "llvm/Support/raw_ostream.h"
 
 using namespace clang;
@@ -248,7 +249,10 @@ void InitHeaderSearch::AddDefaultCIncludePaths(const llvm::Triple &triple,
       LLVM_FALLTHROUGH;
     default:
       // FIXME: temporary hack: hard-coded paths.
-      AddPath("/usr/local/include", System, false);
+      Optional<std::string> CondaBuildSysrootValue =
+              llvm::sys::Process::GetEnv("CONDA_BUILD_SYSROOT");
+      if (!CondaBuildSysrootValue.hasValue())
+        AddPath("/usr/local/include", System, false);
       break;
     }
   }
-- 
2.35.3.windows.1

