OLD | NEW |
(Empty) | |
| 1 # Copyright 2016 The Chromium 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 |
| 6 # Recipe wrapper used in SwarmBucket. |
| 7 |
| 8 |
| 9 DEPS = [ |
| 10 'build/file', |
| 11 'depot_tools/bot_update', |
| 12 'depot_tools/gclient', |
| 13 'recipe_engine/json', |
| 14 'recipe_engine/path', |
| 15 'recipe_engine/properties', |
| 16 'recipe_engine/python', |
| 17 'recipe_engine/step', |
| 18 ] |
| 19 |
| 20 |
| 21 def checkout_steps(api): |
| 22 """Run the steps to obtain a checkout of Skia.""" |
| 23 # Find the workdir and cache dir. |
| 24 workdir = api.path['b'].join('work') |
| 25 if not api.path.exists(workdir): |
| 26 api.file.makedirs('workdir', workdir, infra_step=True) |
| 27 cache_dir = api.path['b'].join('cache') |
| 28 |
| 29 # Set up gclient config. |
| 30 api.gclient.use_mirror = True |
| 31 gclient_cfg = api.gclient.make_config(GIT_MODE=True, CACHE_DIR=cache_dir) |
| 32 soln = gclient_cfg.solutions.add() |
| 33 soln.name = 'skia' |
| 34 soln.url = 'https://skia.googlesource.com/skia.git' |
| 35 soln.revision = api.properties.get('revision', 'origin/master') |
| 36 api.gclient.c = gclient_cfg |
| 37 api.gclient.c.got_revision_mapping['skia'] = 'got_revision' |
| 38 |
| 39 # Set up options for bot_update based on properties. In general, these will |
| 40 # all take the default value. |
| 41 patch = api.properties.get('patch', True) |
| 42 clobber = True if api.properties.get('clobber') else False |
| 43 force = True if api.properties.get('force') else False |
| 44 no_shallow = True if api.properties.get('no_shallow') else False |
| 45 output_manifest = api.properties.get('output_manifest', False) |
| 46 with_branch_heads = api.properties.get('with_branch_heads', False) |
| 47 refs = api.properties.get('refs', []) |
| 48 oauth2 = api.properties.get('oauth2', False) |
| 49 root_solution_revision = api.properties.get('root_solution_revision') |
| 50 suffix = api.properties.get('suffix') |
| 51 gerrit_no_reset = True if api.properties.get('gerrit_no_reset') else False |
| 52 |
| 53 # Run bot_update to sync the code and apply a patch if necessary. |
| 54 api.bot_update.ensure_checkout(force=force, |
| 55 no_shallow=no_shallow, |
| 56 patch=patch, |
| 57 with_branch_heads=with_branch_heads, |
| 58 output_manifest=output_manifest, |
| 59 refs=refs, patch_oauth2=oauth2, |
| 60 clobber=clobber, |
| 61 root_solution_revision=root_solution_revision, |
| 62 suffix=suffix, |
| 63 gerrit_no_reset=gerrit_no_reset, |
| 64 cwd=workdir) |
| 65 |
| 66 # Ensure that we ended up with the desired revision. |
| 67 got_revision = api.step.active_result.presentation.properties['got_revision'] |
| 68 if soln.revision != 'origin/master': # pragma: no cover |
| 69 assert got_revision == soln.revision |
| 70 return got_revision |
| 71 |
| 72 |
| 73 def forward_to_recipe_in_repo(api): |
| 74 workdir = api.path['b'].join('work') |
| 75 recipes_py = workdir.join('skia', 'infra', 'bots', 'recipes.py') |
| 76 cmd = ['python', recipes_py, 'run', |
| 77 '--workdir', workdir, |
| 78 'swarm_trigger', 'path_config=kitchen'] |
| 79 for k, v in api.properties.iteritems(): |
| 80 cmd.append('%s=%s' % (k, v)) |
| 81 api.step('run recipe', cmd=cmd, allow_subannotations=True) |
| 82 |
| 83 |
| 84 def print_properties(api): |
| 85 """Dump out all properties for debugging purposes.""" |
| 86 props = {} |
| 87 for k, v in api.properties.iteritems(): |
| 88 props[k] = v |
| 89 api.python.inline( |
| 90 'print properties', |
| 91 ''' |
| 92 import json |
| 93 import sys |
| 94 |
| 95 with open(sys.argv[1]) as f: |
| 96 content = json.load(f) |
| 97 |
| 98 print json.dumps(content, indent=2) |
| 99 ''', |
| 100 args=[api.json.input(props)]) |
| 101 |
| 102 |
| 103 def RunSteps(api): |
| 104 api.path.c.base_paths['b'] = ('/', 'b') |
| 105 |
| 106 # TODO(borenet): Remove this once SwarmBucket is working. |
| 107 print_properties(api) |
| 108 |
| 109 checkout_steps(api) |
| 110 forward_to_recipe_in_repo(api) |
| 111 |
| 112 |
| 113 def GenTests(api): |
| 114 yield ( |
| 115 api.test('trigger_recipe') + |
| 116 api.properties(buildername='Some-Builder', |
| 117 buildnumber=5, |
| 118 mastername='client.skia.fyi', |
| 119 slavename='some-slave', |
| 120 path_config='swarmbucket') |
| 121 ) |
OLD | NEW |