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