| 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 glob | 22 import glob |
| 23 import json | 23 import json |
| 24 import logging | 24 import logging |
| 25 import os | 25 import os |
| 26 import posixpath | 26 import posixpath |
| 27 import re | |
| 28 import StringIO | 27 import StringIO |
| 29 import subprocess | 28 import subprocess |
| 30 import sys | 29 import sys |
| 31 import time | 30 import time |
| 32 | 31 |
| 33 TOOLS_DIR = os.path.dirname(os.path.abspath(__file__)) | 32 TOOLS_DIR = os.path.dirname(os.path.abspath(__file__)) |
| 34 SWARMING_CLIENT_DIR = os.path.join(TOOLS_DIR, 'swarming_client') | 33 SWARMING_CLIENT_DIR = os.path.join(TOOLS_DIR, 'swarming_client') |
| 35 SRC_DIR = os.path.dirname(TOOLS_DIR) | 34 SRC_DIR = os.path.dirname(TOOLS_DIR) |
| 36 | 35 |
| 37 sys.path.insert(0, SWARMING_CLIENT_DIR) | 36 sys.path.insert(0, SWARMING_CLIENT_DIR) |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 return item not in ('', '|', '||') | 134 return item not in ('', '|', '||') |
| 136 | 135 |
| 137 | 136 |
| 138 def raw_build_to_deps(item): | 137 def raw_build_to_deps(item): |
| 139 """Converts a raw ninja build statement into the list of interesting | 138 """Converts a raw ninja build statement into the list of interesting |
| 140 dependencies. | 139 dependencies. |
| 141 """ | 140 """ |
| 142 # TODO(maruel): Use a whitelist instead? .stamp, .so.TOC, .dylib.TOC, | 141 # TODO(maruel): Use a whitelist instead? .stamp, .so.TOC, .dylib.TOC, |
| 143 # .dll.lib, .exe and empty. | 142 # .dll.lib, .exe and empty. |
| 144 # The first item is the build rule, e.g. 'link', 'cxx', 'phony', etc. | 143 # The first item is the build rule, e.g. 'link', 'cxx', 'phony', etc. |
| 145 # In ninja build files, spaces in targets are escaped with a $-prefix. | 144 return filter(using_blacklist, item.split(' ')[1:]) |
| 146 # Use a negative lookbehind to not split on '$ '. | |
| 147 return filter(using_blacklist, re.split('(?<!\$) ', item)[1:]) | |
| 148 | 145 |
| 149 | 146 |
| 150 def collect_deps(target, build_steps, dependencies_added, rules_seen): | 147 def collect_deps(target, build_steps, dependencies_added, rules_seen): |
| 151 """Recursively adds all the interesting dependencies for |target| | 148 """Recursively adds all the interesting dependencies for |target| |
| 152 into |dependencies_added|. | 149 into |dependencies_added|. |
| 153 """ | 150 """ |
| 154 if rules_seen is None: | 151 if rules_seen is None: |
| 155 rules_seen = set() | 152 rules_seen = set() |
| 156 if target in rules_seen: | 153 if target in rules_seen: |
| 157 # TODO(maruel): Figure out how it happens. | 154 # TODO(maruel): Figure out how it happens. |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 306 | 303 |
| 307 swarming_client = os.path.join(SRC_DIR, 'tools', 'swarming_client') | 304 swarming_client = os.path.join(SRC_DIR, 'tools', 'swarming_client') |
| 308 sys.stdout.flush() | 305 sys.stdout.flush() |
| 309 result = subprocess.call( | 306 result = subprocess.call( |
| 310 [sys.executable, os.path.join(swarming_client, 'isolate.py')] + args) | 307 [sys.executable, os.path.join(swarming_client, 'isolate.py')] + args) |
| 311 return result | 308 return result |
| 312 | 309 |
| 313 | 310 |
| 314 if __name__ == '__main__': | 311 if __name__ == '__main__': |
| 315 sys.exit(main()) | 312 sys.exit(main()) |
| OLD | NEW |