|
| 1 | +#!/usr/bin/env python3 |
| 2 | +# For simplify migration between different CI |
| 3 | + |
| 4 | +import os, time, sys |
| 5 | +from pathlib import Path |
| 6 | +from subprocess import check_call |
| 7 | +from multiprocessing import cpu_count |
| 8 | + |
| 9 | +def show_timing(function): |
| 10 | + def _wrapper(*args, **kwargs): |
| 11 | + start = time.time() |
| 12 | + ret = function(*args, **kwargs) |
| 13 | + elapsed = (time.time() - start) |
| 14 | + print("%s elapsed time: %f" % (function.__name__, elapsed)) |
| 15 | + return ret |
| 16 | + return _wrapper |
| 17 | + |
| 18 | +def mkdir_if_not_exists(dir_path: str): |
| 19 | + if not os.path.exists(dir_path): |
| 20 | + os.makedirs(dir_path) |
| 21 | + |
| 22 | +def get_src_root_path(my_path: str) -> str: |
| 23 | + my_path = os.path.dirname(os.path.realpath(my_path)) |
| 24 | + return my_path |
| 25 | + |
| 26 | +@show_timing |
| 27 | +def build_and_test_cpp_part(src_root: str): |
| 28 | + cmake_build_dir = os.path.join(src_root, "build-cmake") |
| 29 | + cmake_src_dir = os.path.join(src_root, "couchbase-lite-core-sys", |
| 30 | + "couchbase-lite-core") |
| 31 | + mkdir_if_not_exists(cmake_build_dir) |
| 32 | + print("Current path: %s" % os.environ["PATH"]) |
| 33 | + check_call(["cmake", "-DCMAKE_BUILD_TYPE=RelWithDebInfo", cmake_src_dir], |
| 34 | + cwd = cmake_build_dir) |
| 35 | + check_call(["ls"], cwd = cmake_build_dir) |
| 36 | + check_call(["cmake", "--build", ".", "--", "-j%d" % (cpu_count() + 1)], |
| 37 | + cwd = cmake_build_dir) |
| 38 | + |
| 39 | +@show_timing |
| 40 | +def build_and_test_rust_part(src_root: str): |
| 41 | + print("running tests in debug mode") |
| 42 | + check_call(["cargo", "test", "--all", "-vv"], cwd = src_root) |
| 43 | + print("running tests in release mode") |
| 44 | + check_call(["cargo", "test", "--all", "--release", "-vv"], cwd = src_root) |
| 45 | + |
| 46 | +@show_timing |
| 47 | +def main(): |
| 48 | + ci_dir = Path(get_src_root_path(sys.argv[0])) |
| 49 | + src_root = ci_dir.parent |
| 50 | + build_and_test_cpp_part(src_root) |
| 51 | + build_and_test_rust_part(src_root) |
| 52 | + |
| 53 | +if __name__ == "__main__": |
| 54 | + main() |
0 commit comments