OLD | NEW |
| (Empty) |
1 # Copyright 2016 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 import os | |
6 import re | |
7 | |
8 from pylib import constants | |
9 | |
10 | |
11 _BLACKLIST = [ | |
12 re.compile(r'.*OWNERS'), # Should never be included. | |
13 re.compile(r'.*\.crx'), # Chrome extension zip files. | |
14 re.compile(r'.*\.so'), # Libraries packed into .apk. | |
15 re.compile(r'.*Mojo.*manifest\.json'), # Some source_set()s pull these in. | |
16 re.compile(r'.*\.py'), # Some test_support targets include python deps. | |
17 | |
18 # Some test_support targets include python deps. | |
19 re.compile(r'.*\.mojom\.js'), | |
20 | |
21 # Chrome external extensions config file. | |
22 re.compile(r'.*external_extensions\.json'), | |
23 | |
24 # Exists just to test the compile, not to be run. | |
25 re.compile(r'.*jni_generator_tests'), | |
26 | |
27 # v8's blobs get packaged into APKs. | |
28 re.compile(r'.*natives_blob.*\.bin'), | |
29 re.compile(r'.*snapshot_blob.*\.bin'), | |
30 ] | |
31 | |
32 | |
33 def DevicePathComponentsFor(host_path, output_directory): | |
34 """Returns the device path components for a given host path. | |
35 | |
36 This returns the device path as a list of joinable path components, | |
37 with None as the first element to indicate that the path should be | |
38 rooted at $EXTERNAL_STORAGE. | |
39 | |
40 e.g., given | |
41 | |
42 '$CHROMIUM_SRC/foo/bar/baz.txt' | |
43 | |
44 this would return | |
45 | |
46 [None, 'foo', 'bar', 'baz.txt'] | |
47 | |
48 This handles a couple classes of paths differently than it otherwise would: | |
49 - All .pak files get mapped to top-level paks/ | |
50 - Anything in the output directory gets mapped relative to the output | |
51 directory rather than the source directory. | |
52 | |
53 e.g. given | |
54 | |
55 '$CHROMIUM_SRC/out/Release/icu_fake_dir/icudtl.dat' | |
56 | |
57 this would return | |
58 | |
59 [None, 'icu_fake_dir', 'icudtl.dat'] | |
60 | |
61 Args: | |
62 host_path: The absolute path to the host file. | |
63 Returns: | |
64 A list of device path components. | |
65 """ | |
66 if host_path.startswith(output_directory): | |
67 if os.path.splitext(host_path)[1] == '.pak': | |
68 return [None, 'paks', os.path.basename(host_path)] | |
69 rel_host_path = os.path.relpath(host_path, output_directory) | |
70 else: | |
71 rel_host_path = os.path.relpath(host_path, constants.DIR_SOURCE_ROOT) | |
72 | |
73 device_path_components = [None] | |
74 p = rel_host_path | |
75 while p: | |
76 p, d = os.path.split(p) | |
77 if d: | |
78 device_path_components.insert(1, d) | |
79 return device_path_components | |
80 | |
81 | |
82 def GetDataDependencies(runtime_deps_path): | |
83 """Returns a list of device data dependencies. | |
84 | |
85 Args: | |
86 runtime_deps_path: A str path to the .runtime_deps file. | |
87 Returns: | |
88 A list of (host_path, device_path) tuples. | |
89 """ | |
90 if not runtime_deps_path: | |
91 return [] | |
92 | |
93 with open(runtime_deps_path, 'r') as runtime_deps_file: | |
94 rel_host_files = [l.strip() for l in runtime_deps_file if l] | |
95 | |
96 output_directory = constants.GetOutDirectory() | |
97 abs_host_files = [ | |
98 os.path.abspath(os.path.join(output_directory, r)) | |
99 for r in rel_host_files] | |
100 filtered_abs_host_files = [ | |
101 host_file for host_file in abs_host_files | |
102 if not any(blacklist_re.match(host_file) for blacklist_re in _BLACKLIST)] | |
103 return [(f, DevicePathComponentsFor(f, output_directory)) | |
104 for f in filtered_abs_host_files] | |
OLD | NEW |