Chromium Code Reviews| Index: tools/isolate_driver.py |
| diff --git a/tools/isolate_driver.py b/tools/isolate_driver.py |
| new file mode 100755 |
| index 0000000000000000000000000000000000000000..b07c044a25da69b74217fd052cc541aef7d35f40 |
| --- /dev/null |
| +++ b/tools/isolate_driver.py |
| @@ -0,0 +1,90 @@ |
| +#!/usr/bin/env python |
| +# Copyright 2014 The Chromium Authors. All rights reserved. |
| +# Use of this source code is governed by a BSD-style license that can be |
| +# found in the LICENSE file. |
| + |
| +"""Adaptor script called through build/isolate.gyp. |
|
Vadim Sh.
2014/03/14 01:51:35
isolate.gypi (with 'i')?
M-A Ruel
2014/03/14 12:51:56
Done.
|
| + |
| +Creates a temporary .isolate merged with the original one into a .isolate file |
| +that can be consumed by tools/swarming_client/isolate.py. |
| + |
| +For now it packages all the dynamic libraries found. This is inefficient and |
| +non-deterministic. In the very near future, it will parse build.ninja, find back |
| +the root target and find all the dynamic libraries that are marked as a |
| +dependency to this target. |
| +""" |
| + |
| +import glob |
| +import os |
| +import optparse |
| +import subprocess |
| +import sys |
| + |
| + |
| +SRC_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) |
| + |
| +DYNAMIC_LIBRARIES = { |
| + 'darwin': '*.dylib', |
| + 'linux2': 'lib/*.so', |
| + 'win32': '*.dll', |
| +} |
| + |
| + |
| +def mangle(args, isolate, isolated): |
| + # Open the .isolate, edit it, store it in the temporary directory. |
| + # All paths are relative to cwd. |
| + cwd = os.getcwd() |
|
Vadim Sh.
2014/03/14 01:51:35
What is cwd? Does ninja gives any guarantees about
M-A Ruel
2014/03/14 12:51:56
ninja guarantees the script will be called from th
Vadim Sh.
2014/03/14 18:01:38
Please add a comment describing what cwd is expect
|
| + src_isolate = os.path.relpath(os.path.join(cwd, args[isolate]), SRC_DIR) |
| + build_dir = os.path.dirname(args[isolated]) |
| + temp_isolate = os.path.join(build_dir, 'gen', src_isolate) |
| + dynamic_libs = glob.glob( |
| + os.path.join(build_dir, DYNAMIC_LIBRARIES[sys.platform])) |
| + |
| + # Mangle it. |
| + with open(args[isolate], 'rb') as f: |
| + isolate_content = f.read() |
| + isolate_content = isolate_content.strip()[:-1] |
| + isolate_content += ( |
|
Vadim Sh.
2014/03/14 01:51:35
that's is very hacky... why not exec it, modify as
M-A Ruel
2014/03/14 12:51:56
There's a few options;
1. Hack the way it's curren
Vadim Sh.
2014/03/14 18:01:38
I think #1 is more fragile than #2. It's a big rel
|
| + " 'variables': {\n" |
| + " 'isolate_tracked': [\n" |
| + "%s" |
| + " ],\n" |
| + " },\n" |
| + "}\n") % ''.join(' %s,\n' % repr(d) for d in dynamic_libs) |
| + gen_dir = os.path.dirname(temp_isolate) |
| + if not os.path.isdir(gen_dir): |
| + os.makedirs(gen_dir) |
| + with open(temp_isolate, 'wb') as f: |
| + f.write(isolate_content) |
| + |
| + print('Added %d dynamic libs' % len(dynamic_libs)) |
| + args[isolate] = temp_isolate |
| + |
| + |
| +def main(): |
| + args = sys.argv[1:] |
| + isolate = None |
| + isolated = None |
| + is_component = False |
| + for i, arg in enumerate(args): |
|
Vadim Sh.
2014/03/14 01:51:35
why not optparse? It's even imported.
M-A Ruel
2014/03/14 12:51:56
Yeah I thought about using it first and proxying a
Vadim Sh.
2014/03/14 18:01:38
Yeah, makes sense.
|
| + if arg == '--isolate': |
| + isolate = i + 1 |
| + if arg == '--isolated': |
| + isolated = i + 1 |
| + if arg == 'component=shared_library': |
| + is_component = True |
| + if isolate is None or isolated is None: |
| + print >> sys.stderr, 'Internal failure' |
| + return 1 |
| + |
| + if is_component: |
| + mangle(args, isolate, isolated) |
| + |
| + swarming_client = os.path.join(SRC_DIR, 'tools', 'swarming_client') |
| + return subprocess.call( |
| + [sys.executable, os.path.join(swarming_client, 'isolate.py')] + |
| + sys.argv[1:]) |
| + |
| + |
| +if __name__ == '__main__': |
| + sys.exit(main()) |