1
0
Fork 0
llvm-premerge-checks/scripts/run_ninja.py

65 lines
2.3 KiB
Python
Raw Normal View History

#!/usr/bin/env python3
# Copyright 2020 Google LLC
#
# Licensed under the the Apache License v2.0 with LLVM Exceptions (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://llvm.org/LICENSE.txt
#
# 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 os
import platform
2020-05-04 16:22:49 +02:00
import shutil
import subprocess
2020-05-25 16:42:40 +02:00
import sys
2020-05-04 16:16:50 +02:00
2020-05-25 16:42:40 +02:00
def check_sccache(dryrun: bool):
2020-05-04 16:22:49 +02:00
"""check if sccache can be started
Wipe local cache folder if it fails with a timeout.
This is based on the problem described here:
https://github.com/google/llvm-premerge-checks/wiki/LLVM-pre-merge-tests-operations-blog#2020-05-04
"""
if platform.system() != 'Windows':
return
if 'SCCACHE_DIR' not in os.environ:
return
sccache_dir = os.environ['SCCACHE_DIR']
result = subprocess.run('sccache --start-server', shell=True, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, text=True)
if result.returncode == 0:
return
if result.stderr is not None and 'Timed out waiting for server startup' in result.stderr:
print('sccache failed with timeout. Wiping local cache dir {}'.format(sccache_dir))
if dryrun:
print('Dryrun. Not deleting anything.')
2020-05-25 16:42:40 +02:00
else:
2020-05-04 16:22:49 +02:00
shutil.rmtree(sccache_dir)
2020-05-25 16:42:40 +02:00
def run_ninja(target: str, work_dir: str, *, dryrun: bool = False):
check_sccache(dryrun)
cmd = 'ninja {}'.format(target)
2020-05-04 16:16:50 +02:00
if dryrun:
print('Dryrun. Command would have been:\n{}'.format(cmd))
2020-05-25 16:42:40 +02:00
return 0
2020-05-04 16:16:50 +02:00
else:
2020-05-25 16:42:40 +02:00
return subprocess.call(cmd, shell=True, cwd=work_dir)
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Run ninja for LLVM.')
parser.add_argument('target')
parser.add_argument('repo_path', type=str, nargs='?', default=os.getcwd())
2020-05-04 16:16:50 +02:00
parser.add_argument('--dryrun', action='store_true')
args = parser.parse_args()
2020-05-25 16:42:40 +02:00
sys.exit(run_ninja(args.target, os.path.join(args.repo_path, 'build'), dryrun=args.dryrun))