Home | History | Annotate | Download | only in flavor
      1 # Copyright 2014 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 
      9 """Default flavor utils class, used for desktop builders."""
     10 
     11 
     12 import json
     13 
     14 
     15 WIN_TOOLCHAIN_DIR = 't'
     16 
     17 
     18 class DeviceDirs(object):
     19   def __init__(self,
     20                dm_dir,
     21                perf_data_dir,
     22                resource_dir,
     23                images_dir,
     24                skp_dir,
     25                svg_dir,
     26                tmp_dir):
     27     self._dm_dir = dm_dir
     28     self._perf_data_dir = perf_data_dir
     29     self._resource_dir = resource_dir
     30     self._images_dir = images_dir
     31     self._skp_dir = skp_dir
     32     self._svg_dir = svg_dir
     33     self._tmp_dir = tmp_dir
     34 
     35   @property
     36   def dm_dir(self):
     37     """Where DM writes."""
     38     return self._dm_dir
     39 
     40   @property
     41   def perf_data_dir(self):
     42     return self._perf_data_dir
     43 
     44   @property
     45   def resource_dir(self):
     46     return self._resource_dir
     47 
     48   @property
     49   def images_dir(self):
     50     return self._images_dir
     51 
     52   @property
     53   def skp_dir(self):
     54     """Holds SKP files that are consumed by RenderSKPs and BenchPictures."""
     55     return self._skp_dir
     56 
     57   @property
     58   def svg_dir(self):
     59     return self._svg_dir
     60 
     61   @property
     62   def tmp_dir(self):
     63     return self._tmp_dir
     64 
     65 
     66 class DefaultFlavorUtils(object):
     67   """Utilities to be used by build steps.
     68 
     69   The methods in this class define how certain high-level functions should
     70   work. Each build step flavor should correspond to a subclass of
     71   DefaultFlavorUtils which may override any of these functions as appropriate
     72   for that flavor.
     73 
     74   For example, the AndroidFlavorUtils will override the functions for
     75   copying files between the host and Android device, as well as the
     76   'step' function, so that commands may be run through ADB.
     77   """
     78   def __init__(self, m):
     79     self.m = m
     80     self._chrome_path = None
     81     self._win_toolchain_dir = self.m.vars.slave_dir.join(WIN_TOOLCHAIN_DIR)
     82     win_toolchain_asset_path = self.m.vars.infrabots_dir.join(
     83         'assets', 'win_toolchain', 'VERSION')
     84     if not self.m.path.exists(win_toolchain_asset_path):
     85       self._win_toolchain_dir = self.m.vars.slave_dir
     86 
     87   def copy_extra_build_products(self, swarming_out_dir):
     88     pass
     89 
     90   @property
     91   def out_dir(self):
     92     """Flavor-specific out directory."""
     93     return self.m.vars.skia_out.join(self.m.vars.configuration)
     94 
     95   def device_path_join(self, *args):
     96     """Like os.path.join(), but for paths on a connected device."""
     97     return self.m.path.join(*args)
     98 
     99   def copy_directory_contents_to_device(self, host_dir, device_dir):
    100     """Like shutil.copytree(), but for copying to a connected device."""
    101     # For "normal" builders who don't have an attached device, we expect
    102     # host_dir and device_dir to be the same.
    103     if str(host_dir) != str(device_dir):
    104       raise ValueError('For builders who do not have attached devices, copying '
    105                        'from host to device is undefined and only allowed if '
    106                        'host_path and device_path are the same (%s vs %s).' % (
    107                        str(host_dir), str(device_dir)))  # pragma: no cover
    108 
    109   def copy_directory_contents_to_host(self, device_dir, host_dir):
    110     """Like shutil.copytree(), but for copying from a connected device."""
    111     # For "normal" builders who don't have an attached device, we expect
    112     # host_dir and device_dir to be the same.
    113     if str(host_dir) != str(device_dir):
    114       raise ValueError('For builders who do not have attached devices, copying '
    115                        'from device to host is undefined and only allowed if '
    116                        'host_path and device_path are the same (%s vs %s).' % (
    117                        str(host_dir), str(device_dir)))  # pragma: no cover
    118 
    119   def copy_file_to_device(self, host_path, device_path):
    120     """Like shutil.copyfile, but for copying to a connected device."""
    121     # For "normal" builders who don't have an attached device, we expect
    122     # host_dir and device_dir to be the same.
    123     if str(host_path) != str(device_path):  # pragma: no cover
    124       raise ValueError('For builders who do not have attached devices, copying '
    125                        'from host to device is undefined and only allowed if '
    126                        'host_path and device_path are the same (%s vs %s).' % (
    127                        str(host_path), str(device_path)))
    128 
    129   def create_clean_device_dir(self, path):
    130     """Like shutil.rmtree() + os.makedirs(), but on a connected device."""
    131     self.create_clean_host_dir(path)
    132 
    133   def create_clean_host_dir(self, path):
    134     """Convenience function for creating a clean directory."""
    135     self.m.run.rmtree(path)
    136     self.m.file.makedirs(
    137         self.m.path.basename(path), path, infra_step=True)
    138 
    139   def install(self):
    140     """Run device-specific installation steps."""
    141     self.device_dirs = DeviceDirs(
    142         dm_dir=self.m.vars.dm_dir,
    143         perf_data_dir=self.m.vars.perf_data_dir,
    144         resource_dir=self.m.vars.resource_dir,
    145         images_dir=self.m.vars.images_dir,
    146         skp_dir=self.m.vars.local_skp_dir,
    147         svg_dir=self.m.vars.local_svg_dir,
    148         tmp_dir=self.m.vars.tmp_dir)
    149 
    150   def cleanup_steps(self):
    151     """Run any device-specific cleanup steps."""
    152     pass
    153