| # 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. |
| """Recipe for extracting and uploading a kzip for Fuchsia.""" |
| |
| from recipe_engine.config import Enum |
| from recipe_engine.post_process import DoesNotRun |
| from recipe_engine.recipe_api import Property |
| |
| TARGETS = ("arm64", "x64") |
| |
| BUILD_TYPES = ("debug", "release", "thinlto", "lto") |
| |
| DEPS = [ |
| "fuchsia/build", |
| "fuchsia/checkout", |
| "fuchsia/jiri", |
| "fuchsia/kythe", |
| "fuchsia/status_check", |
| "recipe_engine/buildbucket", |
| "recipe_engine/context", |
| "recipe_engine/path", |
| "recipe_engine/properties", |
| "recipe_engine/step", |
| "recipe_engine/time", |
| ] |
| |
| PROPERTIES = { |
| "target": Property( |
| kind=Enum(*TARGETS), |
| help="Targets from which to generate a kzip", |
| default="x64", |
| ), |
| "build_type": Property( |
| kind=Enum(*BUILD_TYPES), help="The build type", default="debug" |
| ), |
| "product": Property(kind=str, help="Product to build", default="products/core.gni"), |
| "board": Property(kind=str, help="Board to build", default="boards/x64.gni"), |
| "gcs_bucket": Property( |
| kind=str, |
| help="GCS bucket for uploading extracted kzip for kythe indexing", |
| default="fuchsia-kythe", |
| ), |
| "dry_run": Property( |
| kind=bool, default=False, help="Whether to skip the final upload step", |
| ), |
| } |
| |
| KYTHE_CORPUS = "fuchsia.googlesource.com/fuchsia" |
| |
| |
| def RunSteps(api, target, build_type, product, board, gcs_bucket, dry_run): |
| # Get a clean checkout of fuchsia.git |
| fuchsia_dir = api.path["start_dir"].join("fuchsia") |
| checkout = api.checkout.fuchsia_with_options( |
| path=fuchsia_dir, |
| build=api.buildbucket.build, |
| manifest="flower", |
| remote="https://fuchsia.googlesource.com/integration", |
| ) |
| |
| # Build so we have all the generated files. |
| build_results = api.build.with_options( |
| checkout=checkout, |
| target=target, |
| build_type=build_type, |
| packages=["//bundles:kitchen_sink"], |
| product=product, |
| board=board, |
| gn_args=["is_analysis=true"], |
| ) |
| fuchsia_build_dir = build_results.fuchsia_build_dir |
| |
| # Run `gn gen --export-compile-commands` and merge the compdbs |
| with api.step.nest("generate compdb"): |
| gn_results = api.build.gen( |
| checkout=checkout, |
| fuchsia_build_dir=fuchsia_build_dir, |
| target=target, |
| build_type=build_type, |
| product=product, |
| board=board, |
| export_compdb=True, |
| ) |
| merged_compdb_path = gn_results.filtered_compdb([]) |
| |
| with api.context(cwd=fuchsia_dir): |
| revision = api.jiri.project(["fuchsia"]).json.output[0]["revision"] |
| commit_timestamp = int(api.time.time()) |
| kzip_name_with_revision = "fuchsia_%s_%s+%d.kzip" % ( |
| target, |
| revision, |
| commit_timestamp, |
| ) |
| |
| if dry_run: |
| final_path = "testing/%s" % kzip_name_with_revision |
| else: |
| final_path = "prod/%s" % kzip_name_with_revision |
| |
| api.kythe.extract_and_upload( |
| checkout_dir=fuchsia_dir, |
| build_dir=fuchsia_build_dir, |
| compdb_path=merged_compdb_path, |
| corpus=KYTHE_CORPUS, |
| gcs_bucket=gcs_bucket, |
| gcs_filename=final_path, |
| langs=("cxx", "rust"), |
| ) |
| |
| |
| def GenTests(api): |
| yield api.status_check.test("basic") |
| yield api.status_check.test("dry_run") + api.properties(dry_run=True) |