OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright 2014 The Chromium Authors. All rights reserved. | 2 # Copyright 2014 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """Adaptor script called through build/isolate.gypi. | 6 """Adaptor script called through build/isolate.gypi. |
7 | 7 |
8 Creates a wrapping .isolate which 'includes' the original one, that can be | 8 Creates a wrapping .isolate which 'includes' the original one, that can be |
9 consumed by tools/swarming_client/isolate.py. Path variables are determined | 9 consumed by tools/swarming_client/isolate.py. Path variables are determined |
10 based on the current working directory. The relative_cwd in the .isolated file | 10 based on the current working directory. The relative_cwd in the .isolated file |
11 is determined based on the .isolate file that declare the 'command' variable to | 11 is determined based on the .isolate file that declare the 'command' variable to |
12 be used so the wrapping .isolate doesn't affect this value. | 12 be used so the wrapping .isolate doesn't affect this value. |
13 | 13 |
14 This script loads build.ninja and processes it to determine all the executables | 14 This script loads build.ninja and processes it to determine all the executables |
15 referenced by the isolated target. It adds them in the wrapping .isolate file. | 15 referenced by the isolated target. It adds them in the wrapping .isolate file. |
16 | 16 |
17 WARNING: The target to use for build.ninja analysis is the base name of the | 17 WARNING: The target to use for build.ninja analysis is the base name of the |
18 .isolate file plus '_run'. For example, 'foo_test.isolate' would have the target | 18 .isolate file plus '_run'. For example, 'foo_test.isolate' would have the target |
19 'foo_test_run' analysed. | 19 'foo_test_run' analysed. |
20 """ | 20 """ |
21 | 21 |
22 import StringIO | |
23 import glob | 22 import glob |
| 23 import json |
24 import logging | 24 import logging |
25 import os | 25 import os |
26 import posixpath | 26 import posixpath |
| 27 import StringIO |
27 import subprocess | 28 import subprocess |
28 import sys | 29 import sys |
29 import time | 30 import time |
30 | 31 |
31 TOOLS_DIR = os.path.dirname(os.path.abspath(__file__)) | 32 TOOLS_DIR = os.path.dirname(os.path.abspath(__file__)) |
32 SWARMING_CLIENT_DIR = os.path.join(TOOLS_DIR, 'swarming_client') | 33 SWARMING_CLIENT_DIR = os.path.join(TOOLS_DIR, 'swarming_client') |
33 SRC_DIR = os.path.dirname(TOOLS_DIR) | 34 SRC_DIR = os.path.dirname(TOOLS_DIR) |
34 | 35 |
35 sys.path.insert(0, SWARMING_CLIENT_DIR) | 36 sys.path.insert(0, SWARMING_CLIENT_DIR) |
36 | 37 |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 out = StringIO.StringIO() | 242 out = StringIO.StringIO() |
242 isolate_format.print_all(comment, isolate_dict, out) | 243 isolate_format.print_all(comment, isolate_dict, out) |
243 isolate_content = out.getvalue() | 244 isolate_content = out.getvalue() |
244 with open(temp_isolate, 'wb') as f: | 245 with open(temp_isolate, 'wb') as f: |
245 f.write(isolate_content) | 246 f.write(isolate_content) |
246 logging.info('Added %d dynamic libs', len(binary_deps)) | 247 logging.info('Added %d dynamic libs', len(binary_deps)) |
247 logging.debug('%s', isolate_content) | 248 logging.debug('%s', isolate_content) |
248 args[isolate_index] = temp_isolate | 249 args[isolate_index] = temp_isolate |
249 | 250 |
250 | 251 |
| 252 def prepare_isolate_call(args, output): |
| 253 """Gathers all information required to run isolate.py later. |
| 254 |
| 255 Dumps it as JSON to |output| file. |
| 256 """ |
| 257 with open(output, 'wb') as f: |
| 258 json.dump({ |
| 259 'args': args, |
| 260 'dir': os.getcwd(), |
| 261 'version': 1, |
| 262 }, f, indent=2, sort_keys=True) |
| 263 |
| 264 |
251 def main(): | 265 def main(): |
252 logging.basicConfig(level=logging.ERROR, format='%(levelname)7s %(message)s') | 266 logging.basicConfig(level=logging.ERROR, format='%(levelname)7s %(message)s') |
253 args = sys.argv[1:] | 267 args = sys.argv[1:] |
| 268 mode = args[0] if args else None |
254 isolate = None | 269 isolate = None |
255 isolated = None | 270 isolated = None |
256 is_component = False | 271 is_component = False |
257 for i, arg in enumerate(args): | 272 for i, arg in enumerate(args): |
258 if arg == '--isolate': | 273 if arg == '--isolate': |
259 isolate = i + 1 | 274 isolate = i + 1 |
260 if arg == '--isolated': | 275 if arg == '--isolated': |
261 isolated = i + 1 | 276 isolated = i + 1 |
262 if arg == 'component=shared_library': | 277 if arg == 'component=shared_library': |
263 is_component = True | 278 is_component = True |
264 if isolate is None or isolated is None: | 279 if isolate is None or isolated is None or not mode: |
265 print >> sys.stderr, 'Internal failure' | 280 print >> sys.stderr, 'Internal failure' |
266 return 1 | 281 return 1 |
267 | 282 |
268 if is_component: | 283 if is_component: |
269 create_wrapper(args, isolate, isolated) | 284 create_wrapper(args, isolate, isolated) |
270 | 285 |
| 286 # In 'prepare' mode just collect all required information for postponed |
| 287 # isolated.py invocation later, store it in *.isolated.gen.json file. |
| 288 if mode == 'prepare': |
| 289 prepare_isolate_call(args[1:], args[isolated] + '.gen.json') |
| 290 return 0 |
| 291 |
271 swarming_client = os.path.join(SRC_DIR, 'tools', 'swarming_client') | 292 swarming_client = os.path.join(SRC_DIR, 'tools', 'swarming_client') |
272 sys.stdout.flush() | 293 sys.stdout.flush() |
273 result = subprocess.call( | 294 result = subprocess.call( |
274 [sys.executable, os.path.join(swarming_client, 'isolate.py')] + args) | 295 [sys.executable, os.path.join(swarming_client, 'isolate.py')] + args) |
275 return result | 296 return result |
276 | 297 |
277 | 298 |
278 if __name__ == '__main__': | 299 if __name__ == '__main__': |
279 sys.exit(main()) | 300 sys.exit(main()) |
OLD | NEW |