Use sandboxed clang

Change-Id: I0b9b5b7940b441aba6c6214e621d8997feef90b1
diff --git a/tools/cpp/CROSSTOOL b/tools/cpp/CROSSTOOL
index 55abdc4..b29c5ad 100644
--- a/tools/cpp/CROSSTOOL
+++ b/tools/cpp/CROSSTOOL
@@ -79,38 +79,64 @@
   target_system_name: "k8"
   toolchain_identifier: "k8_linux"
 
-  tool_path { name: "ar" path: "/usr/bin/ar" }
-  tool_path { name: "compat-ld" path: "/usr/bin/ld" }
-  tool_path { name: "cpp" path: "/usr/bin/cpp" }
-  tool_path { name: "dwp" path: "/usr/bin/dwp" }
-  tool_path { name: "gcc" path: "/usr/bin/clang-3.6" }
-  tool_path { name: "gcov" path: "/usr/bin/gcov" }
+  # These paths are relative to //tools/cpp.
+  tool_path { name: "ar" path: "clang_3p6/x86_64-linux-gnu-ar" }
+  tool_path { name: "compat-ld" path: "clang_3p6/x86_64-linux-gnu-ld" }
+  tool_path { name: "cpp" path: "clang_3p6/x86_64-linux-gnu-cpp" }
+  tool_path { name: "dwp" path: "clang_3p6/x86_64-linux-gnu-dwp" }
+  tool_path { name: "gcc" path: "clang_3p6/x86_64-linux-gnu-clang-3.6" }
+  tool_path { name: "gcov" path: "clang_3p6/x86_64-linux-gnu-gcov" }
   # C(++) compiles invoke the compiler (as that is the one knowing where
   # to find libraries), but we provide LD so other rules can invoke the linker.
-  tool_path { name: "ld" path: "/usr/bin/ld" }
-  tool_path { name: "nm" path: "/usr/bin/nm" }
-  tool_path { name: "objcopy" path: "/usr/bin/objcopy" }
+  tool_path { name: "ld" path: "clang_3p6/x86_64-linux-gnu-ld" }
+  tool_path { name: "nm" path: "clang_3p6/x86_64-linux-gnu-nm" }
+  tool_path { name: "objcopy" path: "clang_3p6/x86_64-linux-gnu-objcopy" }
   objcopy_embed_flag: "-I"
   objcopy_embed_flag: "binary"
-  tool_path { name: "objdump" path: "/usr/bin/objdump" }
-  tool_path { name: "strip" path: "/usr/bin/strip" }
+  tool_path { name: "objdump" path: "clang_3p6/x86_64-linux-gnu-objdump" }
+  tool_path { name: "strip" path: "clang_3p6/x86_64-linux-gnu-strip" }
   linking_mode_flags { mode: DYNAMIC }
 
+  compiler_flag: "--sysroot=external/clang_3p6_repo/"
+  compiler_flag: "-nostdinc"
+  compiler_flag: "-isystem"
+  compiler_flag: "external/clang_3p6_repo/usr/include",
+  compiler_flag: "-isystem"
+  compiler_flag: "external/clang_3p6_repo/usr/include/x86_64-linux-gnu",
+  compiler_flag: "-isystem"
+  compiler_flag: "external/clang_3p6_repo/usr/lib/llvm-3.6/lib/clang/3.6.2/include",
+
+  cxx_flag: "-isystem"
+  cxx_flag: "external/clang_3p6_repo/usr/include/c++/4.9"
+  cxx_flag: "-isystem"
+  cxx_flag: "external/clang_3p6_repo/usr/include/x86_64-linux-gnu/c++/4.9"
+  cxx_flag: "-isystem"
+  cxx_flag: "external/clang_3p6_repo/usr/include/c++/4.9/backward"
+
   # TODO(bazel-team): In theory, the path here ought to exactly match the path
   # used by gcc. That works because bazel currently doesn't track files at
   # absolute locations and has no remote execution, yet. However, this will need
   # to be fixed, maybe with auto-detection?
-  cxx_builtin_include_directory: '/usr/include/c++/4.9'
-  cxx_builtin_include_directory: '/usr/include/x86_64-linux-gnu/c++/4.9'
-  cxx_builtin_include_directory: '/usr/include/c++/4.9/backward'
-  cxx_builtin_include_directory: '/usr/local/include'
-  cxx_builtin_include_directory: '/usr/lib/llvm-3.6/lib/clang/3.6.2/include'
-  cxx_builtin_include_directory: '/usr/include/x86_64-linux-gnu'
-  cxx_builtin_include_directory: '/usr/include'
-  cxx_builtin_include_directory: '/usr/lib/clang/3.6.2/include'
+  cxx_builtin_include_directory: '%package(@clang_3p6_repo//usr)%/include/c++/4.9'
+  cxx_builtin_include_directory: '%package(@clang_3p6_repo//usr)%/include/x86_64-linux-gnu/c++/4.9'
+  cxx_builtin_include_directory: '%package(@clang_3p6_repo//usr)%/include/c++/4.9/backward'
+  cxx_builtin_include_directory: '%package(@clang_3p6_repo//usr)%/local/include'
+  cxx_builtin_include_directory: '%package(@clang_3p6_repo//usr)%/lib/llvm-3.6/lib/clang/3.6.2/include'
+  cxx_builtin_include_directory: '%package(@clang_3p6_repo//usr)%/include/x86_64-linux-gnu'
+  cxx_builtin_include_directory: '%package(@clang_3p6_repo//usr)%/include'
+  cxx_builtin_include_directory: '%package(@clang_3p6_repo//usr)%/lib/clang/3.6.2/include'
 
+  linker_flag: "-nodefaultlibs"
+  linker_flag: "--sysroot=external/clang_3p6_repo/"
   linker_flag: "-lstdc++"
-  linker_flag: "-B/usr/bin/"
+  linker_flag: "-lc"
+  linker_flag: "-lgcc"
+  linker_flag: "-lgcc_s"
+  linker_flag: "-Bexternal/clang_3p6_repo/usr/bin/"
+  linker_flag: "-Ltools/cpp/clang_3p6/clang_more_libs"
+  linker_flag: "-Lexternal/clang_3p6/lib/x86_64-linux-gnu"
+  linker_flag: "-Lexternal/clang_3p6/usr/lib/x86_64-linux-gnu"
+  linker_flag: "-Lexternal/clang_3p6/usr/lib/gcc/x86_64-linux-gnu"
 
   feature {
     name: "opt"