| # Copyright 2016 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 building Jiri.""" |
| |
| from PB.recipes.fuchsia.jiri import InputProperties |
| |
| DEPS = [ |
| "fuchsia/buildbucket_util", |
| "fuchsia/checkout", |
| "fuchsia/cipd_util", |
| "fuchsia/go", |
| "fuchsia/gsutil", |
| "fuchsia/jiri", |
| "fuchsia/status_check", |
| "recipe_engine/buildbucket", |
| "recipe_engine/context", |
| "recipe_engine/path", |
| "recipe_engine/properties", |
| "recipe_engine/step", |
| "recipe_engine/time", |
| ] |
| |
| PROPERTIES = InputProperties |
| |
| # The current list of platforms that we build for. |
| GO_OS_ARCH = ( |
| ("linux", "amd64"), |
| ("linux", "arm64"), |
| ("darwin", "amd64"), |
| ("darwin", "arm64"), |
| ) |
| |
| |
| def RunSteps(api, props): |
| checkout_dir = api.checkout.with_options( |
| manifest=props.manifest, |
| remote=props.remote, |
| project=props.project, |
| ) |
| revision = api.checkout.project(props.project, checkout_root=checkout_dir)[ |
| "revision" |
| ] |
| |
| staging_dir = api.path.mkdtemp("jiri") |
| |
| with api.context( |
| cwd=checkout_dir.join("go/src/fuchsia.googlesource.com/jiri"), |
| env_prefixes={"PATH": [api.go.go_root.join("bin")]}, |
| ): |
| # Run all the tests. |
| api.go("build", "./...") |
| api.go("test", "-v", "./...") |
| api.go("test", "-v", "-race", "./...") |
| |
| for goos, goarch in GO_OS_ARCH: |
| with api.context(env={"GOOS": goos, "GOARCH": goarch}): |
| platform = "%s-%s" % (goos.replace("darwin", "mac"), goarch) |
| |
| with api.step.nest(platform): |
| args = [ |
| "build", |
| "-o", |
| staging_dir.join("jiri"), |
| ] |
| |
| if not api.buildbucket_util.is_tryjob: |
| build_time = api.time.utcnow().isoformat() |
| ldflags = " ".join( |
| [ |
| '-X "go.fuchsia.dev/jiri/version.GitCommit=%s"' |
| % revision, |
| '-X "go.fuchsia.dev/jiri/version.BuildTime=%s"' |
| % build_time, |
| ] |
| ) |
| args.extend(["-ldflags", ldflags]) |
| |
| args.append("./cmd/jiri") |
| |
| # Build the package. |
| api.go(*args) |
| |
| api.cipd_util.upload_package( |
| "fuchsia/tools/jiri/%s" % platform, |
| staging_dir, |
| pkg_paths=[staging_dir.join("jiri")], |
| search_tag={"git_revision": revision}, |
| repository=props.remote, |
| ) |
| |
| if not api.buildbucket_util.is_tryjob: |
| api.gsutil.upload( |
| "fuchsia-build", |
| staging_dir.join("jiri"), |
| api.gsutil.join("jiri", "%s-%s" % (goos, goarch), revision), |
| unauthenticated_url=True, |
| ok_ret=(0, 1), |
| ) |
| |
| |
| def GenTests(api): |
| yield ( |
| api.status_check.test("ci") |
| + api.buildbucket.ci_build( |
| git_repo="https://fuchsia.googlesource.com/jiri", |
| revision=api.jiri.example_revision, |
| ) |
| + api.properties( |
| project="jiri", |
| manifest="jiri", |
| remote="https://fuchsia.googlesource.com/manifest", |
| ) |
| ) |
| yield ( |
| api.status_check.test("cq") |
| + api.buildbucket.try_build(git_repo="https://fuchsia.googlesource.com/jiri") |
| + api.properties( |
| project="jiri", |
| manifest="jiri", |
| remote="https://fuchsia.googlesource.com/manifest", |
| ) |
| ) |