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