Merge "Hide the symbols in the builtins library"
diff --git a/constants.py b/constants.py
index ae45b83..a34cf5b 100644
--- a/constants.py
+++ b/constants.py
@@ -21,7 +21,7 @@
 MAC_MIN_VERSION: str = '10.10'
 
 # This is the baseline stable version of Clang to start our stage-1 build.
-CLANG_PREBUILT_VERSION: str = 'clang-r399163b'
+CLANG_PREBUILT_VERSION: str = 'clang-bootstrap'
 
 # This is the ndk version used to build runtimes.
 NDK_VERSION: str = 'r20'
diff --git a/patches/Ensure-that-we-use-our-toolchain-s-lipo-and-not-the-.patch b/patches/Ensure-that-we-use-our-toolchain-s-lipo-and-not-the-.patch
new file mode 100644
index 0000000..5d75365
--- /dev/null
+++ b/patches/Ensure-that-we-use-our-toolchain-s-lipo-and-not-the-.patch
@@ -0,0 +1,83 @@
+From 81e8e4a75774df541bc65d04369174da0e8caeec Mon Sep 17 00:00:00 2001
+From: Stephen Hines <srhines@google.com>
+Date: Fri, 18 Dec 2020 00:10:27 -0800
+Subject: [PATCH] Ensure that we use our toolchain's lipo, and not the system
+ version
+
+Change-Id: Ib505775e62e10e1821dc4e036daae46f2cff630f
+---
+ clang/CMakeLists.txt                                  | 5 +++++
+ clang/runtime/CMakeLists.txt                          | 1 +
+ compiler-rt/cmake/Modules/AddCompilerRT.cmake         | 1 +
+ compiler-rt/cmake/Modules/CompilerRTDarwinUtils.cmake | 2 +-
+ llvm/cmake/modules/LLVMExternalProjectUtils.cmake     | 1 +
+ 5 files changed, 9 insertions(+), 1 deletion(-)
+
+diff --git a/clang/CMakeLists.txt b/clang/CMakeLists.txt
+index 900ef0a4d73..cae5cfe7feb 100644
+--- a/clang/CMakeLists.txt
++++ b/clang/CMakeLists.txt
+@@ -782,6 +782,11 @@ if (CLANG_ENABLE_BOOTSTRAP)
+     set(PGO_OPT -DLLVM_PROFDATA=${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-profdata)
+   endif()
+ 
++  # Retain lipo configuration as needed
++  if(APPLE)
++    set(CMAKE_LIPO "lipo" CACHE FILEPATH "path to the lipo tool")
++  endif()
++
+   if(LLVM_BUILD_INSTRUMENTED)
+     add_dependencies(clang-bootstrap-deps generate-profdata)
+     set(PGO_OPT -DLLVM_PROFDATA_FILE=${CMAKE_CURRENT_BINARY_DIR}/utils/perf-training/clang.profdata)
+diff --git a/clang/runtime/CMakeLists.txt b/clang/runtime/CMakeLists.txt
+index 61bbbf8faed..9429de3116e 100644
+--- a/clang/runtime/CMakeLists.txt
++++ b/clang/runtime/CMakeLists.txt
+@@ -76,6 +76,7 @@ if(LLVM_BUILD_EXTERNAL_COMPILER_RT AND EXISTS ${COMPILER_RT_SRC_ROOT}/)
+                -DCMAKE_C_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/clang
+                -DCMAKE_CXX_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/clang++
+                -DCMAKE_ASM_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/clang
++               -DCMAKE_LIPO=${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-lipo
+                -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
+                -DCMAKE_MAKE_PROGRAM=${CMAKE_MAKE_PROGRAM}
+                -DLLVM_CONFIG_PATH=${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-config
+diff --git a/compiler-rt/cmake/Modules/AddCompilerRT.cmake b/compiler-rt/cmake/Modules/AddCompilerRT.cmake
+index 90a946a0df7..66bd0a5761a 100644
+--- a/compiler-rt/cmake/Modules/AddCompilerRT.cmake
++++ b/compiler-rt/cmake/Modules/AddCompilerRT.cmake
+@@ -610,6 +610,7 @@ macro(add_custom_libcxx name prefix)
+     CMAKE_INSTALL_PREFIX
+     CMAKE_MAKE_PROGRAM
+     CMAKE_LINKER
++    CMAKE_LIPO
+     CMAKE_AR
+     CMAKE_RANLIB
+     CMAKE_NM
+diff --git a/compiler-rt/cmake/Modules/CompilerRTDarwinUtils.cmake b/compiler-rt/cmake/Modules/CompilerRTDarwinUtils.cmake
+index f6689c2e79a..02dc7f3c0fc 100644
+--- a/compiler-rt/cmake/Modules/CompilerRTDarwinUtils.cmake
++++ b/compiler-rt/cmake/Modules/CompilerRTDarwinUtils.cmake
+@@ -2,7 +2,7 @@ include(CMakeParseArguments)
+ include(CompilerRTUtils)
+ include(BuiltinTests)
+ 
+-set(CMAKE_LIPO "lipo" CACHE PATH "path to the lipo tool")
++#set(CMAKE_LIPO "lipo" CACHE PATH "path to the lipo tool")
+ 
+ # On OS X SDKs can be installed anywhere on the base system and xcode-select can
+ # set the default Xcode to use. This function finds the SDKs that are present in
+diff --git a/llvm/cmake/modules/LLVMExternalProjectUtils.cmake b/llvm/cmake/modules/LLVMExternalProjectUtils.cmake
+index 1b4a1f339e2..f68f38407ea 100644
+--- a/llvm/cmake/modules/LLVMExternalProjectUtils.cmake
++++ b/llvm/cmake/modules/LLVMExternalProjectUtils.cmake
+@@ -216,6 +216,7 @@ function(llvm_ExternalProject_Add name source_dir)
+                       -DCMAKE_LINKER=${CMAKE_LINKER}
+                       -DCMAKE_AR=${CMAKE_AR}
+                       -DCMAKE_RANLIB=${CMAKE_RANLIB}
++                      -DCMAKE_LIPO=${CMAKE_LIPO}
+                       -DCMAKE_NM=${CMAKE_NM}
+                       -DCMAKE_OBJCOPY=${CMAKE_OBJCOPY}
+                       -DCMAKE_OBJDUMP=${CMAKE_OBJDUMP}
+-- 
+2.29.2.729.g45daf8777d-goog
+
diff --git a/patches/PATCHES.json b/patches/PATCHES.json
index dba74ac..531b957 100644
--- a/patches/PATCHES.json
+++ b/patches/PATCHES.json
@@ -394,5 +394,11 @@
         "rel_patch_path": "Revert-Sema-Introduce-BuiltinAttr-per-declaration-bu.patch",
         "start_version": 407598,
         "end_version": null
+    },
+    {
+        "comment": "Ensure that we use our toolchain's lipo, and not the system version",
+        "rel_patch_path": "Ensure-that-we-use-our-toolchain-s-lipo-and-not-the-.patch",
+        "start_version": 407598,
+        "end_version": null
     }
-]
\ No newline at end of file
+]
diff --git a/test/scripts/ab_client.py b/test/scripts/ab_client.py
index cab4b06..a566f3c 100644
--- a/test/scripts/ab_client.py
+++ b/test/scripts/ab_client.py
@@ -93,19 +93,29 @@
                 workDone = worknode['status'] == 'complete'
                 continue
 
