Bug 1467897 Allow local runs of build-clang by providing a --base-dir option r?glandium draft
authorTom Ritter <tom@mozilla.com>
Tue, 05 Jun 2018 14:01:59 -0500
changeset 812576 b5e944ed3401232e843b6acb97ac0f913aab07e2
parent 806052 b967fee7396ead1998d5850319944bb5a2e102b8
push id114600
push userbmo:tom@mozilla.com
push dateFri, 29 Jun 2018 16:59:46 +0000
reviewersglandium
bugs1467897
milestone62.0a1
Bug 1467897 Allow local runs of build-clang by providing a --base-dir option r?glandium MozReview-Commit-ID: Gd9W1DV5g1x
build/build-clang/build-clang.py
--- a/build/build-clang/build-clang.py
+++ b/build/build-clang/build-clang.py
@@ -320,35 +320,66 @@ def prune_final_dir_for_clang_tidy(final
         if os.path.basename(f) != "clang":
             delete(f)
     for f in glob.glob("%s/share/clang/*" % final_dir):
         if re_clang_tidy.search(os.path.basename(f)) is None:
             delete(f)
 
 
 if __name__ == "__main__":
+    parser = argparse.ArgumentParser()
+    parser.add_argument('-c', '--config', required=True,
+                        type=argparse.FileType('r'),
+                        help="Clang configuration file")
+    parser.add_argument('-b', '--base-dir', required=False,
+                        type=str,
+                        help="Base directory for code and build artifacts")
+    parser.add_argument('--clean', required=False,
+                        action='store_true',
+                        help="Clean the build directory")
+    parser.add_argument('--skip-tar', required=False,
+                        action='store_true',
+                        help="Skip tar packaging stage")
+
+    args = parser.parse_args()
+
     # The directories end up in the debug info, so the easy way of getting
     # a reproducible build is to run it in a know absolute directory.
     # We use a directory that is registered as a volume in the Docker image.
-    base_dir = "/builds/worker/workspace/moz-toolchain"
 
-    if is_windows():
+    if args.base_dir:
+        base_dir = args.base_dir
+    elif os.environ.get('MOZ_AUTOMATION') and not is_windows():
+        base_dir = "/builds/worker/workspace/moz-toolchain"
+    else:
+        # Handles both the Windows automation case and the local build case
         # TODO: Because Windows taskcluster builds are run with distinct
         # user IDs for each job, we can't store things in some globally
         # accessible directory: one job will run, checkout LLVM to that
         # directory, and then if another job runs, the new user won't be
         # able to access the previously-checked out code--or be able to
         # delete it.  So on Windows, we build in the task-specific home
         # directory; we will eventually add -fdebug-prefix-map options
         # to the LLVM build to bring back reproducibility.
-        base_dir = os.path.join(os.getcwd(), 'llvm-sources')
+        base_dir = os.path.join(os.getcwd(), 'build-clang')
 
     source_dir = base_dir + "/src"
     build_dir = base_dir + "/build"
 
+    if args.clean:
+        shutil.rmtree(build_dir)
+        os.sys.exit(0)
+
+    if not os.path.exists(base_dir):
+        os.makedirs(base_dir)
+    elif os.listdir(base_dir) and '.build-clang' not in os.listdir(base_dir):
+        raise ValueError("Base directory %s exists and is not a build-clang directory. " \
+                         "Supply a non-existent or empty directory with --base-dir" % base_dir)
+    open(os.path.join(base_dir, '.build-clang'), 'a').close()
+
     llvm_source_dir = source_dir + "/llvm"
     clang_source_dir = source_dir + "/clang"
     extra_source_dir = source_dir + "/extra"
     lld_source_dir = source_dir + "/lld"
     compiler_rt_source_dir = source_dir + "/compiler-rt"
     libcxx_source_dir = source_dir + "/libcxx"
     libcxxabi_source_dir = source_dir + "/libcxxabi"
 
@@ -360,34 +391,18 @@ if __name__ == "__main__":
         exe_ext = ".exe"
 
     cc_name = "clang"
     cxx_name = "clang++"
     if is_windows():
         cc_name = "clang-cl"
         cxx_name = "clang-cl"
 
-    parser = argparse.ArgumentParser()
-    parser.add_argument('-c', '--config', required=True,
-                        type=argparse.FileType('r'),
-                        help="Clang configuration file")
-    parser.add_argument('--clean', required=False,
-                        action='store_true',
-                        help="Clean the build directory")
-    parser.add_argument('--skip-tar', required=False,
-                        action='store_true',
-                        help="Skip tar packaging stage")
-
-    args = parser.parse_args()
     config = json.load(args.config)
 
-    if args.clean:
-        shutil.rmtree(build_dir)
-        os.sys.exit(0)
-
     llvm_revision = config["llvm_revision"]
     llvm_repo = config["llvm_repo"]
     clang_repo = config["clang_repo"]
     extra_repo = config.get("extra_repo")
     lld_repo = config.get("lld_repo")
     compiler_repo = config["compiler_repo"]
     libcxx_repo = config["libcxx_repo"]
     libcxxabi_repo = config.get("libcxxabi_repo")