|
| 1 | +#!/usr/bin/env python3 |
| 2 | +# Licensed to the Apache Software Foundation (ASF) under one |
| 3 | +# or more contributor license agreements. See the NOTICE file |
| 4 | +# distributed with this work for additional information |
| 5 | +# regarding copyright ownership. The ASF licenses this file |
| 6 | +# to you under the Apache License, Version 2.0 (the |
| 7 | +# "License"); you may not use this file except in compliance |
| 8 | +# with the License. You may obtain a copy of the License at |
| 9 | +# |
| 10 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +# |
| 12 | +# Unless required by applicable law or agreed to in writing, |
| 13 | +# software distributed under the License is distributed on an |
| 14 | +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | +# KIND, either express or implied. See the License for the |
| 16 | +# specific language governing permissions and limitations |
| 17 | +# under the License. |
| 18 | +import argparse |
| 19 | +import shutil |
| 20 | +import os |
| 21 | +import logging |
| 22 | +import multiprocessing |
| 23 | + |
| 24 | +from pathlib import Path |
| 25 | +from cmd_utils import Sh, init_log, REPO_ROOT |
| 26 | + |
| 27 | + |
| 28 | +if __name__ == "__main__": |
| 29 | + init_log() |
| 30 | + |
| 31 | + parser = argparse.ArgumentParser(description="List pytest nodeids for a folder") |
| 32 | + parser.add_argument("--sccache-bucket", required=False, help="sccache bucket name") |
| 33 | + parser.add_argument("--num-executors", required=True, help="number of Jenkins executors") |
| 34 | + parser.add_argument("--build-dir", default="build", help="build folder") |
| 35 | + args = parser.parse_args() |
| 36 | + |
| 37 | + env = {"VTA_HW_PATH": str(Path(os.getcwd()) / "3rdparty" / "vta-hw")} |
| 38 | + sccache_exe = shutil.which("sccache") |
| 39 | + |
| 40 | + use_sccache = sccache_exe is not None and args.sccache_bucket is not None |
| 41 | + build_dir = Path(os.getcwd()) / args.build_dir |
| 42 | + build_dir = build_dir.relative_to(REPO_ROOT) |
| 43 | + |
| 44 | + if use_sccache: |
| 45 | + env["SCCACHE_BUCKET"] = args.sccache_bucket |
| 46 | + env["CXX"] = "/opt/sccache/c++" |
| 47 | + env["CC"] = "/opt/sccache/cc" |
| 48 | + |
| 49 | + logging.info(f"Using sccache bucket: {args.sccache_bucket}") |
| 50 | + else: |
| 51 | + if sccache_exe is None: |
| 52 | + reason = "'sccache' executable not found" |
| 53 | + elif args.sccache_bucket is None: |
| 54 | + reason = "'sccache' executable not found" |
| 55 | + else: |
| 56 | + reason = "<unknown>" |
| 57 | + logging.info(f"Not using sccache, reason: {reason}") |
| 58 | + |
| 59 | + sh = Sh(env) |
| 60 | + |
| 61 | + if use_sccache: |
| 62 | + sh.run("sccache --start-server", check=False) |
| 63 | + logging.info("===== sccache stats =====") |
| 64 | + sh.run("sccache --show-stats") |
| 65 | + |
| 66 | + executors = int(args.num_executors) |
| 67 | + nproc = multiprocessing.cpu_count() |
| 68 | + |
| 69 | + available_cpus = nproc // executors |
| 70 | + num_cpus = max(available_cpus, 1) |
| 71 | + |
| 72 | + sh.run("cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo ..", cwd=build_dir) |
| 73 | + sh.run(f"cmake --build . -- VERBOSE=1 -j{num_cpus}", cwd=build_dir) |
| 74 | + |
| 75 | + if use_sccache: |
| 76 | + logging.info("===== sccache stats =====") |
| 77 | + sh.run("sccache --show-stats") |
0 commit comments