Home | History | Annotate | Download | only in core
      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 import json
     10 import os
     11 import re
     12 import sys
     13 
     14 from recipe_engine import recipe_api
     15 from recipe_engine import config_types
     16 
     17 
     18 class SkiaApi(recipe_api.RecipeApi):
     19 
     20   def setup(self):
     21     """Prepare the bot to run."""
     22     # Setup dependencies.
     23     self.m.vars.setup()
     24 
     25     # Check out the Skia code.
     26     self.checkout_steps()
     27 
     28     if not self.m.path.exists(self.m.vars.tmp_dir):
     29       self.m.run.run_once(self.m.file.ensure_directory,
     30                           'makedirs tmp_dir',
     31                           self.m.vars.tmp_dir)
     32 
     33     self.m.flavor.setup()
     34 
     35   def checkout_steps(self):
     36     """Run the steps to obtain a checkout of Skia."""
     37     cfg_kwargs = {}
     38     if not self.m.vars.persistent_checkout:
     39       # We should've obtained the Skia checkout through isolates, so we don't
     40       # need to perform the checkout ourselves.
     41       return
     42 
     43     # Use a persistent gclient cache for Swarming.
     44     cfg_kwargs['CACHE_DIR'] = self.m.vars.gclient_cache
     45 
     46     # Create the checkout path if necessary.
     47     if not self.m.path.exists(self.m.vars.checkout_root):
     48       self.m.file.ensure_directory('makedirs checkout_path',
     49                                    self.m.vars.checkout_root)
     50 
     51     # Initial cleanup.
     52     gclient_cfg = self.m.gclient.make_config(**cfg_kwargs)
     53     main_repo = self.m.properties['repository']
     54     if self.m.vars.need_pdfium_checkout:
     55       main_repo = 'https://pdfium.googlesource.com/pdfium.git'
     56     if self.m.vars.need_flutter_checkout:
     57       main_repo = 'https://github.com/flutter/engine.git'
     58     main_name = self.m.path.basename(main_repo)
     59     if main_name.endswith('.git'):
     60       main_name = main_name[:-len('.git')]
     61       # Special case for flutter because it seems to need a very specific
     62       # directory structure to successfully build.
     63       if self.m.vars.need_flutter_checkout and main_name == 'engine':
     64         main_name = 'src/flutter'
     65     main = gclient_cfg.solutions.add()
     66     main.name = main_name
     67     main.managed = False
     68     main.url = main_repo
     69     main.revision = self.m.properties.get('revision') or 'origin/master'
     70     m = gclient_cfg.got_revision_mapping
     71     m[main_name] = 'got_revision'
     72     patch_root = main_name
     73     patch_repo = main.url
     74     if self.m.properties.get('patch_repo'):
     75       patch_repo = self.m.properties['patch_repo']
     76       patch_root = patch_repo.split('/')[-1]
     77       if patch_root.endswith('.git'):
     78         patch_root = patch_root[:-4]
     79 
     80     if self.m.vars.need_pdfium_checkout:
     81       # Skia is a DEP of PDFium; the 'revision' property is a Skia revision, and
     82       # any patch should be applied to Skia, not PDFium.
     83       main.revision = 'origin/master'
     84       main.managed = True
     85       m[main_name] = 'got_%s_revision' % main_name
     86 
     87       skia_dep_path = 'pdfium/third_party/skia'
     88       gclient_cfg.patch_projects['skia'] = (skia_dep_path, 'HEAD')
     89       gclient_cfg.revisions[skia_dep_path] = self.m.properties['revision']
     90       m[skia_dep_path] = 'got_revision'
     91       patch_repo = 'https://skia.googlesource.com/skia.git'
     92       patch_root = skia_dep_path
     93 
     94     if self.m.vars.need_flutter_checkout:
     95       # Skia is a DEP of Flutter; the 'revision' property is a Skia revision,
     96       # and any patch should be applied to Skia, not Flutter.
     97       main.revision = 'origin/master'
     98       main.managed = True
     99       m[main_name] = 'got_flutter_revision'
    100       if 'Android' in self.m.vars.builder_cfg.get('extra_config', ''):
    101         gclient_cfg.target_os.add('android')
    102 
    103       skia_dep_path = 'src/third_party/skia'
    104       gclient_cfg.patch_projects['skia'] = (skia_dep_path, 'HEAD')
    105       gclient_cfg.revisions[skia_dep_path] = self.m.properties['revision']
    106       m[skia_dep_path] = 'got_revision'
    107       patch_repo = 'https://skia.googlesource.com/skia.git'
    108       patch_root = skia_dep_path
    109 
    110     # TODO(rmistry): Remove the below block after there is a solution for
    111     #                crbug.com/616443
    112     entries_file = self.m.vars.checkout_root.join('.gclient_entries')
    113     if self.m.path.exists(entries_file) or self._test_data.enabled:
    114       self.m.file.remove('remove %s' % entries_file,
    115                          entries_file)
    116 
    117     if self.m.vars.need_chromium_checkout:
    118       chromium = gclient_cfg.solutions.add()
    119       chromium.name = 'src'
    120       chromium.managed = False
    121       chromium.url = 'https://chromium.googlesource.com/chromium/src.git'
    122       chromium.revision = 'origin/lkgr'
    123 
    124     # Run bot_update.
    125 
    126     # Hack the patch ref if necessary.
    127     if self.m.bot_update._issue and self.m.bot_update._patchset:
    128       self.m.bot_update._gerrit_ref = 'refs/changes/%s/%d/%d' % (
    129           str(self.m.bot_update._issue)[-2:],
    130           self.m.bot_update._issue,
    131           self.m.bot_update._patchset,
    132       )
    133       self.m.bot_update._repository = patch_repo
    134 
    135     self.m.gclient.c = gclient_cfg
    136     with self.m.context(cwd=self.m.vars.checkout_root):
    137       update_step = self.m.bot_update.ensure_checkout(patch_root=patch_root)
    138 
    139     self.m.vars.got_revision = (
    140         update_step.presentation.properties['got_revision'])
    141 
    142     if self.m.vars.need_chromium_checkout:
    143       with self.m.context(cwd=self.m.vars.checkout_root,
    144                           env=self.m.vars.gclient_env):
    145         self.m.gclient.runhooks()
    146