-            workOutput = worknode['workOutput']
-            success = workOutput['success']
+            workOutput = worknode.get('workOutput', None)
+            success = workOutput and workOutput['success']
             if msg == 'pendingChangeBuild':
                 work_type = 'BUILD'
                 params = worknode['workParameters']['submitQueue']
-                build_id = workOutput['buildOutput']['buildId']
+
+                # If workOutput is absent, Try to get build Id from
+                # workParameters.
+                if workOutput:
+                    build_id = workOutput['buildOutput']['buildId']
+                elif 'buildIds' in worknode['workParameters']['submitQueue']:
+                    # Just pick the first build Id.
+                    build_id = worknode['workParameters']['submitQueue'][
+                        'buildIds'][0]
+                else:
+                    build_id = 'NA'
                 test_name = 'NA'
                 ants_id = 'NA'
                 display_message = 'NA'
             elif msg == 'atpTest':
                 work_type = 'TEST'
                 params = worknode['workParameters']['atpTestParameters']
-                if 'testOutput' in workOutput:
+                if workOutput and 'testOutput' in workOutput:
                     build_id = workOutput['testOutput']['buildId']
                     ants_id = workOutput['testOutput']['antsInvocationId']
                 else:
diff --git a/test/scripts/test_prebuilts.py b/test/scripts/test_prebuilts.py
index c394ad9..9907474 100755
--- a/test/scripts/test_prebuilts.py
+++ b/test/scripts/test_prebuilts.py
@@ -306,7 +306,8 @@
     parser = argparse.ArgumentParser(
         description=inspect.getdoc(sys.modules[__name__]))
 
-    parser.add_argument('--build', help='Toolchain build number (from go/ab/).')
+    parser.add_argument(
+        '--build', help='Toolchain build number (from go/ab/).', required=True)
     parser.add_argument(
         '--prebuilt_cl',
         help='Prebuilts CL (to prebuilts/clang/host/linux-x86)')