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

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

Issue 2101243005: Add a snapshot of flutter/engine/src/build to our sdk (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: add README.dart Created 4 years, 5 months 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 # Note: This list must match the --config-vars in build/isolate.gypi
28 return {
29 'CONFIGURATION_NAME': constants.GetBuildType(),
30 'OS': 'android',
31 'asan': '0',
32 'branding': 'Chromium',
33 'chromeos': '0',
34 'component': 'static_library',
35 'enable_pepper_cdms': '0',
36 'enable_plugins': '0',
37 'fastbuild': '0',
38 'icu_use_data_file_flag': '1',
39 'kasko': '0',
40 'lsan': '0',
41 'msan': '0',
42 # TODO(maruel): This may not always be true.
43 'target_arch': 'arm',
44 'tsan': '0',
45 'use_custom_libcxx': '0',
46 'use_instrumented_libraries': '0',
47 'use_prebuilt_instrumented_libraries': '0',
48 'use_openssl': '0',
49 'use_ozone': '0',
50 'use_x11': '0',
51 'v8_use_external_startup_data': '1',
52 }
53
54
55 class Isolator(object):
56 """Manages calls to isolate.py for the android test runner scripts."""
57
58 def __init__(self, isolate_deps_dir):
59 """
60 Args:
61 isolate_deps_dir: The directory in which dependencies specified by
62 isolate are or should be stored.
63 """
64 self._isolate_deps_dir = isolate_deps_dir
65
66 def Clear(self):
67 """Deletes the isolate dependency directory."""
68 if os.path.exists(self._isolate_deps_dir):
69 shutil.rmtree(self._isolate_deps_dir)
70
71 def Remap(self, isolate_abs_path, isolated_abs_path,
72 path_variables=None, config_variables=None):
73 """Remaps data dependencies into |self._isolate_deps_dir|.
74
75 Args:
76 isolate_abs_path: The absolute path to the .isolate file, which specifies
77 data dependencies in the source tree.
78 isolated_abs_path: The absolute path to the .isolated file, which is
79 generated by isolate.py and specifies data dependencies in
80 |self._isolate_deps_dir| and their digests.
81 path_variables: A dict containing everything that should be passed
82 as a |--path-variable| to the isolate script. Defaults to the return
83 value of |DefaultPathVariables()|.
84 config_variables: A dict containing everything that should be passed
85 as a |--config-variable| to the isolate script. Defaults to the return
86 value of |DefaultConfigVariables()|.
87 Raises:
88 Exception if the isolate command fails for some reason.
89 """
90 if not path_variables:
91 path_variables = DefaultPathVariables()
92 if not config_variables:
93 config_variables = DefaultConfigVariables()
94
95 isolate_cmd = [
96 sys.executable, _ISOLATE_SCRIPT, 'remap',
97 '--isolate', isolate_abs_path,
98 '--isolated', isolated_abs_path,
99 '--outdir', self._isolate_deps_dir,
100 ]
101 for k, v in path_variables.iteritems():
102 isolate_cmd.extend(['--path-variable', k, v])
103 for k, v in config_variables.iteritems():
104 isolate_cmd.extend(['--config-variable', k, v])
105
106 if cmd_helper.RunCmd(isolate_cmd):
107 raise Exception('isolate command failed: %s' % ' '.join(isolate_cmd))
108
109 def VerifyHardlinks(self):
110 """Checks |isolate_deps_dir| for a hardlink.
111
112 Returns:
113 True if a hardlink is found.
114 False if nothing is found.
115 Raises:
116 Exception if a non-hardlink is found.
117 """
118 for root, _, filenames in os.walk(self._isolate_deps_dir):
119 if filenames:
120 linked_file = os.path.join(root, filenames[0])
121 orig_file = os.path.join(
122 self._isolate_deps_dir,
123 os.path.relpath(linked_file, self._isolate_deps_dir))
124 if os.stat(linked_file).st_ino == os.stat(orig_file).st_ino:
125 return True
126 else:
127 raise Exception('isolate remap command did not use hardlinks.')
128 return False
129
130 def PurgeExcluded(self, deps_exclusion_list):
131 """Deletes anything on |deps_exclusion_list| from |self._isolate_deps_dir|.
132
133 Args:
134 deps_exclusion_list: A list of globs to exclude from the isolate
135 dependency directory.
136 """
137 excluded_paths = (
138 x for y in deps_exclusion_list
139 for x in glob.glob(
140 os.path.abspath(os.path.join(self._isolate_deps_dir, y))))
141 for p in excluded_paths:
142 if os.path.isdir(p):
143 shutil.rmtree(p)
144 else:
145 os.remove(p)
146
147 def MoveOutputDeps(self):
148 """Moves files from the output directory to the top level of
149 |self._isolate_deps_dir|.
150
151 Moves pak files from the output directory to to <isolate_deps_dir>/paks
152 Moves files from the product directory to <isolate_deps_dir>
153 """
154 # On Android, all pak files need to be in the top-level 'paks' directory.
155 paks_dir = os.path.join(self._isolate_deps_dir, 'paks')
156 os.mkdir(paks_dir)
157
158 deps_out_dir = os.path.join(
159 self._isolate_deps_dir,
160 os.path.relpath(os.path.join(constants.GetOutDirectory(), os.pardir),
161 constants.DIR_SOURCE_ROOT))
162 for root, _, filenames in os.walk(deps_out_dir):
163 for filename in fnmatch.filter(filenames, '*.pak'):
164 shutil.move(os.path.join(root, filename), paks_dir)
165
166 # Move everything in PRODUCT_DIR to top level.
167 deps_product_dir = os.path.join(deps_out_dir, constants.GetBuildType())
168 if os.path.isdir(deps_product_dir):
169 for p in os.listdir(deps_product_dir):
170 shutil.move(os.path.join(deps_product_dir, p), self._isolate_deps_dir)
171 os.rmdir(deps_product_dir)
172 os.rmdir(deps_out_dir)
173
OLDNEW
« no previous file with comments | « build/android/pylib/utils/host_utils.py ('k') | build/android/pylib/utils/json_results_generator_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698