Chromium Code Reviews| Index: build/android/pylib/utils/device_dependencies.py |
| diff --git a/build/android/pylib/utils/device_dependencies.py b/build/android/pylib/utils/device_dependencies.py |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..e9b06cf73d90e84353d0bf6f20c0c8e4423e4610 |
| --- /dev/null |
| +++ b/build/android/pylib/utils/device_dependencies.py |
| @@ -0,0 +1,82 @@ |
| +# Copyright 2016 The Chromium Authors. All rights reserved. |
| +# Use of this source code is governed by a BSD-style license that can be |
| +# found in the LICENSE file. |
| + |
| +import ast |
| +import os |
| + |
| +from pylib import constants |
| + |
| + |
| +def DevicePathComponentsFor(host_path, output_directory): |
| + """Returns the device path components for a given host path. |
| + |
| + This returns the device path as a list of joinable path compoents, |
|
agrieve
2016/11/15 15:51:01
compoents
jbudorick
2016/11/15 19:33:15
Doe
|
| + with None as the first element to indicate that the path should be |
| + rooted at $EXTERNAL_STORAGE. |
| + |
| + e.g., given |
| + |
| + '$CHROMIUM_SRC/foo/bar/baz.txt' |
| + |
| + this would return |
| + |
| + [None, 'foo', 'bar', 'baz.txt'] |
| + |
| + This handles a couple classes of paths differently than it otherwise would: |
| + - All .pak files get mapped to top-level paks/ |
| + - Anything in the output directory gets mapped relative to the output |
| + directory rather than the source directory. |
| + |
| + e.g. given |
| + |
| + '$CHROMIUM_SRC/out/Release/icu_fake_dir/icudtl.dat' |
| + |
| + this would return |
| + |
| + [None, 'icu_fake_dir', 'icudtl.dat'] |
| + |
| + Args: |
| + host_path: The absolute path to the host file. |
| + Returns: |
| + A list of device path components. |
| + """ |
| + if os.path.commonprefix([output_directory, host_path]) == output_directory: |
|
agrieve
2016/11/15 15:51:01
commonprefix just does string comparison. So.. I t
jbudorick
2016/11/15 19:33:15
Done.
|
| + if os.path.splitext(host_path)[1] == '.pak': |
| + return [None, 'paks', os.path.basename(host_path)] |
| + rel_host_path = os.path.relpath(host_path, output_directory) |
| + else: |
| + rel_host_path = os.path.relpath(host_path, constants.DIR_SOURCE_ROOT) |
| + |
| + device_path_components = [None] |
| + p = rel_host_path |
| + while p: |
| + p, d = os.path.split(p) |
| + if d: |
| + device_path_components.insert(1, d) |
| + return device_path_components |
| + |
| + |
| +def GetDataDependencies(isolate_file_path): |
| + """Returns a list of device data dependencies. |
| + |
| + Args: |
| + isolate_file_path: A str path to the isolate file. |
| + Returns: |
| + A list of (host_path, device_path) tuples. |
| + """ |
| + if not isolate_file_path: |
| + return [] |
| + |
| + with open(isolate_file_path, 'r') as isolate_file: |
| + isolate_contents = ast.literal_eval(isolate_file.read()) |
| + |
| + isolate_file_dir = os.path.dirname(isolate_file_path) |
| + rel_host_files = isolate_contents.get('variables', {}).get('files', []) |
| + abs_host_files = [ |
| + os.path.abspath(os.path.join(isolate_file_dir, r)) |
| + for r in rel_host_files] |
| + |
| + return [(a, DevicePathComponentsFor(a, constants.GetOutDirectory())) |
| + for a in abs_host_files] |
| + |