Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 #!/usr/bin/env python | |
| 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 | |
| 4 # found in the LICENSE file. | |
| 5 | |
| 6 """Adaptor script called through build/isolate.gypi. | |
| 7 | |
| 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 | |
| 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 | |
| 12 be used* so the wrapping .isolate doesn't affect this value. | |
| 13 | |
| 14 It packages all the dynamic libraries found in this wrapping .isolate. This is | |
| 15 inefficient and non-deterministic. In the very near future, it will parse | |
| 16 build.ninja, find back the root target and find all the dynamic libraries that | |
| 17 are marked as a dependency to this target. | |
| 18 """ | |
| 19 | |
| 20 import glob | |
| 21 import os | |
| 22 import posixpath | |
| 23 import subprocess | |
| 24 import sys | |
| 25 | |
| 26 TOOLS_DIR = os.path.dirname(os.path.abspath(__file__)) | |
| 27 SWARMING_CLIENT_DIR = os.path.join(TOOLS_DIR, 'swarming_client') | |
| 28 | |
| 29 sys.path.insert(0, SWARMING_CLIENT_DIR) | |
| 30 | |
| 31 import isolate_format | |
| 32 | |
| 33 | |
| 34 SRC_DIR = os.path.dirname(TOOLS_DIR) | |
|
Vadim Sh.
2014/03/31 18:21:53
minor nit: move this right after SWARMING_CLIENT_D
M-A Ruel
2014/04/04 00:35:18
Done.
| |
| 35 | |
| 36 | |
| 37 # Location to grab binaries based on the OS. | |
| 38 DYNAMIC_LIBRARIES = { | |
| 39 'darwin': '*.dylib', | |
| 40 'linux2': 'lib/*.so', | |
| 41 'win32': '*.dll', | |
| 42 } | |
| 43 | |
| 44 | |
| 45 def create_wrapper(args, isolate_index, isolated_index): | |
| 46 """Creates a wrapper .isolate that add dynamic libs. | |
| 47 | |
| 48 The original .isolate is not modified. | |
| 49 """ | |
| 50 cwd = os.getcwd() | |
| 51 isolate = args[isolate_index] | |
| 52 # The code assumes the .isolate file is always specified path-less in cwd. Fix | |
| 53 # if this assumption doesn't hold true. | |
| 54 assert os.path.basename(isolate) == isolate, isolate | |
| 55 | |
| 56 # This will look like ../out/Debug. This is based against cwd. Note that this | |
| 57 # must equal the value provided as PRODUCT_DIR. | |
| 58 build_dir = os.path.dirname(args[isolated_index]) | |
| 59 | |
| 60 # This will look like chrome/unit_tests.isolate. It is based against SRC_DIR. | |
| 61 # It's used to calculate temp_isolate. | |
| 62 src_isolate = os.path.relpath(os.path.join(cwd, isolate), SRC_DIR) | |
| 63 | |
| 64 # The wrapping .isolate. This will look like | |
| 65 # ../out/Debug/gen/chrome/unit_tests.isolate. | |
| 66 temp_isolate = os.path.join(build_dir, 'gen', src_isolate) | |
| 67 temp_isolate_dir = os.path.dirname(temp_isolate) | |
| 68 | |
| 69 # Relative path between the new and old .isolate file. | |
| 70 isolate_relpath = os.path.relpath( | |
| 71 '.', temp_isolate_dir).replace(os.path.sep, '/') | |
| 72 | |
| 73 # This will look like [../out/Debug/lib/libuser_prefs.so]. | |
| 74 dynamic_libs = [ | |
| 75 i.replace(os.path.sep, '/') | |
| 76 for i in glob.iglob( | |
| 77 os.path.join(build_dir, DYNAMIC_LIBRARIES[sys.platform])) | |
| 78 ] | |
| 79 # And now like ['<(PRODUCT_DIR)/lib/flibuser_prefs.so']. | |
| 80 rebased_libs = [ | |
| 81 '<(PRODUCT_DIR)/%s' % i[len(build_dir)+1:] | |
| 82 for i in dynamic_libs | |
| 83 ] | |
| 84 | |
| 85 # Now do actual wrapping .isolate. | |
| 86 out = { | |
| 87 'includes': [ | |
| 88 posixpath.join(isolate_relpath, isolate), | |
| 89 ], | |
| 90 'variables': { | |
| 91 isolate_format.KEY_TRACKED: rebased_libs, | |
| 92 }, | |
| 93 } | |
| 94 if not os.path.isdir(temp_isolate_dir): | |
| 95 os.makedirs(temp_isolate_dir) | |
| 96 comment = ( | |
| 97 '# Warning: this file was AUTOGENERATED.\n' | |
| 98 '# DO NO EDIT.\n') | |
| 99 with open(temp_isolate, 'wb') as f: | |
| 100 isolate_format.print_all(comment, out, f) | |
| 101 if '--verbose' in args: | |
| 102 print('Added %d dynamic libs' % len(dynamic_libs)) | |
| 103 args[isolate_index] = temp_isolate | |
| 104 | |
| 105 | |
| 106 def main(): | |
| 107 args = sys.argv[1:] | |
| 108 print ' '.join(sys.argv) | |
|
Vadim Sh.
2014/03/31 18:21:53
Is it helpful?
M-A Ruel
2014/04/04 00:35:18
No, I had forgot it from debugging.
| |
| 109 isolate = None | |
| 110 isolated = None | |
| 111 is_component = False | |
| 112 for i, arg in enumerate(args): | |
| 113 if arg == '--isolate': | |
| 114 isolate = i + 1 | |
| 115 if arg == '--isolated': | |
| 116 isolated = i + 1 | |
| 117 if arg == 'component=shared_library': | |
| 118 is_component = True | |
| 119 if isolate is None or isolated is None: | |
| 120 print >> sys.stderr, 'Internal failure' | |
| 121 return 1 | |
| 122 | |
| 123 if is_component: | |
| 124 create_wrapper(args, isolate, isolated) | |
| 125 | |
| 126 swarming_client = os.path.join(SRC_DIR, 'tools', 'swarming_client') | |
| 127 sys.stdout.flush() | |
| 128 result = subprocess.call( | |
| 129 [sys.executable, os.path.join(swarming_client, 'isolate.py')] + args) | |
| 130 return result | |
| 131 | |
| 132 | |
| 133 if __name__ == '__main__': | |
| 134 sys.exit(main()) | |
| OLD | NEW |