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 setup(self):
19    """Prepare the variables."""
20    # Setup
21    self.builder_name = self.m.properties['buildername']
22
23    self.slave_dir = self.m.path['start_dir']
24
25    # Special input/output directories.
26    self.build_dir = self.slave_dir.join('build')
27
28    self.default_env = self.m.context.env
29    self.default_env['CHROME_HEADLESS'] = '1'
30    self.default_env['PATH'] = self.m.path.pathsep.join([
31        self.default_env.get('PATH', '%(PATH)s'),
32        str(self.m.bot_update._module.PACKAGE_REPO_ROOT),
33    ])
34    self.cache_dir = self.slave_dir.join('cache')
35
36    self.swarming_out_dir = self.slave_dir.join(
37        self.m.properties['swarm_out_dir'])
38
39    self.tmp_dir = self.m.path['start_dir'].join('tmp')
40
41    self.builder_cfg = self.m.builder_name_schema.DictForBuilderName(
42        self.builder_name)
43    self.role = self.builder_cfg['role']
44    if self.role in [self.m.builder_name_schema.BUILDER_ROLE_HOUSEKEEPER,
45                     self.m.builder_name_schema.BUILDER_ROLE_CALMBENCH]:
46      self.configuration = CONFIG_RELEASE
47    else:
48      self.configuration = self.builder_cfg.get('configuration', CONFIG_DEBUG)
49    arch = (self.builder_cfg.get('arch') or self.builder_cfg.get('target_arch'))
50    if ('Win' in self.builder_cfg.get('os', '') and arch == 'x86_64'):
51      self.configuration += '_x64'
52
53    self.extra_tokens = []
54    if len(self.builder_cfg.get('extra_config', '')) > 0:
55      if self.builder_cfg['extra_config'].startswith('SK'):
56        assert self.builder_cfg['extra_config'].isupper()
57        self.extra_tokens = [self.builder_cfg['extra_config']]
58      else:
59        self.extra_tokens = self.builder_cfg['extra_config'].split('_')
60
61    self.patch_storage = self.m.properties.get('patch_storage', 'gerrit')
62    self.issue = None
63    self.patchset = None
64    self.is_trybot = False
65    if (self.m.properties.get('patch_issue', '') and
66        self.m.properties.get('patch_set', '') and
67        self.m.properties.get('patch_ref', '')):
68      self.is_trybot = True
69      self.issue = self.m.properties['patch_issue']
70      self.patchset = self.m.properties['patch_set']
71
72    self._swarming_bot_id = None
73    self._swarming_task_id = None
74
75    # Internal bot support.
76    self.internal_hardware_label = (
77        self.m.properties.get('internal_hardware_label'))
78    self.is_internal_bot = self.internal_hardware_label is not None
79
80  @property
81  def is_linux(self):
82    return 'Ubuntu' in self.builder_name or 'Debian' in self.builder_name
83
84  @property
85  def swarming_bot_id(self):
86    if not self._swarming_bot_id:
87      self._swarming_bot_id = self.m.python.inline(
88          name='get swarming bot id',
89          program='''import os
90print os.environ.get('SWARMING_BOT_ID', '')
91''',
92          stdout=self.m.raw_io.output()).stdout.rstrip()
93    return self._swarming_bot_id
94
95  @property
96  def swarming_task_id(self):
97    if not self._swarming_task_id:
98      self._swarming_task_id = self.m.python.inline(
99          name='get swarming task id',
100          program='''import os
101print os.environ.get('SWARMING_TASK_ID', '')
102''',
103          stdout=self.m.raw_io.output()).stdout.rstrip()
104    return self._swarming_task_id
105