Debian Codegraph @

infra/bots/recipe_modules/build/util.py

raw
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
5
6 """Shared utilities for the build recipe module."""
7
8
9 # This lists the products we want to isolate as outputs for future steps.
10 DEFAULT_BUILD_PRODUCTS = [
11 'dm',
12 'dm.exe',
13 'dm.app',
14 'nanobench.app',
15 'get_images_from_skps',
16 'get_images_from_skps.exe',
17 'nanobench',
18 'nanobench.exe',
19 '*.so',
20 '*.dll',
21 '*.dylib',
22 'skottie_tool',
23 'lib/*.so',
24 'run_testlab',
25 ]
26
27 def py_to_gn(val):
28 """Convert val to a string that can be used as GN args."""
29 if isinstance(val, bool):
30 return 'true' if val else 'false'
31 elif '%s' % val == val:
32 # TODO(dogben): Handle quoting "$\
33 return '"%s"' % val
34 elif isinstance(val, (list, tuple)):
35 return '[%s]' % (','.join(py_to_gn(x) for x in val))
36 elif isinstance(val, dict):
37 gn = ' '.join(
38 '%s=%s' % (k, py_to_gn(v)) for (k, v) in sorted(val.items()))
39 return gn
40 else: # pragma: nocover
41 raise Exception('Converting %s to gn is not implemented.' % type(val))
42
43
44 def copy_listed_files(api, src, dst, product_list):
45 """Copy listed files src to dst."""
46 script = api.build.resource('copy_build_products.py')
47 api.step(
48 name='copy build products',
49 cmd=['python3', script, src, dst, ','.join(product_list)],
50 infra_step=True)
51
52
53 def set_dawn_args_and_env(args, env, api, extra_tokens, skia_dir):
54 """Add to ``args`` and ``env`` the gn args and environment vars needed to
55 make a build targeting Dawn."""
56 args['skia_use_dawn'] = 'true'
57 args['skia_use_gl'] = 'false'
58 # Set dawn specific args to limit which backends are built
59 args['dawn_enable_d3d11'] = 'false'
60 args['dawn_enable_d3d12'] = 'false'
61 args['dawn_enable_metal'] = 'false'
62 args['dawn_enable_opengles'] = 'false'
63 args['dawn_enable_vulkan'] = 'false'
64 if 'D3D11' in extra_tokens:
65 args['dawn_enable_d3d11'] = 'true'
66 if 'D3D12' in extra_tokens:
67 args['dawn_enable_d3d12'] = 'true'
68 if 'GLES' in extra_tokens:
69 args['dawn_enable_opengles'] = 'true'
70 if 'Metal' in extra_tokens:
71 args['dawn_enable_metal'] = 'true'
72 if 'Vulkan' in extra_tokens:
73 args['dawn_enable_vulkan'] = 'true'
74 env['PYTHONPATH'] = api.path.pathsep.join([
75 str(skia_dir.joinpath('third_party', 'externals')), '%%(PYTHONPATH)s'])