blob: 320a9a1aaa9f00489a01895cd4e39dee6fe49b3d [file] [log] [blame]
# 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.recipe_api import Property
DEPS = [
"fuchsia/build",
"fuchsia/checkout",
"fuchsia/git",
"recipe_engine/buildbucket",
"recipe_engine/context",
"recipe_engine/path",
"recipe_engine/properties",
"recipe_engine/raw_io",
"recipe_engine/step",
]
PROPERTIES = {
"manifest": Property(kind=str, help="Jiri manifest to use. Should include //topaz"),
"remote": Property(kind=str, help="Remote manifest repository"),
}
def RunSteps(api, remote, manifest):
checkout_root = api.path["start_dir"].join("fuchsia")
checkout = api.checkout.fuchsia_with_options(
path=checkout_root,
build=api.buildbucket.build,
manifest=manifest,
remote=remote,
)
fuchsia_build_dir = checkout.root_dir.join("out", "default")
# Check docs.
with api.step.nest("build"):
gn_results = api.build.gen(
checkout=checkout,
fuchsia_build_dir=fuchsia_build_dir,
# Target doesn't matter since it's a host-side target
target="x64",
build_type="debug",
packages=["//tools/doc_checker", "//tools/check-licenses:host"],
# Product doesn't matter; bringup.gni is faster that core.gni
product="products/bringup.gni",
)
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, fuchsia_build_dir),
api.path.relpath(doc_checker_path, fuchsia_build_dir),
],
# Skip building zircon since it is unnecessary
build_zircon=False,
)
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=["BUILD.gn", "foo.cc"],
deleted=False,
)
else:
step_result = api.git.ls_files(
step_name="get gn files",
file="*.gn*",
test_data="BUILD.gn\nfoo.cc\n",
)
files = step_result.stdout.strip("\n").split("\n")
files = [f for f in files if f.endswith((".gn", ".gni"))]
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):
yield (
api.test("default_ci")
+ api.buildbucket.ci_build(git_repo="https://fuchsia.googlesource.com/fuchsia")
+ api.properties(
manifest="fuchsia", remote="https://fuchsia.googlesource.com/manifest",
)
)
yield (
api.test("default_cq")
+ api.buildbucket.try_build(git_repo="https://fuchsia.googlesource.com/fuchsia")
+ api.properties(
manifest="fuchsia", remote="https://fuchsia.googlesource.com/manifest",
)
)