OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright 2015 the V8 project authors. All rights reserved. | 2 # Copyright 2015 the V8 project 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 Slimmed down version of chromium's isolate driver that doesn't process dynamic | 8 Slimmed down version of chromium's isolate driver that doesn't process dynamic |
9 dependencies. | 9 dependencies. |
10 """ | 10 """ |
(...skipping 12 matching lines...) Expand all Loading... |
23 | 23 |
24 Dumps it as JSON to |output| file. | 24 Dumps it as JSON to |output| file. |
25 """ | 25 """ |
26 with open(output, 'wb') as f: | 26 with open(output, 'wb') as f: |
27 json.dump({ | 27 json.dump({ |
28 'args': args, | 28 'args': args, |
29 'dir': os.getcwd(), | 29 'dir': os.getcwd(), |
30 'version': 1, | 30 'version': 1, |
31 }, f, indent=2, sort_keys=True) | 31 }, f, indent=2, sort_keys=True) |
32 | 32 |
| 33 def rebase_directories(args, abs_base): |
| 34 """Rebases all paths to be relative to abs_base.""" |
| 35 def replace(index): |
| 36 args[index] = os.path.relpath(os.path.abspath(args[index]), abs_base) |
| 37 for i, arg in enumerate(args): |
| 38 if arg in ['--isolate', '--isolated']: |
| 39 replace(i + 1) |
| 40 if arg == '--path-variable': |
| 41 # Path variables have a triple form: --path-variable NAME <path>. |
| 42 replace(i + 2) |
33 | 43 |
34 def main(): | 44 def main(): |
35 logging.basicConfig(level=logging.ERROR, format='%(levelname)7s %(message)s') | 45 logging.basicConfig(level=logging.ERROR, format='%(levelname)7s %(message)s') |
36 if len(sys.argv) < 2: | 46 if len(sys.argv) < 2: |
37 print >> sys.stderr, 'Internal failure; mode required' | 47 print >> sys.stderr, 'Internal failure; mode required' |
38 return 1 | 48 return 1 |
39 mode = sys.argv[1] | 49 mode = sys.argv[1] |
40 args = sys.argv[1:] | 50 args = sys.argv[1:] |
41 isolate = None | 51 isolate = None |
42 isolated = None | 52 isolated = None |
43 for i, arg in enumerate(args): | 53 for i, arg in enumerate(args): |
44 if arg == '--isolate': | 54 if arg == '--isolate': |
45 isolate = i + 1 | 55 isolate = i + 1 |
46 if arg == '--isolated': | 56 if arg == '--isolated': |
47 isolated = i + 1 | 57 isolated = i + 1 |
48 if not isolate or not isolated: | 58 if not isolate or not isolated: |
49 print >> sys.stderr, 'Internal failure' | 59 print >> sys.stderr, 'Internal failure' |
50 return 1 | 60 return 1 |
51 | 61 |
| 62 # Make sure all paths are relative to the isolate file. This is an |
| 63 # expectation of the go binaries. In gn, this script is not called |
| 64 # relative to the isolate file, but relative to the product dir. |
| 65 new_base = os.path.abspath(os.path.dirname(args[isolate])) |
| 66 rebase_directories(args, new_base) |
| 67 assert args[isolate] == os.path.basename(args[isolate]) |
| 68 os.chdir(new_base) |
| 69 |
52 # In 'prepare' mode just collect all required information for postponed | 70 # In 'prepare' mode just collect all required information for postponed |
53 # isolated.py invocation later, store it in *.isolated.gen.json file. | 71 # isolated.py invocation later, store it in *.isolated.gen.json file. |
54 if mode == 'prepare': | 72 if mode == 'prepare': |
55 prepare_isolate_call(args[1:], args[isolated] + '.gen.json') | 73 prepare_isolate_call(args[1:], args[isolated] + '.gen.json') |
56 return 0 | 74 return 0 |
57 | 75 |
58 swarming_client = os.path.join(TOOLS_DIR, 'swarming_client') | 76 swarming_client = os.path.join(TOOLS_DIR, 'swarming_client') |
59 sys.stdout.flush() | 77 sys.stdout.flush() |
60 return subprocess.call( | 78 return subprocess.call( |
61 [sys.executable, os.path.join(swarming_client, 'isolate.py')] + args) | 79 [sys.executable, os.path.join(swarming_client, 'isolate.py')] + args) |
62 | 80 |
63 | 81 |
64 if __name__ == '__main__': | 82 if __name__ == '__main__': |
65 sys.exit(main()) | 83 sys.exit(main()) |
OLD | NEW |