| #!/usr/bin/env python3 |
| |
| # Copyright 2020 The Fuchsia Authors. All rights reserved. |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| |
| """Outputs a `led edit` command to re-use a good subbuild. |
| |
| Useful for testing recipe changes that only touch the testing part. |
| Example of suggested usage: |
| |
| export BUILDER="fuchsia/try:core.x64-asan" |
| led get-builder -real-build ${BUILDER} | led edit-recipe-bundle | /bin/bash -c $(scripts/led_edit_to_reuse_subbuild.py ${BUILDER}) | led launch |
| """ |
| |
| import json |
| import sys |
| import subprocess |
| |
| |
| def main(argv): |
| if len(argv) != 1: |
| sys.exit("Need exactly 1 argument: <project>/<bucket>:<builder>") |
| led_format_builder = argv[0] |
| project, rest = led_format_builder.split("/") |
| bucket, builder = rest.split(":") |
| subbuilder = builder |
| if not builder.endswith("-subbuild"): |
| subbuilder += "-subbuild" |
| output = subprocess.check_output( |
| ( |
| "bb", |
| "ls", |
| f"{project}/{bucket}/{subbuilder}", |
| "-n", |
| "20", |
| "-status", |
| "success", |
| "-json", |
| "-fields", |
| "output.properties", |
| ) |
| ) |
| output_lines = output.strip().split(b"\n") |
| build_id = None |
| use_cas = False |
| for ol in output_lines: |
| try: |
| build_dict = json.loads(ol) |
| except json.decoder.JSONDecodeError: |
| continue |
| output_properties = build_dict["output"]["properties"] |
| if output_properties.get("test_orchestration_inputs_hash"): |
| build_id = build_dict["id"] |
| break |
| elif output_properties.get("test_orchestration_inputs_digest"): |
| use_cas = True |
| build_id = build_dict["id"] |
| break |
| if not build_id: |
| sys.exit( |
| f"Unable to find a recent build of {subbuilder} with property " |
| "test_orchestration_inputs_hash or test_orchestration_inputs_digest" |
| ) |
| led_edit_cmd = f'led edit -p child_build_id=\\"{build_id}\\"' |
| if use_cas: |
| led_edit_cmd += " -p experimental.rbe_cas=true" |
| print(led_edit_cmd) |
| |
| |
| if __name__ == "__main__": |
| main(sys.argv[1:]) |