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

Side by Side Diff: tools/win/link_limiter/build_link_limiter.py

Issue 10826067: Implement a tool called link_limiter to impose a global restriction on how many (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: refactor concurrency metrics Created 8 years, 4 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
OLDNEW
(Empty)
1 #!/usr/bin/env python
2 # Copyright (c) 2012 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 import os
7 import subprocess
8 import sys
9 import tempfile
10
11
12 def run_with_vsvars(cmd):
13 fd, filename = tempfile.mkstemp('.bat', text=True)
14 with os.fdopen(fd, "w") as f:
15 print >> f, '@echo off'
16 print >> f, r'call "%VS100COMNTOOLS%\vsvars32.bat"'
17 print >> f, cmd
18 try:
19 p = subprocess.Popen([filename], shell=True, stdout=subprocess.PIPE,
20 universal_newlines=True)
21 out, _ = p.communicate()
22 return p.returncode, out
23 finally:
24 os.unlink(filename)
25
26
27 def get_vc_dir():
28 _, out = run_with_vsvars('echo VCINSTALLDIR=%VCINSTALLDIR%')
29 for line in out.splitlines(): # pylint: disable-msg=E1103
30 if line.startswith('VCINSTALLDIR='):
31 return line[len('VCINSTALLDIR='):]
32 return None
33
34
35 def build(shimname, infile):
36 outfile = '%s_%s.exe' % (shimname, infile.split('.')[0])
37 shimexe = shimname + '.exe'
38 cpptime = os.path.getmtime(infile)
39 if not os.path.exists(outfile) or cpptime > os.path.getmtime(outfile):
40 print 'Building %s...' % outfile
41 rc, out = run_with_vsvars(
42 'cl /nologo /Ox /Zi /W4 /WX /D_UNICODE /DUNICODE'
43 ' /D_CRT_SECURE_NO_WARNINGS /EHsc /DSHIM_EXE=L\\"%s\\"'
44 ' %s /link /out:%s' % (shimexe, infile, outfile))
45 if rc:
46 print out
47 print 'Failed to build %s' % outfile
48 sys.exit(1)
49 else:
50 print "%s already built" % outfile
51 fullpath = os.path.abspath(outfile)
52 print '%s shim built. Use with msbuild like: "/p:LinkToolExe=%s"' \
53 % (shimexe, fullpath)
54
55
56 def main():
57 if sys.argv[-1] == 'clean':
58 basedir = os.path.dirname(os.path.abspath(__file__))
59 extensions = set(".%s" % ext for ext in "exe obj ilk pdb".split())
60 for fname in os.listdir(basedir):
61 if os.path.splitext(fname)[1] in extensions:
62 print "removing %s" % fname
63 os.unlink(os.path.join(basedir, fname))
64 return 0
65
66 vcdir = os.environ.get('VCINSTALLDIR')
67 if not vcdir:
68 vcdir = get_vc_dir()
69 if not vcdir:
70 print "Couldn't get VCINSTALLDIR. Run vsvars32.bat?"
71 return 1
72 os.environ['PATH'] += (';' + os.path.join(vcdir, 'bin') +
73 ';' + os.path.join(vcdir, r'..\Common7\IDE'))
74
75 # Switch to our own dir.
76 os.chdir(os.path.dirname(os.path.abspath(__file__)))
77
78 # Verify that we can find link.exe.
79 link = os.path.join(vcdir, 'bin', 'link.exe')
80 if not os.path.exists(link):
81 print 'link.exe not found at %s' % link
82 return 1
83
84 build('link', 'limiter.cpp')
85 build('lib', 'limiter.cpp')
86
87 return 0
88
89
90 if __name__ == '__main__':
91 sys.exit(main())
OLDNEW
« .gitignore ('K') | « .gitignore ('k') | tools/win/link_limiter/limiter.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698