Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(156)

Side by Side Diff: tools/isolate_driver.py

Issue 196283016: Add a wrapper script which modifies the .isolate on the fly. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fixes Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« base/base_unittests.isolate ('K') | « net/net_unittests.isolate ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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.gyp.
Vadim Sh. 2014/03/14 01:51:35 isolate.gypi (with 'i')?
M-A Ruel 2014/03/14 12:51:56 Done.
7
8 Creates a temporary .isolate merged with the original one into a .isolate file
9 that can be consumed by tools/swarming_client/isolate.py.
10
11 For now it packages all the dynamic libraries found. This is inefficient and
12 non-deterministic. In the very near future, it will parse build.ninja, find back
13 the root target and find all the dynamic libraries that are marked as a
14 dependency to this target.
15 """
16
17 import glob
18 import os
19 import optparse
20 import subprocess
21 import sys
22
23
24 SRC_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
25
26 DYNAMIC_LIBRARIES = {
27 'darwin': '*.dylib',
28 'linux2': 'lib/*.so',
29 'win32': '*.dll',
30 }
31
32
33 def mangle(args, isolate, isolated):
34 # Open the .isolate, edit it, store it in the temporary directory.
35 # All paths are relative to cwd.
36 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
37 src_isolate = os.path.relpath(os.path.join(cwd, args[isolate]), SRC_DIR)
38 build_dir = os.path.dirname(args[isolated])
39 temp_isolate = os.path.join(build_dir, 'gen', src_isolate)
40 dynamic_libs = glob.glob(
41 os.path.join(build_dir, DYNAMIC_LIBRARIES[sys.platform]))
42
43 # Mangle it.
44 with open(args[isolate], 'rb') as f:
45 isolate_content = f.read()
46 isolate_content = isolate_content.strip()[:-1]
47 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
48 " 'variables': {\n"
49 " 'isolate_tracked': [\n"
50 "%s"
51 " ],\n"
52 " },\n"
53 "}\n") % ''.join(' %s,\n' % repr(d) for d in dynamic_libs)
54 gen_dir = os.path.dirname(temp_isolate)
55 if not os.path.isdir(gen_dir):
56 os.makedirs(gen_dir)
57 with open(temp_isolate, 'wb') as f:
58 f.write(isolate_content)
59
60 print('Added %d dynamic libs' % len(dynamic_libs))
61 args[isolate] = temp_isolate
62
63
64 def main():
65 args = sys.argv[1:]
66 isolate = None
67 isolated = None
68 is_component = False
69 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.
70 if arg == '--isolate':
71 isolate = i + 1
72 if arg == '--isolated':
73 isolated = i + 1
74 if arg == 'component=shared_library':
75 is_component = True
76 if isolate is None or isolated is None:
77 print >> sys.stderr, 'Internal failure'
78 return 1
79
80 if is_component:
81 mangle(args, isolate, isolated)
82
83 swarming_client = os.path.join(SRC_DIR, 'tools', 'swarming_client')
84 return subprocess.call(
85 [sys.executable, os.path.join(swarming_client, 'isolate.py')] +
86 sys.argv[1:])
87
88
89 if __name__ == '__main__':
90 sys.exit(main())
OLDNEW
« base/base_unittests.isolate ('K') | « net/net_unittests.isolate ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698