github.com/btwiuse/jiri@v0.0.0-20191125065820-53353bcfef54/infra/recipes/jiri.py (about)

     1  # Copyright 2016 The Fuchsia Authors. All rights reserved.
     2  # Use of this source code is governed by a BSD-style license that can be
     3  # found in the LICENSE file.
     4  
     5  """Recipe for building Jiri."""
     6  
     7  from recipe_engine.recipe_api import Property
     8  from recipe_engine import config
     9  
    10  
    11  DEPS = [
    12      'infra/jiri',
    13      'infra/git',
    14      'infra/go',
    15      'recipe_engine/path',
    16      'recipe_engine/properties',
    17      'recipe_engine/raw_io',
    18      'recipe_engine/step',
    19  ]
    20  
    21  PROPERTIES = {
    22      'category': Property(kind=str, help='Build category', default=None),
    23      'patch_gerrit_url': Property(kind=str, help='Gerrit host', default=None),
    24      'patch_project': Property(kind=str, help='Gerrit project', default=None),
    25      'patch_ref': Property(kind=str, help='Gerrit patch ref', default=None),
    26      'patch_storage': Property(kind=str, help='Patch location', default=None),
    27      'patch_repository_url': Property(kind=str, help='URL to a Git repository',
    28                                default=None),
    29      'manifest': Property(kind=str, help='Jiri manifest to use'),
    30      'remote': Property(kind=str, help='Remote manifest repository'),
    31      'target': Property(kind=str, help='Target to build'),
    32  }
    33  
    34  
    35  def RunSteps(api, category, patch_gerrit_url, patch_project, patch_ref,
    36               patch_storage, patch_repository_url, manifest, remote, target):
    37      api.jiri.ensure_jiri()
    38  
    39      api.jiri.init()
    40      api.jiri.clean_project()
    41      api.jiri.import_manifest(manifest, remote)
    42      api.jiri.update(gc=True)
    43      if patch_ref is not None:
    44          api.jiri.patch(patch_ref, host=patch_gerrit_url)
    45  
    46      api.go.ensure_go()
    47  
    48      gitdir = api.path['start_dir'].join(
    49          'go', 'src', 'fuchsia.googlesource.com', 'jiri')
    50      git_commit = api.git.get_hash(cwd=gitdir)
    51      result = api.step('date', ['date', '--rfc-3339=seconds'],
    52          stdout=api.raw_io.output(),
    53          step_test_data=lambda:
    54              api.raw_io.test_api.stream_output('2016-10-11 14:40:25-07:00'))
    55      build_time = result.stdout.strip()
    56  
    57      ldflags = "-X \"fuchsia.googlesource.com/jiri/version.GitCommit=%s\" -X \"fuchsia.googlesource.com/jiri/version.BuildTime=%s\"" % (git_commit, build_time)
    58      gopath = api.path['start_dir'].join('go')
    59      goos, goarch = target.split("-", 2)
    60  
    61      with api.step.context({'env': {'GOPATH': gopath, 'GOOS': goos, 'GOARCH': goarch}}):
    62          api.go('build', '-ldflags', ldflags, '-a',
    63                 'fuchsia.googlesource.com/jiri/cmd/jiri')
    64  
    65      with api.step.context({'env': {'GOPATH': gopath}}):
    66          api.go('test', 'fuchsia.googlesource.com/jiri/cmd/jiri')
    67  
    68  
    69  def GenTests(api):
    70      yield api.test('ci') + api.properties(
    71          manifest='jiri',
    72          remote='https://fuchsia.googlesource.com/manifest',
    73          target='linux-amd64',
    74      )
    75      yield api.test('cq_try') + api.properties.tryserver(
    76          gerrit_project='jiri',
    77          patch_gerrit_url='fuchsia-review.googlesource.com',
    78          manifest='jiri',
    79          remote='https://fuchsia.googlesource.com/manifest',
    80          target='linux-amd64',
    81      )