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# pylint: disable=W0201 7 8 9from recipe_engine import recipe_api 10 11 12CONFIG_DEBUG = 'Debug' 13CONFIG_RELEASE = 'Release' 14 15 16class SkiaVarsApi(recipe_api.RecipeApi): 17 18 def make_path(self, *path): 19 """Return a Path object for the given path.""" 20 key = 'custom_%s' % '_'.join(path) 21 self.m.path.c.base_paths[key] = tuple(path) 22 return self.m.path[key] 23 24 def setup(self): 25 """Prepare the variables.""" 26 # Setup 27 self.builder_name = self.m.properties['buildername'] 28 29 self.slave_dir = self.m.path['start_dir'] 30 self.checkout_root = self.slave_dir 31 self.default_env = self.m.context.env 32 self.default_env['CHROME_HEADLESS'] = '1' 33 self.default_env['PATH'] = self.m.path.pathsep.join([ 34 self.default_env.get('PATH', '%(PATH)s'), 35 str(self.m.bot_update._module.PACKAGE_REPO_ROOT), 36 ]) 37 self.gclient_env = {} 38 self.is_compile_bot = self.builder_name.startswith('Build-') 39 40 # Compile bots keep a persistent checkout. 41 self.persistent_checkout = (self.is_compile_bot or 42 'RecreateSKPs' in self.builder_name or 43 'UpdateMetaConfig' in self.builder_name or 44 '-CT_' in self.builder_name or 45 'Presubmit' in self.builder_name or 46 'InfraTests' in self.builder_name or 47 self.builder_name == "Housekeeper-PerCommit") 48 if self.persistent_checkout: 49 if 'Win' in self.builder_name: 50 self.checkout_root = self.make_path('C:\\', 'b', 'work') 51 self.gclient_cache = self.make_path('C:\\', 'b', 'cache') 52 else: 53 self.checkout_root = self.make_path('/', 'b', 'work') 54 self.gclient_cache = self.make_path('/', 'b', 'cache') 55 56 # got_revision is filled in after checkout steps. 57 self.got_revision = None 58 else: 59 # If there's no persistent checkout, then we have to asume we got the 60 # correct revision of the files from isolate. 61 self.got_revision = self.m.properties['revision'] 62 63 # Some bots also require a checkout of PDFium; in this case we use the 64 # checkout of Skia obtained through DEPS in pdfium/third_party/skia. 65 self.need_pdfium_checkout = 'PDFium' in self.builder_name 66 67 # Some bots also require a checkout of Flutter; in this case we use the 68 # checkout of Skia obtained through DEPS in src/third_party/skia. 69 self.need_flutter_checkout = 'Flutter' in self.builder_name 70 71 self.skia_dir = self.checkout_root.join('skia') 72 if self.need_pdfium_checkout: 73 self.skia_dir = self.checkout_root.join('pdfium', 'third_party', 'skia') 74 elif self.need_flutter_checkout: 75 self.checkout_root = self.checkout_root.join('flutter') 76 self.skia_dir = self.checkout_root.join('src', 'third_party', 'skia') 77 78 if not self.persistent_checkout: 79 self.m.path['checkout'] = self.skia_dir 80 81 self.infrabots_dir = self.skia_dir.join('infra', 'bots') 82 self.resource_dir = self.skia_dir.join('resources') 83 self.images_dir = self.slave_dir.join('skimage') 84 self.skia_out = self.skia_dir.join('out', self.builder_name) 85 self.swarming_out_dir = self.make_path(self.m.properties['swarm_out_dir']) 86 self.local_skp_dir = self.slave_dir.join('skp') 87 self.local_svg_dir = self.slave_dir.join('svg') 88 if not self.is_compile_bot: 89 self.skia_out = self.slave_dir.join('out') 90 self.tmp_dir = self.m.path['start_dir'].join('tmp') 91 92 # Some bots also require a checkout of chromium. 93 self.need_chromium_checkout = False 94 if 'CommandBuffer' in self.builder_name: 95 self.need_chromium_checkout = True 96 self.gclient_env['GYP_CHROMIUM_NO_ACTION'] = '0' 97 if 'RecreateSKPs' in self.builder_name: 98 self.need_chromium_checkout = True 99 self.gclient_env['CPPFLAGS'] = ( 100 '-DSK_ALLOW_CROSSPROCESS_PICTUREIMAGEFILTERS=1') 101 102 self.builder_cfg = self.m.builder_name_schema.DictForBuilderName( 103 self.builder_name) 104 self.role = self.builder_cfg['role'] 105 if self.role == self.m.builder_name_schema.BUILDER_ROLE_HOUSEKEEPER: 106 self.configuration = CONFIG_RELEASE 107 else: 108 self.configuration = self.builder_cfg.get('configuration', CONFIG_DEBUG) 109 arch = (self.builder_cfg.get('arch') or self.builder_cfg.get('target_arch')) 110 if ('Win' in self.builder_cfg.get('os', '') and arch == 'x86_64'): 111 self.configuration += '_x64' 112 113 self.default_env.update({'SKIA_OUT': self.skia_out, 114 'BUILDTYPE': self.configuration}) 115 116 self.patch_storage = self.m.properties.get('patch_storage', 'gerrit') 117 self.issue = None 118 self.patchset = None 119 self.is_trybot = False 120 if (self.m.properties.get('patch_issue', '') and 121 self.m.properties.get('patch_set', '')): 122 self.is_trybot = True 123 self.issue = self.m.properties['patch_issue'] 124 self.patchset = self.m.properties['patch_set'] 125 126 self.dm_dir = self.m.path.join( 127 self.swarming_out_dir, 'dm') 128 self.perf_data_dir = self.m.path.join(self.swarming_out_dir, 129 'perfdata', self.builder_name, 'data') 130 self._swarming_bot_id = None 131 self._swarming_task_id = None 132 133 # Data should go under in _data_dir, which may be preserved across runs. 134 self.android_data_dir = '/sdcard/revenge_of_the_skiabot/' 135 # Executables go under _bin_dir, which, well, allows executable files. 136 self.android_bin_dir = '/data/local/tmp/' 137 138 if self.builder_cfg.get('os', '') == 'Chromecast': 139 # On the Chromecast, everything goes in the (~110M) /cache/skia 140 self.android_bin_dir = '/cache/skia/' 141 self.android_data_dir = '/cache/skia/' 142 143 self.chromeos_homedir = '/home/chronos/user/' 144 145 @property 146 def is_linux(self): 147 return 'Ubuntu' in self.builder_name or 'Debian' in self.builder_name 148 149 @property 150 def upload_dm_results(self): 151 # TODO(borenet): Move this into the swarm_test recipe. 152 skip_upload_bots = [ 153 'ASAN', 154 'Coverage', 155 'MSAN', 156 'TSAN', 157 'UBSAN', 158 'Valgrind', 159 ] 160 upload_dm_results = True 161 for s in skip_upload_bots: 162 if s in self.m.properties['buildername']: 163 upload_dm_results = False 164 break 165 return upload_dm_results 166 167 @property 168 def upload_perf_results(self): 169 # TODO(borenet): Move this into the swarm_perf recipe. 170 if 'Release' not in self.m.properties['buildername']: 171 return False 172 skip_upload_bots = [ 173 'ASAN', 174 'Coverage', 175 'MSAN', 176 'TSAN', 177 'UBSAN', 178 'Valgrind', 179 ] 180 upload_perf_results = True 181 for s in skip_upload_bots: 182 if s in self.m.properties['buildername']: 183 upload_perf_results = False 184 break 185 return upload_perf_results 186 187 @property 188 def swarming_bot_id(self): 189 if not self._swarming_bot_id: 190 self._swarming_bot_id = self.m.python.inline( 191 name='get swarming bot id', 192 program='''import os 193print os.environ.get('SWARMING_BOT_ID', '') 194''', 195 stdout=self.m.raw_io.output()).stdout.rstrip() 196 return self._swarming_bot_id 197 198 @property 199 def swarming_task_id(self): 200 if not self._swarming_task_id: 201 self._swarming_task_id = self.m.python.inline( 202 name='get swarming task id', 203 program='''import os 204print os.environ.get('SWARMING_TASK_ID', '') 205''', 206 stdout=self.m.raw_io.output()).stdout.rstrip() 207 return self._swarming_task_id 208 209