File: device_dependencies.py

package info (click to toggle)
chromium-browser 57.0.2987.98-1~deb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 2,637,852 kB
  • ctags: 2,544,394
  • sloc: cpp: 12,815,961; ansic: 3,676,222; python: 1,147,112; asm: 526,608; java: 523,212; xml: 286,794; perl: 92,654; sh: 86,408; objc: 73,271; makefile: 27,698; cs: 18,487; yacc: 13,031; tcl: 12,957; pascal: 4,875; ml: 4,716; lex: 3,904; sql: 3,862; ruby: 1,982; lisp: 1,508; php: 1,368; exp: 404; awk: 325; csh: 117; jsp: 39; sed: 37
file content (104 lines) | stat: -rw-r--r-- 3,141 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# 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 os
import re

from pylib import constants


_BLACKLIST = [
  re.compile(r'.*OWNERS'),  # Should never be included.
  re.compile(r'.*\.crx'),  # Chrome extension zip files.
  re.compile(r'.*\.so'),  # Libraries packed into .apk.
  re.compile(r'.*Mojo.*manifest\.json'),  # Some source_set()s pull these in.
  re.compile(r'.*\.py'),  # Some test_support targets include python deps.

  # Some test_support targets include python deps.
  re.compile(r'.*\.mojom\.js'),

  # Chrome external extensions config file.
  re.compile(r'.*external_extensions\.json'),

  # Exists just to test the compile, not to be run.
  re.compile(r'.*jni_generator_tests'),

  # v8's blobs get packaged into APKs.
  re.compile(r'.*natives_blob.*\.bin'),
  re.compile(r'.*snapshot_blob.*\.bin'),
]


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 components,
  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 host_path.startswith(output_directory):
    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(runtime_deps_path):
  """Returns a list of device data dependencies.

  Args:
    runtime_deps_path: A str path to the .runtime_deps file.
  Returns:
    A list of (host_path, device_path) tuples.
  """
  if not runtime_deps_path:
    return []

  with open(runtime_deps_path, 'r') as runtime_deps_file:
    rel_host_files = [l.strip() for l in runtime_deps_file if l]

  output_directory = constants.GetOutDirectory()
  abs_host_files = [
      os.path.abspath(os.path.join(output_directory, r))
      for r in rel_host_files]
  filtered_abs_host_files = [
      host_file for host_file in abs_host_files
      if not any(blacklist_re.match(host_file) for blacklist_re in _BLACKLIST)]
  return [(f, DevicePathComponentsFor(f, output_directory))
          for f in filtered_abs_host_files]