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 5from . import util 6 7IMAGES = { 8 # Used to build Flutter_Android in Debian9, since the underlying build 9 # scripts require jdk8. 10 'Debian9': ( 11 'gcr.io/skia-public/debian9@sha256:' 12 '5541f5674eee0a1558f1335c711f674f85f96b9ae8fb6c289f42dd81479a768e'), 13} 14 15def compile_fn(api, checkout_root, out_dir): 16 flutter_dir = checkout_root.join('src') 17 configuration = api.vars.builder_cfg.get('configuration').lower() 18 os_name = api.vars.builder_cfg.get('os', '') 19 extra_tokens = api.vars.extra_tokens 20 builder_name = api.vars.builder_name 21 22 # Setup GN args. 23 gn_args = ['--runtime-mode=%s' % configuration,] 24 if 'Android' in extra_tokens: 25 gn_args.append('--android') 26 27 if os_name == 'Debian9' and 'Docker' in builder_name: 28 script = api.build.resource('docker-flutter-compile.sh') 29 image_hash = IMAGES[os_name] 30 api.docker.run('Run build script in Docker', image_hash, 31 api.path['start_dir'], out_dir, script, 32 [api.path['start_dir'], flutter_dir, out_dir] + gn_args, 33 match_directory_structure=True) 34 return 35 36 with api.context(cwd=flutter_dir): 37 # Delete out_dir so that we start from a clean slate. See skbug/6310. 38 api.run.rmtree(out_dir) 39 40 # Run GN. 41 api.run( 42 api.step, 43 'gn_gen', 44 cmd=['flutter/tools/gn'] + gn_args) 45 46 # Build Flutter. 47 api.run( 48 api.step, 49 'build_flutter', 50 cmd=['ninja', '-C', out_dir, '-j100']) 51 52 53FLUTTER_BUILD_PRODUCTS_LIST = [ 54 '*.so', 55 'lib/*.so', 56] 57 58def copy_build_products(api, src, dst): 59 util.copy_listed_files(api, src, dst, FLUTTER_BUILD_PRODUCTS_LIST) 60 stripped_src = src.join('lib.stripped', 'libflutter.so') 61 stripped_dst = dst.join('libflutter_stripped.so') 62 api.python.inline( 63 name='copy stripped library', 64 program=''' 65import os 66import shutil 67import sys 68 69src = sys.argv[1] 70dst = sys.argv[2] 71 72if not os.path.isdir(os.path.dirname(dst)): 73 os.makedirs(os.path.dirname(dst)) 74 75shutil.copyfile(src, dst) 76''', 77 args=[stripped_src, stripped_dst], 78 infra_step=True) 79