diff --git a/Jenkinsfile b/Jenkinsfile index 9fda569d55997..7fa9bdb52da97 100755 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -249,7 +249,7 @@ def cmake_build(image, path, make_flag) { variable: 'SCCACHE_BUCKET', )]) { sh ( - script: "${docker_run} ${image} ./tests/scripts/task_build.sh ${path} ${make_flag} ${SCCACHE_BUCKET}", + script: "${docker_run} ${image} ./tests/scripts/task_build.py --num-executors ${CI_NUM_EXECUTORS} --sccache-bucket ${SCCACHE_BUCKET} --node-name ${NODE_NAME}", label: 'Run cmake build', ) } diff --git a/tests/scripts/cmd_utils.py b/tests/scripts/cmd_utils.py new file mode 100644 index 0000000000000..5c7973c40e32b --- /dev/null +++ b/tests/scripts/cmd_utils.py @@ -0,0 +1,35 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import subprocess +import os + + +class Sh: + def __init__(self, env=None): + self.env = os.environ.copy() + if env is not None: + self.env.update(env) + + def run(self, cmd: str, **kwargs): + print("+", cmd) + if "check" not in kwargs: + kwargs["check"] = True + if "shell" not in kwargs: + kwargs["shell"] = True + + subprocess.run(cmd, **kwargs) diff --git a/tests/scripts/task_build.py b/tests/scripts/task_build.py new file mode 100755 index 0000000000000..eef7e2e4cb89f --- /dev/null +++ b/tests/scripts/task_build.py @@ -0,0 +1,63 @@ +#!/usr/bin/env python3 +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +import argparse +import shutil +import os +import base64 +import multiprocessing + +from pathlib import Path +from cmd_utils import Sh + + +if __name__ == "__main__": + parser = argparse.ArgumentParser(description="List pytest nodeids for a folder") + parser.add_argument("--node-name", required=True, help="Jenkins executor node name") + parser.add_argument("--sccache-bucket", required=True, help="sccache bucket name") + parser.add_argument("--num-executors", required=True, help="number of Jenkins executors") + parser.add_argument("--path", default="build", help="build folder") + args = parser.parse_args() + + env = {"VTA_HW_PATH": Path(os.getcwd()) / "3rdparty" / "vta-hw"} + use_sccache = shutil.which("sccache") is not None + if use_sccache: + env["SCCACHE_BUCKET"] = args.sccache_bucket + env["CXX"] = "/opt/sccache/c++" + env["CC"] = "/opt/sccache/cc" + + # Send this out through a side channel, the bucket name is not actually secret + # so it's OK to leak it in this way + print(f"Using sccache bucket: {base64.b64encode(args.sccache_bucket.encode())}") + + sh = Sh(env) + + if use_sccache: + sh.run("sccache --start-server", check=False) + sh.run("sccache --show-stats") + + executors = int(args.num_executors) + nproc = multiprocessing.cpu_count() + + available_cpus = nproc // executors + num_cpus = max(available_cpus, 1) + + sh.run("cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo ..") + sh.run(f"cmake --build . -- VERBOSE=1 -j{num_cpus}") + + if use_sccache: + sh.run("sccache --show-stats") diff --git a/tests/scripts/task_build.sh b/tests/scripts/task_build.sh index 5275655f3ac3a..b578a4adad8c0 100755 --- a/tests/scripts/task_build.sh +++ b/tests/scripts/task_build.sh @@ -15,41 +15,6 @@ # KIND, either express or implied. See the License for the # specific language governing permissions and limitations # under the License. -set -eux -VTA_HW_PATH=$(pwd)/3rdparty/vta-hw -export VTA_HW_PATH - -pushd "$1" - -# Set up sccache to use S3 -if [ -n "${3+x}" ] && which sccache; then - export SCCACHE_BUCKET=$3 - HAS_SCCACHE=1 -else - export SCCACHE_BUCKET="no-bucket-configured" - HAS_SCCACHE=0 -fi - -if [ "$HAS_SCCACHE" -eq "1" ]; then - echo "Running with sccache enabled" - export CC=/opt/sccache/cc - export CXX=/opt/sccache/c++ -fi - -# Send this out through a side channel, the bucket name is not actually secret -# so it's OK to leak it in this way -echo "$SCCACHE_BUCKET" | base64 - -if [ "$HAS_SCCACHE" -eq "1" ]; then - sccache --start-server || echo failed - sccache --show-stats -fi - -cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo .. -cmake --build . -- VERBOSE=1 "$2" - -if [ "$HAS_SCCACHE" -eq "1" ]; then - sccache --show-stats -fi -popd +# This file is intentionally left blank. Delete when +# https://github.com/apache/tvm/pull/ is merged \ No newline at end of file