From df7d744fecef34209817e55ea7d309f65288de92 Mon Sep 17 00:00:00 2001 From: Dennis Kempin Date: Wed, 27 Oct 2021 10:53:16 -0700 Subject: [PATCH] test_runner: Parallelize building of common/ crates Each of these is a separate workspace and can be built in parallel. BUG=b:195126527 TEST=./tools/run_tests Change-Id: I9ad61b5d5d83903fda36c948ba470bba8f608d46 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3248128 Commit-Queue: Dennis Kempin Tested-by: Dennis Kempin Reviewed-by: Daniel Verkamp --- tools/impl/test_runner.py | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/tools/impl/test_runner.py b/tools/impl/test_runner.py index c7afff2e7c..021eff48d4 100755 --- a/tools/impl/test_runner.py +++ b/tools/impl/test_runner.py @@ -203,6 +203,17 @@ def cargo_build_executables( yield from cargo("test", cwd, ["--no-run", *flags], env) +def build_common_crate(build_env: dict[str, str], crate_name: str): + print(f"Building tests for: common/{crate_name}") + return list( + cargo_build_executables( + [], + env=build_env, + cwd=COMMON_ROOT / crate_name, + ) + ) + + def build_all_binaries(target: TestTarget, target_arch: Arch): """Discover all crates and build them.""" build_env = os.environ.copy() @@ -219,15 +230,17 @@ def build_all_binaries(target: TestTarget, target_arch: Arch): main_crates, env=build_env, features=set(["all-linux"]) ) - for crate in list_common_crates(): - if not should_build_crate(crate, target_arch): - continue - print(f"Building tests for: common/{crate}") - yield from cargo_build_executables( - [], - env=build_env, - cwd=COMMON_ROOT / crate, - ) + common_crates = [ + crate + for crate in list_common_crates() + if should_build_crate(crate, target_arch) + ] + + with Pool(PARALLELISM) as pool: + for executables in pool.imap( + functools.partial(build_common_crate, build_env), common_crates + ): + yield from executables def execute_test(target: TestTarget, executable: Executable):