| # Copyright 2018 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. |
| |
| """Recipe for checks that require a checkout but not a full build.""" |
| |
| from recipe_engine.config import List |
| from recipe_engine.recipe_api import Property |
| |
| DEPS = [ |
| "fuchsia/build", |
| "fuchsia/checkout", |
| "fuchsia/git", |
| "fuchsia/status_check", |
| "recipe_engine/buildbucket", |
| "recipe_engine/context", |
| "recipe_engine/path", |
| "recipe_engine/properties", |
| "recipe_engine/step", |
| ] |
| |
| PROPERTIES = { |
| "manifest": Property(kind=str, help="Jiri manifest to use. Should include //topaz"), |
| "remote": Property(kind=str, help="Remote manifest repository"), |
| "fint_params_path": Property(kind=str, help="Spec path to pass to fint"), |
| } |
| |
| |
| def RunSteps(api, remote, manifest, fint_params_path): |
| checkout_root = api.path["start_dir"].join("fuchsia") |
| checkout = api.checkout.fuchsia_with_options( |
| path=checkout_root, manifest=manifest, remote=remote, |
| ) |
| |
| # Check docs. |
| with api.step.nest("build"): |
| gn_results = api.build.gen( |
| checkout=checkout, fint_params_path=fint_params_path, |
| ) |
| check_licenses_path = gn_results.tool("check-licenses") |
| doc_checker_path = gn_results.tool("doc-checker") |
| |
| api.build.ninja( |
| gn_results=gn_results, |
| targets=[ |
| api.path.relpath(check_licenses_path, gn_results.build_dir), |
| api.path.relpath(doc_checker_path, gn_results.build_dir), |
| ], |
| ) |
| |
| with api.context(cwd=checkout.root_dir): |
| api.step("doc_check", [doc_checker_path, "--local-links-only"]) |
| |
| # Check gn formatting. Doesn't attempt to suggest fixes, the tricium recipe |
| # does that. |
| with api.step.nest("gn format"): |
| # On try jobs, only check the modified files. On CI, check them all. |
| if ( |
| api.buildbucket.build.input |
| and api.buildbucket.build.input.gerrit_changes |
| ): |
| files = checkout.changed_files( |
| api.buildbucket.build.input, |
| test_data=["bar/BUILD.gn", "foo.cc", "third_party/foo/BUILD.gn",], |
| deleted=False, |
| ) |
| else: |
| step_result = api.git.ls_files( |
| step_name="get gn files", |
| file="*.gn*", |
| test_data="bar/BUILD.gn\nfoo.cc\nthird_party/foo/BUILD.gn", |
| ) |
| files = step_result.stdout.strip("\n").split("\n") |
| files = [ |
| f |
| for f in files |
| if f.endswith((".gn", ".gni")) and "third_party" not in f |
| ] |
| if files: |
| api.step( |
| "gn format --dry-run", |
| [gn_results.tool("gn"), "format", "--dry-run"] + files, |
| ) |
| api.step( |
| "check-licenses", [check_licenses_path, "-output_license_file=false"], |
| ) |
| |
| |
| def GenTests(api): |
| def props(): |
| return api.properties( |
| manifest="fuchsia", |
| remote="https://fuchsia.googlesource.com/manifest", |
| fint_params_path="specs/static-checks.textproto", |
| ) |
| |
| yield ( |
| api.status_check.test("default_ci") |
| + api.buildbucket.ci_build(git_repo="https://fuchsia.googlesource.com/fuchsia") |
| + props() |
| ) |
| yield ( |
| api.status_check.test("default_cq") |
| + api.buildbucket.try_build(git_repo="https://fuchsia.googlesource.com/fuchsia") |
| + props() |
| ) |