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

Side by Side Diff: pylib/gyp/win_tool.py

Issue 83803003: Adds an helper class to shard mspdbsrv. (Closed) Base URL: http://gyp.googlecode.com/svn/trunk/
Patch Set: Created 7 years 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
« no previous file with comments | « no previous file | 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
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 2
3 # Copyright (c) 2012 Google Inc. All rights reserved. 3 # Copyright (c) 2012 Google Inc. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be 4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file. 5 # found in the LICENSE file.
6 6
7 """Utility functions for Windows builds. 7 """Utility functions for Windows builds.
8 8
9 These functions are executed via gyp-win-tool when using the ninja generator. 9 These functions are executed via gyp-win-tool when using the ninja generator.
10 """ 10 """
11 11
12 import os 12 import os
13 import re
13 import shutil 14 import shutil
14 import subprocess 15 import subprocess
15 import sys 16 import sys
16 17
17 BASE_DIR = os.path.dirname(os.path.abspath(__file__)) 18 BASE_DIR = os.path.dirname(os.path.abspath(__file__))
18 19
20 # A regex matching an argument corresponding to a PDB filename passed as an
21 # argument to link.exe.
22 _LINK_EXE_PDB_ARG = re.compile('/PDB:(?P<pdb>.+\.exe\.pdb)$', re.IGNORECASE)
19 23
20 def main(args): 24 def main(args):
21 executor = WinTool() 25 executor = WinTool()
22 exit_code = executor.Dispatch(args) 26 exit_code = executor.Dispatch(args)
23 if exit_code is not None: 27 if exit_code is not None:
24 sys.exit(exit_code) 28 sys.exit(exit_code)
25 29
26 30
27 class WinTool(object): 31 class WinTool(object):
28 """This class performs all the Windows tooling steps. The methods can either 32 """This class performs all the Windows tooling steps. The methods can either
29 be executed directly, or dispatched from an argument list.""" 33 be executed directly, or dispatched from an argument list."""
30 34
35 def _MaybeUseSeparateMspdbsrv(self, env, args):
36 """Allows to use a unique instance of mspdbsrv.exe for the linkers linking
37 an .exe target if GYP_USE_SEPARATE_MSPDBSRV has been set."""
38 if not os.environ.get('GYP_USE_SEPARATE_MSPDBSRV'):
39 return
40
41 if len(args) < 1:
42 raise Exception("Not enough arguments")
43
44 if args[0] != 'link.exe':
45 return
46
47 # Checks if this linker produces a PDB for an .exe target. If so use the
48 # name of this PDB to generate an endpoint name for mspdbsrv.exe.
49 endpoint_name = None
50 for arg in args:
51 m = _LINK_EXE_PDB_ARG.match(arg)
52 if m:
53 endpoint_name = '%s_%d' % (m.group('pdb'), os.getpid())
54 break
55
56 if endpoint_name is None:
57 return
58
59 # Adds the appropriate environment variable. This will be read by link.exe
60 # to know which instance of mspdbsrv.exe it should connect to (if it's
61 # not set then the default endpoint is used).
62 env['_MSPDBSRV_ENDPOINT_'] = endpoint_name
63
31 def Dispatch(self, args): 64 def Dispatch(self, args):
32 """Dispatches a string command to a method.""" 65 """Dispatches a string command to a method."""
33 if len(args) < 1: 66 if len(args) < 1:
34 raise Exception("Not enough arguments") 67 raise Exception("Not enough arguments")
35 68
36 method = "Exec%s" % self._CommandifyName(args[0]) 69 method = "Exec%s" % self._CommandifyName(args[0])
37 return getattr(self, method)(*args[1:]) 70 return getattr(self, method)(*args[1:])
38 71
39 def _CommandifyName(self, name_string): 72 def _CommandifyName(self, name_string):
40 """Transforms a tool name like recursive-mirror to RecursiveMirror.""" 73 """Transforms a tool name like recursive-mirror to RecursiveMirror."""
(...skipping 23 matching lines...) Expand all
64 shutil.copytree(source, dest) 97 shutil.copytree(source, dest)
65 else: 98 else:
66 shutil.copy2(source, dest) 99 shutil.copy2(source, dest)
67 100
68 def ExecLinkWrapper(self, arch, *args): 101 def ExecLinkWrapper(self, arch, *args):
69 """Filter diagnostic output from link that looks like: 102 """Filter diagnostic output from link that looks like:
70 ' Creating library ui.dll.lib and object ui.dll.exp' 103 ' Creating library ui.dll.lib and object ui.dll.exp'
71 This happens when there are exports from the dll or exe. 104 This happens when there are exports from the dll or exe.
72 """ 105 """
73 env = self._GetEnv(arch) 106 env = self._GetEnv(arch)
74 popen = subprocess.Popen(args, shell=True, env=env, 107 self._MaybeUseSeparateMspdbsrv(env, args)
75 stdout=subprocess.PIPE, stderr=subprocess.STDOUT) 108 link = subprocess.Popen(args,
76 out, _ = popen.communicate() 109 shell=True,
110 env=env,
111 stdout=subprocess.PIPE,
112 stderr=subprocess.STDOUT)
113 out, _ = link.communicate()
77 for line in out.splitlines(): 114 for line in out.splitlines():
78 if not line.startswith(' Creating library '): 115 if not line.startswith(' Creating library '):
79 print line 116 print line
80 return popen.returncode 117 return link.returncode
81 118
82 def ExecManifestWrapper(self, arch, *args): 119 def ExecManifestWrapper(self, arch, *args):
83 """Run manifest tool with environment set. Strip out undesirable warning 120 """Run manifest tool with environment set. Strip out undesirable warning
84 (some XML blocks are recognized by the OS loader, but not the manifest 121 (some XML blocks are recognized by the OS loader, but not the manifest
85 tool).""" 122 tool)."""
86 env = self._GetEnv(arch) 123 env = self._GetEnv(arch)
87 popen = subprocess.Popen(args, shell=True, env=env, 124 popen = subprocess.Popen(args, shell=True, env=env,
88 stdout=subprocess.PIPE, stderr=subprocess.STDOUT) 125 stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
89 out, _ = popen.communicate() 126 out, _ = popen.communicate()
90 for line in out.splitlines(): 127 for line in out.splitlines():
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 line): 198 line):
162 print line 199 print line
163 return popen.returncode 200 return popen.returncode
164 201
165 def ExecActionWrapper(self, arch, rspfile, *dir): 202 def ExecActionWrapper(self, arch, rspfile, *dir):
166 """Runs an action command line from a response file using the environment 203 """Runs an action command line from a response file using the environment
167 for |arch|. If |dir| is supplied, use that as the working directory.""" 204 for |arch|. If |dir| is supplied, use that as the working directory."""
168 env = self._GetEnv(arch) 205 env = self._GetEnv(arch)
169 args = open(rspfile).read() 206 args = open(rspfile).read()
170 dir = dir[0] if dir else None 207 dir = dir[0] if dir else None
171 popen = subprocess.Popen(args, shell=True, env=env, cwd=dir) 208 return subprocess.call(args, shell=True, env=env, cwd=dir)
172 popen.wait()
173 return popen.returncode
174 209
175 if __name__ == '__main__': 210 if __name__ == '__main__':
176 sys.exit(main(sys.argv[1:])) 211 sys.exit(main(sys.argv[1:]))
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698