1# Copyright 2019 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
5from . import util
6
7DOCKER_IMAGE = 'gcr.io/skia-public/cmake-release:3.13.1_v2'
8INNER_BUILD_SCRIPT = '/SRC/skia/infra/cmake/build_skia.sh'
9
10
11def compile_fn(api, checkout_root, _ignore):
12  out_dir = api.vars.cache_dir.join('docker', 'cmake')
13  configuration = api.vars.builder_cfg.get('configuration', '')
14  if configuration != 'Release': # pragma: nocover
15    # If a debug mode is wanted, update the infra/cmake/build_skia.sh
16    # to support that also.
17    raise 'Only Release mode supported for CMake'
18
19  # We want to make sure the directories exist and were created by chrome-bot,
20  # because if that isn't the case, docker will make them and they will be
21  # owned by root, which causes mysterious failures. To mitigate this risk
22  # further, we don't use the same out_dir as everyone else (thus the _ignore)
23  # param. Instead, we use a "cmake" subdirectory in the "docker" named_cache.
24  api.file.ensure_directory('mkdirs out_dir', out_dir, mode=0o777)
25
26  # This uses the cmake docker image and says "run the
27  # build_skia.sh helper script in there". Additionally, it binds two
28  # folders: the Skia checkout to /SRC and the output directory to /OUT
29  # The called helper script will make the compile happen and put the
30  # output in the right spot.  The neat thing is that since the Skia checkout
31  # (and, by extension, the build script) is not a part of the image, but
32  # bound in at runtime, we don't have to re-build the image, except when the
33  # toolchain changes.
34  cmd = ['docker', 'run', '--rm', '--volume', '%s:/SRC' % checkout_root,
35         '--volume', '%s:/OUT' % out_dir,
36         DOCKER_IMAGE, INNER_BUILD_SCRIPT]
37  # It's always Release mode (for now?) This is mostly an FYI
38  # thing, to make sure we don't break CMake users.
39
40  # Override DOCKER_CONFIG set by Kitchen.
41  env = {'DOCKER_CONFIG': '/home/chrome-bot/.docker'}
42  with api.env(env):
43    api.run(
44        api.step,
45        'Build Skia using CMake in Docker',
46        cmd=cmd)
47
48def copy_build_products(api, src, dst):
49  util.copy_listed_files(api, src, dst, util.DEFAULT_BUILD_PRODUCTS)
50