Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(485)

Side by Side Diff: build/android/pylib/utils/isolator.py

Issue 683113005: Update from chromium https://crrev.com/302282 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 # Copyright 2014 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 fnmatch
6 import glob
7 import os
8 import shutil
9 import sys
10
11 from pylib import cmd_helper
12 from pylib import constants
13
14
15 _ISOLATE_SCRIPT = os.path.join(
16 constants.DIR_SOURCE_ROOT, 'tools', 'swarming_client', 'isolate.py')
17
18
19 def DefaultPathVariables():
20 return {
21 'DEPTH': constants.DIR_SOURCE_ROOT,
22 'PRODUCT_DIR': constants.GetOutDirectory(),
23 }
24
25
26 def DefaultConfigVariables():
27 return {
28 'CONFIGURATION_NAME': constants.GetBuildType(),
29 'OS': 'android',
30 'asan': '0',
31 'chromeos': '0',
32 'component': 'static_library',
33 'fastbuild': '0',
34 'icu_use_data_file_flag': '1',
35 'libpeer_target_type': 'static_library',
36 'lsan': '0',
37 # TODO(maruel): This may not always be true.
38 'target_arch': 'arm',
39 'use_openssl': '0',
40 'use_ozone': '0',
41 'v8_use_external_startup_data': '0',
42 }
43
44
45 class Isolator(object):
46 """Manages calls to isolate.py for the android test runner scripts."""
47
48 def __init__(self, isolate_deps_dir):
49 """
50 Args:
51 isolate_deps_dir: The directory in which dependencies specified by
52 isolate are or should be stored.
53 """
54 self._isolate_deps_dir = isolate_deps_dir
55
56 def Clear(self):
57 """Deletes the isolate dependency directory."""
58 if os.path.exists(self._isolate_deps_dir):
59 shutil.rmtree(self._isolate_deps_dir)
60
61 def Remap(self, isolate_abs_path, isolated_abs_path,
62 path_variables=None, config_variables=None):
63 """Remaps data dependencies into |self._isolate_deps_dir|.
64
65 Args:
66 isolate_abs_path: The absolute path to the .isolate file, which specifies
67 data dependencies in the source tree.
68 isolated_abs_path: The absolute path to the .isolated file, which is
69 generated by isolate.py and specifies data dependencies in
70 |self._isolate_deps_dir| and their digests.
71 path_variables: A dict containing everything that should be passed
72 as a |--path-variable| to the isolate script. Defaults to the return
73 value of |DefaultPathVariables()|.
74 config_variables: A dict containing everything that should be passed
75 as a |--config-variable| to the isolate script. Defaults to the return
76 value of |DefaultConfigVariables()|.
77 Raises:
78 Exception if the isolate command fails for some reason.
79 """
80 if not path_variables:
81 path_variables = DefaultPathVariables()
82 if not config_variables:
83 config_variables = DefaultConfigVariables()
84
85 isolate_cmd = [
86 sys.executable, _ISOLATE_SCRIPT, 'remap',
87 '--isolate', isolate_abs_path,
88 '--isolated', isolated_abs_path,
89 '--outdir', self._isolate_deps_dir,
90 ]
91 for k, v in path_variables.iteritems():
92 isolate_cmd.extend(['--path-variable', k, v])
93 for k, v in config_variables.iteritems():
94 isolate_cmd.extend(['--config-variable', k, v])
95
96 if cmd_helper.RunCmd(isolate_cmd):
97 raise Exception('isolate command failed: %s' % ' '.join(isolate_cmd))
98
99 def VerifyHardlinks(self):
100 """Checks |isolate_deps_dir| for a hardlink.
101
102 Returns:
103 True if a hardlink is found.
104 False if nothing is found.
105 Raises:
106 Exception if a non-hardlink is found.
107 """
108 for root, _, filenames in os.walk(self._isolate_deps_dir):
109 if filenames:
110 linked_file = os.path.join(root, filenames[0])
111 orig_file = os.path.join(
112 self._isolate_deps_dir,
113 os.path.relpath(linked_file, self._isolate_deps_dir))
114 if os.stat(linked_file).st_ino == os.stat(orig_file).st_ino:
115 return True
116 else:
117 raise Exception('isolate remap command did not use hardlinks.')
118 return False
119
120 def PurgeExcluded(self, deps_exclusion_list):
121 """Deletes anything on |deps_exclusion_list| from |self._isolate_deps_dir|.
122
123 Args:
124 deps_exclusion_list: A list of globs to exclude from the isolate
125 dependency directory.
126 """
127 excluded_paths = (
128 x for y in deps_exclusion_list
129 for x in glob.glob(
130 os.path.abspath(os.path.join(self._isolate_deps_dir, y))))
131 for p in excluded_paths:
132 if os.path.isdir(p):
133 shutil.rmtree(p)
134 else:
135 os.remove(p)
136
137 def MoveOutputDeps(self):
138 """Moves files from the output directory to the top level of
139 |self._isolate_deps_dir|.
140
141 Moves pak files from the output directory to to <isolate_deps_dir>/paks
142 Moves files from the product directory to <isolate_deps_dir>
143 """
144 # On Android, all pak files need to be in the top-level 'paks' directory.
145 paks_dir = os.path.join(self._isolate_deps_dir, 'paks')
146 os.mkdir(paks_dir)
147
148 deps_out_dir = os.path.join(
149 self._isolate_deps_dir,
150 os.path.relpath(os.path.join(constants.GetOutDirectory(), os.pardir),
151 constants.DIR_SOURCE_ROOT))
152 for root, _, filenames in os.walk(deps_out_dir):
153 for filename in fnmatch.filter(filenames, '*.pak'):
154 shutil.move(os.path.join(root, filename), paks_dir)
155
156 # Move everything in PRODUCT_DIR to top level.
157 deps_product_dir = os.path.join(deps_out_dir, constants.GetBuildType())
158 if os.path.isdir(deps_product_dir):
159 for p in os.listdir(deps_product_dir):
160 shutil.move(os.path.join(deps_product_dir, p), self._isolate_deps_dir)
161 os.rmdir(deps_product_dir)
162 os.rmdir(deps_out_dir)
163
OLDNEW
« no previous file with comments | « build/android/pylib/gtest/test_package_exe.py ('k') | build/android/pylib/utils/reraiser_thread.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698