• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2018 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
5DOCKER_IMAGE = 'gcr.io/skia-public/android-skqp:8.1_v3'
6INNER_BUILD_DIR = '/SRC/skia/infra/skqp'
7INNER_BUILD_SCRIPT = './build_apk.sh'
8
9BUILD_PRODUCTS_ISOLATE_WHITELIST_SKQP = [
10  '*.apk'
11]
12
13
14def compile_fn(api, checkout_root, _ignore):
15  out_dir = api.vars.cache_dir.join('docker', 'skqp')
16  # We want to make sure the directories exist and were created by chrome-bot,
17  # because if that isn't the case, docker will make them and they will be
18  # owned by root, which causes mysterious failures. To mitigate this risk
19  # further, we don't use the same out_dir as everyone else (thus the _ignore)
20  # param. Instead, we use a "skqp" subdirectory in the "docker" named_cache.
21  api.file.ensure_directory('mkdirs out_dir', out_dir, mode=0777)
22
23  # This uses the emscriptem sdk docker image and says "run the
24  # build_apk.sh helper script in there". Additionally, it binds two
25  # folders: the skia checkout to /SRC and the output directory to /OUT
26  # The called helper script will make the compile happen and put the
27  # output in the right spot.  The neat thing is that since the Skia checkout
28  # (and, by extension, the build script) is not a part of the image, but
29  # bound in at runtime, we don't have to re-build the image, except when the
30  # toolchain changes.
31  cmd = ['docker', 'run', '--rm',
32         '--workdir', INNER_BUILD_DIR,
33         '--volume', '%s:/SRC' % checkout_root,
34         '--volume', '%s:/OUT' % out_dir,
35         DOCKER_IMAGE, INNER_BUILD_SCRIPT]
36  # Override DOCKER_CONFIG set by Kitchen.
37  env = {'DOCKER_CONFIG': '/home/chrome-bot/.docker'}
38  with api.env(env):
39    api.run(
40        api.step,
41        'Build SKQP apk with Docker',
42        cmd=cmd)
43
44
45def copy_extra_build_products(api, _ignore, dst):
46  out_dir = api.vars.cache_dir.join('docker', 'skqp')
47  # We don't use the normal copy_build_products because it uses
48  # shutil.move, which attempts to delete the previous file, which
49  # doesn't work because the docker created outputs are read-only and
50  # owned by root (aka only docker images). It's likely safe to change
51  # the shutil.move in the original script to a non-deleting thing
52  # (like copy or copyfile), but there's some subtle behavior differences
53  # especially with directories, that kjlubick felt it best not to risk it.
54  api.python.inline(
55      name='copy apk output',
56      program='''import errno
57import glob
58import os
59import shutil
60import sys
61
62src = sys.argv[1]
63dst = sys.argv[2]
64build_products_whitelist = %s
65
66try:
67  os.makedirs(dst)
68except OSError as e:
69  if e.errno != errno.EEXIST:
70    raise
71
72for pattern in build_products_whitelist:
73  path = os.path.join(src, pattern)
74  for f in glob.glob(path):
75    dst_path = os.path.join(dst, os.path.relpath(f, src))
76    if not os.path.isdir(os.path.dirname(dst_path)):
77      os.makedirs(os.path.dirname(dst_path))
78    print 'Copying build product %%s to %%s' %% (f, dst_path)
79    # Because Docker usually has some strange permissions (like root
80    # ownership), we'd rather not keep those around. copyfile doesn't
81    # keep the metadata around, so that helps us.
82    shutil.copyfile(f, dst_path)
83''' % str(BUILD_PRODUCTS_ISOLATE_WHITELIST_SKQP),
84      args=[out_dir, dst],
85      infra_step=True)
86