| # Copyright 2021 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. |
| |
| """determinism_check.py - Runs two builds with the same checkout and compares |
| their output to validate the build produces |
| deterministic blobs. |
| """ |
| |
| from PB.recipes.fuchsia.fuchsia.determinism_check import InputProperties |
| |
| DEPS = [ |
| "fuchsia/build", |
| "fuchsia/buildbucket_util", |
| "fuchsia/checkout", |
| "recipe_engine/file", |
| "recipe_engine/path", |
| "recipe_engine/properties", |
| "recipe_engine/step", |
| ] |
| |
| PROPERTIES = InputProperties |
| |
| # From the Fuchsia source tree |
| _COMPARE_SCRIPT = "build/scripts/compare-build-dirs.sh" |
| |
| |
| def RunSteps(api, props): |
| checkout = api.checkout.fuchsia_with_options( |
| manifest=props.manifest, |
| remote=props.remote, |
| ) |
| |
| # Build twice to the same output dir, and move it to a |
| # backup location each time. |
| with api.step.nest("build 1"): |
| saved_build_dir_1 = run_build(api, checkout, props) |
| |
| with api.step.nest("build 2"): |
| saved_build_dir_2 = run_build(api, checkout, props) |
| |
| compare_script = api.path.join(checkout.root_dir, _COMPARE_SCRIPT) |
| api.step( |
| "compare built artifacts", |
| [compare_script, saved_build_dir_1, saved_build_dir_2], |
| ) |
| |
| |
| def run_build(api, checkout, props): |
| """Performs a single build of fuchsia. |
| |
| Returns: |
| A backup location of the build output dir. |
| """ |
| build_results = api.build.with_options( |
| checkout, fint_params_path=props.fint_params_path |
| ) |
| |
| # Save it to a backup location, so we can rebuild over the original |
| # location. |
| new_build_dir = api.path.mkdtemp() |
| api.file.move( |
| f"move outdir to {new_build_dir}", build_results.build_dir, new_build_dir |
| ) |
| return new_build_dir |
| |
| |
| def GenTests(api): |
| properties = { |
| "manifest": "minimal", |
| "project": "integration", |
| "remote": "https://fuchsia.googlesource.com/manifest", |
| "fint_params_path": "fint_params/core.textproto", |
| } |
| |
| # Test case for deterministic builds. |
| yield ( |
| api.buildbucket_util.test("deterministic_build", tryjob=False) |
| + api.properties(**properties) |
| ) |
| |
| # Test case where builds contain differences. |
| yield ( |
| api.buildbucket_util.test("differences_found", tryjob=False, status="FAILURE") |
| + api.step_data( |
| "compare built artifacts", |
| retcode=1, |
| ) |
| + api.properties(**properties) |
| ) |