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

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

Issue 690973002: [Android] Extract isolate logic from gtest setup to its own module. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.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
« no previous file with comments | « build/android/pylib/gtest/setup.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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):
klundberg 2014/10/30 21:21:41 What if _isolate_deps_dir isn't a directory? Will
jbudorick 2014/10/30 21:37:54 Survey says:
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.
67 isolated_abs_path: The absolute path to the .isolated file.
klundberg 2014/10/30 21:21:41 I read the doc for isolate/swarming and cannot dec
jbudorick 2014/10/30 21:37:54 I'm not sure the caller really needs to know what
68 path_variables: A dict containing everything that should be passed
69 as a |--path-variable| to the isolate script. Defaults to the return
70 value of |DefaultPathVariables()|.
71 config_variables: A dict containing everything that should be passed
72 as a |--config-variable| to the isolate script. Defaults to the return
73 value of |DefaultConfigVariables()|.
74 Raises:
75 Exception if the isolate command fails for some reason.
76 """
77 if not path_variables:
78 path_variables = DefaultPathVariables()
79 if not config_variables:
80 config_variables = DefaultConfigVariables()
81
82 isolate_cmd = [
83 sys.executable, _ISOLATE_SCRIPT, 'remap',
84 '--isolate', isolate_abs_path,
85 '--isolated', isolated_abs_path,
86 '--outdir', self._isolate_deps_dir,
87 ]
88 for k, v in path_variables.iteritems():
89 isolate_cmd.extend(['--path-variable', k, v])
90 for k, v in config_variables.iteritems():
91 isolate_cmd.extend(['--config-variable', k, v])
92
93 if cmd_helper.RunCmd(isolate_cmd):
94 raise Exception('isolate command failed: %s' % ' '.join(isolate_cmd))
95
96 def VerifyHardlinks(self):
97 """Checks |isolate_deps_dir| for a hardlink.
98
99 Returns:
100 True if a hardlink is found.
101 False if nothing is found.
102 Raises:
103 Exception if a non-hardlink is found.
104 """
105 for root, _, filenames in os.walk(self._isolate_deps_dir):
106 if filenames:
107 linked_file = os.path.join(root, filenames[0])
108 orig_file = os.path.join(
109 self._isolate_deps_dir,
110 os.path.relpath(linked_file, self._isolate_deps_dir))
111 if os.stat(linked_file).st_ino == os.stat(orig_file).st_ino:
112 return True
113 else:
114 raise Exception('isolate remap command did not use hardlinks.')
115 return False
116
117 def PurgeExcluded(self, deps_exclusion_list):
118 """Deletes anything on |deps_exclusion_list| from |self._isolate_deps_dir|.
119
120 Args:
121 deps_exclusion_list: A list of globs to exclude from the isolate
122 dependency directory.
123 """
124 excluded_paths = (
125 x for y in deps_exclusion_list
126 for x in glob.glob(
127 os.path.abspath(os.path.join(self._isolate_deps_dir, y))))
128 for p in excluded_paths:
129 if os.path.isdir(p):
130 shutil.rmtree(p)
131 else:
132 os.remove(p)
133
134 def MoveOutputDeps(self):
135 """Moves files from the output directory to the top level.
klundberg 2014/10/30 21:21:41 "...top level" of what?
jbudorick 2014/10/30 21:37:54 ... of self._isolate_deps_dir. I suppose I should
136
137 Moves pak files from the output directory to to <isolate_deps_dir>/paks
138 Moves files from the product directory to <isolate_deps_dir>
139 """
140 # On Android, all pak files need to be in the top-level 'paks' directory.
141 paks_dir = os.path.join(self._isolate_deps_dir, 'paks')
142 os.mkdir(paks_dir)
klundberg 2014/10/30 21:21:41 Do we have targets that don't have pak files? If s
jbudorick 2014/10/30 21:37:54 Not sure / no.
143
144 deps_out_dir = os.path.join(
145 self._isolate_deps_dir,
146 os.path.relpath(os.path.join(constants.GetOutDirectory(), os.pardir),
147 constants.DIR_SOURCE_ROOT))
148 for root, _, filenames in os.walk(deps_out_dir):
149 for filename in fnmatch.filter(filenames, '*.pak'):
150 shutil.move(os.path.join(root, filename), paks_dir)
151
152 # Move everything in PRODUCT_DIR to top level.
153 deps_product_dir = os.path.join(deps_out_dir, constants.GetBuildType())
154 if os.path.isdir(deps_product_dir):
155 for p in os.listdir(deps_product_dir):
156 shutil.move(os.path.join(deps_product_dir, p), self._isolate_deps_dir)
157 os.rmdir(deps_product_dir)
158 os.rmdir(deps_out_dir)
159
OLDNEW
« no previous file with comments | « build/android/pylib/gtest/setup.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698