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 module for compiling Skia when we need to get a full Skia checkout. 7 8PYTHON_VERSION_COMPATIBILITY = "PY3" 9 10DEPS = [ 11 'build', 12 'checkout', 13 'infra', 14 'recipe_engine/context', 15 'recipe_engine/file', 16 'recipe_engine/json', 17 'recipe_engine/path', 18 'recipe_engine/platform', 19 'recipe_engine/properties', 20 'recipe_engine/step', 21 'depot_tools/gitiles', 22 'run', 23 'vars', 24] 25 26 27def RunSteps(api): 28 api.vars.setup() 29 30 # Check out code. 31 bot_update = True 32 checkout_root = api.checkout.default_checkout_root 33 skip_patch = False 34 revision = api.properties['revision'] 35 36 if 'NoDEPS' in api.properties['buildername']: 37 bot_update = False 38 checkout_root = api.path.start_dir 39 if 'NoPatch' in api.vars.builder_name: 40 skip_patch = True 41 checkout_root = api.path.start_dir 42 43 # If we are running on the CI (post submit), we want to do a diff with the 44 # previous commit. To do this, we use gitiles to look up the current 45 # git revision, and find its parent. In the unlikely event of there being 46 # multiple parents, we pick the first one arbitrarily. 47 if not api.vars.is_trybot: 48 # Fetches something like 49 # https://skia.googlesource.com/skia.git/+log/b44572fbfeb669998053b023f473b9c274f2f2cf?format=JSON 50 # 51 # https://chromium.googlesource.com/chromium/tools/depot_tools/+/dca14bc463857bd2a0fee59c86ffa289b535d5d3/recipes/recipe_modules/gitiles/api.py#75 52 response, _ = api.gitiles.log( 53 url = api.properties['repository'], 54 ref = api.properties['revision'], 55 limit = 1) 56 # Response looks like: 57 # [{ 58 # 'parents': ['<githash>'], 59 # ... 60 # }] 61 revision = response[0]['parents'][0] 62 63 if bot_update: 64 api.checkout.bot_update( 65 checkout_root=checkout_root, 66 skip_patch=skip_patch, 67 override_revision=revision) 68 69 if 'NoPatch' in api.vars.builder_name: 70 # The CodeSize-* family of tasks compute size diffs between the binaries produced by 71 # Build-<CONFIG>-NoPatch tasks and those produced by Build-<CONFIG> tasks. Some debug strings 72 # in said binaries might contain relative paths from the output directory to the sources 73 # directory (e.g. "../../../dm/DM.cpp"). In order to prevent spurious deltas, we must make 74 # the Build-<CONFIG>-NoPatch tasks match the paths used by Build-<CONFIG> tasks. For example, 75 # Build-<CONFIG> tasks place the Skia checkout at /mnt/pd0/s/w/ir/skia, so 76 # Build-<CONFIG>-NoPatch tasks must do the same. 77 # 78 # For some reason api.checkout.bot_update places the Skia checkout at /mnt/pd0/s/w/ir/k 79 # even though we specified /mnt/pd0/s/w/ir as the checkout root. As a workaround, we manually 80 # copy the Skia checkout to the intended location. 81 # 82 # An inline Python script is necessary here because api.file.copytree[1] does not pipe 83 # through the dirs_exist_ok argument to the underlying shutil.copytree[2] call. 84 # 85 # [1] https://chromium.googlesource.com/infra/luci/recipes-py.git/+/cfdb92cc6933d8f72c2340233ba03b602b447507/recipe_modules/file/api.py#146 86 # [2] https://docs.python.org/3/library/shutil.html#shutil.copytree 87 src = api.path.start_dir.joinpath('k', 'skia') 88 dst = api.path.start_dir.joinpath('skia') 89 script = api.infra.resource('copytree.py') 90 api.step( 91 name='copy Skia repository checkout from %s to %s' % (src, dst), 92 cmd=['python3', script, src, dst]) 93 api.file.rmtree('remove %s' % src, src) 94 95 else: 96 api.checkout.git(checkout_root=checkout_root) 97 98 api.file.ensure_directory('makedirs tmp_dir', api.vars.tmp_dir) 99 100 out_dir = checkout_root.joinpath( 101 'skia', 'out', api.vars.builder_name, api.vars.configuration) 102 if 'NoPatch' in api.vars.builder_name: 103 # Similarly as with the checkout root, we use the same output directory in 104 # Build-<CONFIG>-NoPatch tasks as we do on Build-<CONFIG> tasks to prevent spurious deltas. 105 out_dir = api.vars.cache_dir.joinpath( 106 'work', 'skia', 'out', api.vars.builder_name, api.vars.configuration) 107 108 try: 109 api.build(checkout_root=checkout_root, out_dir=out_dir) 110 111 # TODO(borenet): Move this out of the try/finally. 112 dst = api.vars.swarming_out_dir 113 api.build.copy_build_products(out_dir=out_dir, dst=dst) 114 finally: 115 if 'Win' in api.vars.builder_cfg.get('os', ''): 116 script = api.build.resource('cleanup_win_processes.py') 117 api.step( 118 name='cleanup', 119 cmd=['vpython3', script], 120 infra_step=True) 121 122 api.run.check_failure() 123 124 125def GenTests(api): 126 yield ( 127 api.test('Build-Win10-Clang-x86_64-Release-NoDEPS') + 128 api.properties(buildername='Build-Win10-Clang-x86_64-Release-NoDEPS', 129 repository='https://skia.googlesource.com/skia.git', 130 revision='abc123', 131 path_config='kitchen', 132 swarm_out_dir='[SWARM_OUT_DIR]') + 133 api.platform('win', 64) 134 ) 135 136 yield ( 137 # git revisions based off of real data 138 api.test('Build-Debian10-Clang-arm-Release-NoPatch') + 139 api.properties(buildername='Build-Debian10-Clang-arm-Release-NoPatch', 140 repository='https://skia.googlesource.com/skia.git', 141 revision='b44572fbfeb669998053b023f473b9c274f2f2cf', 142 path_config='kitchen', 143 swarm_out_dir='[SWARM_OUT_DIR]') + 144 # This tells recipes to use this fake data for a step with the given 145 # name. Inspired by 146 # https://chromium.googlesource.com/chromium/tools/depot_tools/+/dca14bc463857bd2a0fee59c86ffa289b535d5d3/recipes/recipe_modules/gitiles/examples/full.py#62 147 # Even though we use the commit 6e0e0... as the "seed string", the actual 148 # commit (and parent commit) returned from make_log_test_data is 149 # different. Mocked commit is 188e23c7abc4b205f0f80fb345ff63ec5b716be8 150 # and parent commit is d2231a340fd47b47d61d0f99a188e46e6aabba0a 151 api.step_data( 152 'gitiles log: b44572fbfeb669998053b023f473b9c274f2f2cf', 153 api.gitiles.make_log_test_data('6e0e0a9f6cbf09078aa4730d1a0dc0aa722ddc11'), 154 ) 155 ) 156 157 yield ( 158 api.test('Build-Debian10-Clang-arm-Release-NoPatch (tryjob)') + 159 api.properties(buildername='Build-Debian10-Clang-arm-Release-NoPatch', 160 repository='https://skia.googlesource.com/skia.git', 161 revision='abc123', 162 path_config='kitchen', 163 swarm_out_dir='[SWARM_OUT_DIR]', 164 patch_issue=123, 165 patch_set=123, 166 patch_ref=123) 167 ) 168