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 ast | |
6 import os | |
7 | |
8 from pylib import constants | |
9 | |
10 | |
11 def DevicePathComponentsFor(host_path, output_directory): | |
12 """Returns the device path components for a given host path. | |
13 | |
14 This returns the device path as a list of joinable path components, | |
15 with None as the first element to indicate that the path should be | |
16 rooted at $EXTERNAL_STORAGE. | |
17 | |
18 e.g., given | |
19 | |
20 '$CHROMIUM_SRC/foo/bar/baz.txt' | |
21 | |
22 this would return | |
23 | |
24 [None, 'foo', 'bar', 'baz.txt'] | |
25 | |
26 This handles a couple classes of paths differently than it otherwise would: | |
27 - All .pak files get mapped to top-level paks/ | |
28 - Anything in the output directory gets mapped relative to the output | |
29 directory rather than the source directory. | |
30 | |
31 e.g. given | |
32 | |
33 '$CHROMIUM_SRC/out/Release/icu_fake_dir/icudtl.dat' | |
34 | |
35 this would return | |
36 | |
37 [None, 'icu_fake_dir', 'icudtl.dat'] | |
Dirk Pranke
2016/11/15 22:33:06
I don't know any of the surrounding code, so don't
jbudorick
2016/11/16 03:47:51
I'm not sure what you mean here, which leads me to
Dirk Pranke
2016/11/17 03:05:45
Ah, it doesn't help that I wrote "//out" when I me
| |
38 | |
39 Args: | |
40 host_path: The absolute path to the host file. | |
41 Returns: | |
42 A list of device path components. | |
43 """ | |
44 if host_path.startswith(output_directory): | |
45 if os.path.splitext(host_path)[1] == '.pak': | |
46 return [None, 'paks', os.path.basename(host_path)] | |
47 rel_host_path = os.path.relpath(host_path, output_directory) | |
48 else: | |
49 rel_host_path = os.path.relpath(host_path, constants.DIR_SOURCE_ROOT) | |
50 | |
51 device_path_components = [None] | |
52 p = rel_host_path | |
53 while p: | |
54 p, d = os.path.split(p) | |
55 if d: | |
56 device_path_components.insert(1, d) | |
57 return device_path_components | |
58 | |
59 | |
60 def GetDataDependencies(isolate_file_path): | |
61 """Returns a list of device data dependencies. | |
62 | |
63 Args: | |
64 isolate_file_path: A str path to the isolate file. | |
65 Returns: | |
66 A list of (host_path, device_path) tuples. | |
67 """ | |
68 if not isolate_file_path: | |
69 return [] | |
70 | |
71 with open(isolate_file_path, 'r') as isolate_file: | |
72 isolate_contents = ast.literal_eval(isolate_file.read()) | |
Dirk Pranke
2016/11/15 22:33:05
Where does the isolate_file_path come from? Can we
jbudorick
2016/11/16 03:47:51
Rewritten.
| |
73 | |
74 isolate_file_dir = os.path.dirname(isolate_file_path) | |
75 rel_host_files = isolate_contents.get('variables', {}).get('files', []) | |
76 abs_host_files = [ | |
77 os.path.abspath(os.path.join(isolate_file_dir, r)) | |
78 for r in rel_host_files] | |
79 | |
80 return [(a, DevicePathComponentsFor(a, constants.GetOutDirectory())) | |
81 for a in abs_host_files] | |
82 | |
OLD | NEW |