2018-10-09 13:36:35 +00:00
|
|
|
# Copyright 2018 The Chromium Authors. All rights reserved.
|
|
|
|
# Use of this source code is governed by a BSD-style license that can be
|
|
|
|
# found in the LICENSE file.
|
|
|
|
|
2019-10-09 14:46:14 +00:00
|
|
|
DOCKER_IMAGE = 'gcr.io/skia-public/canvaskit-emsdk:1.38.47_v1'
|
2018-10-09 13:36:35 +00:00
|
|
|
INNER_BUILD_SCRIPT = '/SRC/skia/infra/canvaskit/build_canvaskit.sh'
|
|
|
|
|
|
|
|
|
|
|
|
def compile_fn(api, checkout_root, _ignore):
|
|
|
|
out_dir = api.vars.cache_dir.join('docker', 'canvaskit')
|
|
|
|
configuration = api.vars.builder_cfg.get('configuration', '')
|
2019-01-31 17:47:20 +00:00
|
|
|
extra = api.vars.builder_cfg.get('extra_config', '')
|
2018-10-09 13:36:35 +00:00
|
|
|
|
|
|
|
# We want to make sure the directories exist and were created by chrome-bot,
|
|
|
|
# because if that isn't the case, docker will make them and they will be
|
|
|
|
# owned by root, which causes mysterious failures. To mitigate this risk
|
|
|
|
# further, we don't use the same out_dir as everyone else (thus the _ignore)
|
2019-01-31 17:47:20 +00:00
|
|
|
# param. Instead, we use a "canvaskit" subdirectory in the "docker" named_cache.
|
2018-10-09 13:36:35 +00:00
|
|
|
api.file.ensure_directory('mkdirs out_dir', out_dir, mode=0777)
|
|
|
|
|
|
|
|
# This uses the emscriptem sdk docker image and says "run the
|
2019-01-31 17:47:20 +00:00
|
|
|
# build_canvaskit.sh helper script in there". Additionally, it binds two
|
2018-10-09 13:36:35 +00:00
|
|
|
# folders: the Skia checkout to /SRC and the output directory to /OUT
|
|
|
|
# The called helper script will make the compile happen and put the
|
|
|
|
# output in the right spot. The neat thing is that since the Skia checkout
|
|
|
|
# (and, by extension, the build script) is not a part of the image, but
|
|
|
|
# bound in at runtime, we don't have to re-build the image, except when the
|
|
|
|
# toolchain changes.
|
|
|
|
# Of note, the wasm build doesn't re-use any intermediate steps from the
|
|
|
|
# previous builds, so it's essentially a build from scratch every time.
|
2019-01-31 17:47:20 +00:00
|
|
|
cmd = ['docker', 'run', '--rm', '--volume', '%s:/SRC' % checkout_root,
|
|
|
|
'--volume', '%s:/OUT' % out_dir,
|
2018-10-09 13:36:35 +00:00
|
|
|
DOCKER_IMAGE, INNER_BUILD_SCRIPT]
|
2018-10-16 14:15:01 +00:00
|
|
|
if 'CPU' in extra:
|
|
|
|
cmd.append('cpu') # It defaults to gpu
|
|
|
|
|
2018-10-09 13:36:35 +00:00
|
|
|
if configuration == 'Debug':
|
|
|
|
cmd.append('debug') # It defaults to Release
|
2019-01-22 23:09:30 +00:00
|
|
|
# Override DOCKER_CONFIG set by Kitchen.
|
|
|
|
env = {'DOCKER_CONFIG': '/home/chrome-bot/.docker'}
|
|
|
|
with api.env(env):
|
|
|
|
api.run(
|
|
|
|
api.step,
|
|
|
|
'Build CanvasKit with Docker',
|
|
|
|
cmd=cmd)
|
2018-10-09 13:36:35 +00:00
|
|
|
|
|
|
|
|
2019-10-04 14:13:42 +00:00
|
|
|
CANVASKIT_BUILD_PRODUCTS = [
|
|
|
|
'canvaskit.*'
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
def copy_build_products(api, _ignore, dst):
|
2018-10-09 13:36:35 +00:00
|
|
|
out_dir = api.vars.cache_dir.join('docker', 'canvaskit')
|
2019-10-04 14:13:42 +00:00
|
|
|
# We don't use the normal copy_listed_files because it uses
|
2018-10-09 13:36:35 +00:00
|
|
|
# shutil.move, which attempts to delete the previous file, which
|
|
|
|
# doesn't work because the docker created outputs are read-only and
|
|
|
|
# owned by root (aka only docker images). It's likely safe to change
|
|
|
|
# the shutil.move in the original script to a non-deleting thing
|
|
|
|
# (like copy or copyfile), but there's some subtle behavior differences
|
|
|
|
# especially with directories, that kjlubick felt it best not to risk it.
|
|
|
|
api.python.inline(
|
|
|
|
name='copy wasm output',
|
|
|
|
program='''import errno
|
|
|
|
import glob
|
|
|
|
import os
|
|
|
|
import shutil
|
|
|
|
import sys
|
|
|
|
|
|
|
|
src = sys.argv[1]
|
|
|
|
dst = sys.argv[2]
|
2019-10-04 14:13:42 +00:00
|
|
|
build_products = %s
|
2018-10-09 13:36:35 +00:00
|
|
|
|
|
|
|
try:
|
|
|
|
os.makedirs(dst)
|
|
|
|
except OSError as e:
|
|
|
|
if e.errno != errno.EEXIST:
|
|
|
|
raise
|
|
|
|
|
2019-10-04 14:13:42 +00:00
|
|
|
for pattern in build_products:
|
2018-10-09 13:36:35 +00:00
|
|
|
path = os.path.join(src, pattern)
|
|
|
|
for f in glob.glob(path):
|
|
|
|
dst_path = os.path.join(dst, os.path.relpath(f, src))
|
|
|
|
if not os.path.isdir(os.path.dirname(dst_path)):
|
|
|
|
os.makedirs(os.path.dirname(dst_path))
|
|
|
|
print 'Copying build product %%s to %%s' %% (f, dst_path)
|
|
|
|
# Because Docker usually has some strange permissions (like root
|
|
|
|
# ownership), we'd rather not keep those around. copyfile doesn't
|
|
|
|
# keep the metadata around, so that helps us.
|
|
|
|
shutil.copyfile(f, dst_path)
|
2019-10-04 14:13:42 +00:00
|
|
|
''' % str(CANVASKIT_BUILD_PRODUCTS),
|
2018-10-09 13:36:35 +00:00
|
|
|
args=[out_dir, dst],
|
|
|
|
infra_step=True)
|