diff options
| author | quapka | 2024-08-12 14:50:48 +0200 |
|---|---|---|
| committer | quapka | 2024-08-12 14:50:48 +0200 |
| commit | 23e27b1e8ab5769ac1578c2670b132a26b58fd7e (patch) | |
| tree | f0acf49ee99d6ce4c57520c84dcfbe26261c0d9d | |
| parent | b83164b1402e96d5b20d36b5941b79f5636dba71 (diff) | |
| download | ECTester-23e27b1e8ab5769ac1578c2670b132a26b58fd7e.tar.gz ECTester-23e27b1e8ab5769ac1578c2670b132a26b58fd7e.tar.zst ECTester-23e27b1e8ab5769ac1578c2670b132a26b58fd7e.zip | |
| -rw-r--r-- | .gitignore | 1 | ||||
| -rw-r--r-- | test_building_all.py | 51 |
2 files changed, 43 insertions, 9 deletions
@@ -46,3 +46,4 @@ # Ignore Gradle build output directory build +build_all diff --git a/test_building_all.py b/test_building_all.py index bf2c509..6303ef9 100644 --- a/test_building_all.py +++ b/test_building_all.py @@ -4,6 +4,8 @@ import argparse import json import time +from pathlib import Path + import subprocess as sp def get_all_versions(library): @@ -12,15 +14,24 @@ def get_all_versions(library): return versions -def can_build(library, version, variant): +def attempt_build(library, version, variant): cmd = ["nix", "build", f".#{variant}.{library}.{version}"] start = time.time() + + result = {} try: sp.check_output(cmd, stderr=sp.STDOUT) + success = True + stderr = "" except sp.CalledProcessError as e: - print(e.output.decode()) - return False, time.time() - start - return True, time.time() - start + stderr = e.output.decode() + success = False + + result['build_time'] = time.time() - start + result['success'] = success + result['stderr'] = stderr.split('\n') if stderr else [] + + return result def valid_build_type(value): value = value.strip() @@ -29,16 +40,30 @@ def valid_build_type(value): raise argparse.ArgumentTypeError(f"'{value}' not from expected {', '.join(valid_types)})") return value +def save_build_result(library, variant, version, result): + resdir = Path(f"build_all/{variant}") + resdir.mkdir(parents=True, exist_ok=True) + try: + # Update previous results + with open(resdir / f"{library}.json", "r") as handle: + prev_results = json.load(handle) + # NOTE this is not ideal as the JSON decoding problem can be other than just an empty file + except (FileNotFoundError, json.JSONDecodeError): + prev_results = {} + + prev_results[version] = result + with open(resdir / f"{library}.json", "w") as handle: + json.dump(prev_results, handle, indent=4) + def main(): parser = argparse.ArgumentParser() parser.add_argument("-l", "--library") - parser.add_argument("-d", "--variant", default="shim", type=valid_build_type) + parser.add_argument("-v", "--variant", default="shim", type=valid_build_type) args = parser.parse_args() library = args.library variant = args.variant - libraries = [ "botan", "cryptopp", @@ -53,14 +78,22 @@ def main(): match library: case None: + print("Building all libraries") + # Build all libraries by default for lib in libraries: print(f"Library: {lib}") for version in get_all_versions(lib): - print(f"{version}: {can_build(lib, version, variant)}") - case _: + result = attempt_build(lib, version, variant) + save_build_result(lib, variant, version, result) + print(f"{version}: {result['success']}") + case lib if lib in libraries: print(f"Library: {library}") for version in get_all_versions(library): - print(f"{version}: {can_build(library, version, variant)}") + result = attempt_build(lib, version, variant) + save_build_result(lib, variant, version, result) + print(f"{version}: {result['success']}") + case _: + print(f"Unrecognized library '{library}'. Try one of: {', '.join(libraries)}.") if __name__ == '__main__': |
