crosvm/ci/kokoro/simulate.py
Dennis Kempin 0520a95161 ci/kokoro: Pythonify the simulate script
Does the same thing, but in python. This should allow us to make
this work on windows as well.

BUG=b:216833094
TEST=./simulate.py build-x86_64.sh

Change-Id: If6eb214c2a3185fbb60a636b89cd03ecf28b42e1
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3425651
Reviewed-by: Vikram Auradkar <auradkar@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
Tested-by: Dennis Kempin <denniskempin@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
2022-01-29 16:49:32 +00:00

56 lines
1.5 KiB
Python
Executable file

#!/usr/bin/env python3
# Copyright 2022 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
from pathlib import Path
import argparse
import os
import subprocess
import tempfile
USAGE="""
Simulates a Kokoro run executing one of the build-* scripts.
Example:
$ cd ./ci/kokoro
$ ./simulate.py build-aarch64.sh
"""
CROSVM_ROOT = Path(__file__).parent.parent.parent.resolve()
def git_clone_source(source: Path, destination: Path):
destination.mkdir(parents=True, exist_ok=True)
print(f"Cloning {source} into {destination}:")
subprocess.check_call(['git', 'clone', '-q', source, destination])
def run_kokoro_build_script(kokoro_root: Path, script_path: Path):
print(f"Running {script_path}:")
env=os.environ.copy()
env['KOKORO_ARTIFACTS_DIR'] = str(kokoro_root / 'src')
subprocess.check_call([script_path.resolve()], cwd=kokoro_root, env=env)
def simulate_kokoro(kokoro_root: Path, script_path: Path):
git_clone_source(CROSVM_ROOT, kokoro_root / 'src/git/crosvm')
run_kokoro_build_script(kokoro_root, script_path)
def main():
parser = argparse.ArgumentParser(usage=USAGE)
parser.add_argument("script_name", type=Path)
args = parser.parse_args()
script_path: Path= args.script_name
if not script_path.exists():
raise ValueError(f"Script '{script_path} not found.")
with tempfile.TemporaryDirectory() as temp_dir:
simulate_kokoro(Path(temp_dir), script_path)
if __name__ == '__main__':
main()