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 Skia Swarming compile.
7
8
9from recipe_engine import recipe_api
10
11
12def build_targets_from_builder_dict(builder_dict):
13  """Return a list of targets to build, depending on the builder type."""
14  if builder_dict.get('extra_config') == 'iOS':
15    return ['iOSShell']
16  return ['most']
17
18
19def get_extra_env_vars(builder_dict):
20  env = {}
21  if builder_dict.get('compiler') == 'Clang':
22    env['CC'] = '/usr/bin/clang'
23    env['CXX'] = '/usr/bin/clang++'
24
25  # SKNX_NO_SIMD, SK_USE_DISCARDABLE_SCALEDIMAGECACHE, etc.
26  extra_config = builder_dict.get('extra_config', '')
27  if extra_config.startswith('SK') and extra_config.isupper():
28    env['CPPFLAGS'] = '-D' + extra_config
29
30  return env
31
32
33class CompileApi(recipe_api.RecipeApi):
34  def run(self):
35    self.m.core.setup()
36
37    env = get_extra_env_vars(self.m.vars.builder_cfg)
38    build_targets = build_targets_from_builder_dict(self.m.vars.builder_cfg)
39
40    try:
41      for target in build_targets:
42        with self.m.step.context({'env': env}):
43          self.m.flavor.compile(target)
44      self.m.run.copy_build_products(
45          self.m.flavor.out_dir,
46          self.m.vars.swarming_out_dir.join(
47              'out', self.m.vars.configuration))
48      self.m.flavor.copy_extra_build_products(self.m.vars.swarming_out_dir)
49    finally:
50      if 'Win' in self.m.vars.builder_cfg.get('os', ''):
51        self.m.python.inline(
52            name='cleanup',
53            program='''import psutil
54for p in psutil.process_iter():
55  try:
56    if p.name in ('mspdbsrv.exe', 'vctip.exe', 'cl.exe', 'link.exe'):
57      p.kill()
58  except psutil._error.AccessDenied:
59    pass
60''',
61            infra_step=True)
62
63    self.m.flavor.cleanup_steps()
64    self.m.run.check_failure()
65