Index: tools/win/link_limiter/build_link_limiter.py |
diff --git a/tools/win/link_limiter/build_link_limiter.py b/tools/win/link_limiter/build_link_limiter.py |
new file mode 100644 |
index 0000000000000000000000000000000000000000..400d13d8aa5ba2f094ba8ffcdb4942e138d94dce |
--- /dev/null |
+++ b/tools/win/link_limiter/build_link_limiter.py |
@@ -0,0 +1,91 @@ |
+#!/usr/bin/env python |
+# Copyright (c) 2012 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. |
+ |
+import os |
+import subprocess |
+import sys |
+import tempfile |
+ |
+ |
+def run_with_vsvars(cmd): |
+ fd, filename = tempfile.mkstemp('.bat', text=True) |
+ with os.fdopen(fd, "w") as f: |
+ print >> f, '@echo off' |
+ print >> f, r'call "%VS100COMNTOOLS%\vsvars32.bat"' |
+ print >> f, cmd |
+ try: |
+ p = subprocess.Popen([filename], shell=True, stdout=subprocess.PIPE, |
+ universal_newlines=True) |
+ out, _ = p.communicate() |
+ return p.returncode, out |
+ finally: |
+ os.unlink(filename) |
+ |
+ |
+def get_vc_dir(): |
+ _, out = run_with_vsvars('echo VCINSTALLDIR=%VCINSTALLDIR%') |
+ for line in out.splitlines(): # pylint: disable-msg=E1103 |
+ if line.startswith('VCINSTALLDIR='): |
+ return line[len('VCINSTALLDIR='):] |
+ return None |
+ |
+ |
+def build(shimname, infile): |
+ outfile = '%s_%s.exe' % (shimname, infile.split('.')[0]) |
+ shimexe = shimname + '.exe' |
+ cpptime = os.path.getmtime(infile) |
+ if not os.path.exists(outfile) or cpptime > os.path.getmtime(outfile): |
+ print 'Building %s...' % outfile |
+ rc, out = run_with_vsvars( |
+ 'cl /nologo /Ox /Zi /W4 /WX /D_UNICODE /DUNICODE' |
+ ' /D_CRT_SECURE_NO_WARNINGS /EHsc /DSHIM_EXE=L\\"%s\\"' |
+ ' %s /link /out:%s' % (shimexe, infile, outfile)) |
+ if rc: |
+ print out |
+ print 'Failed to build %s' % outfile |
+ sys.exit(1) |
+ else: |
+ print "%s already built" % outfile |
+ fullpath = os.path.abspath(outfile) |
+ print '%s shim built. Use with msbuild like: "/p:LinkToolExe=%s"' \ |
+ % (shimexe, fullpath) |
+ |
+ |
+def main(): |
+ if sys.argv[-1] == 'clean': |
+ basedir = os.path.dirname(os.path.abspath(__file__)) |
+ extensions = set(".%s" % ext for ext in "exe obj ilk pdb".split()) |
+ for fname in os.listdir(basedir): |
+ if os.path.splitext(fname)[1] in extensions: |
+ print "removing %s" % fname |
+ os.unlink(os.path.join(basedir, fname)) |
+ return 0 |
+ |
+ vcdir = os.environ.get('VCINSTALLDIR') |
+ if not vcdir: |
+ vcdir = get_vc_dir() |
+ if not vcdir: |
+ print "Couldn't get VCINSTALLDIR. Run vsvars32.bat?" |
+ return 1 |
+ os.environ['PATH'] += (';' + os.path.join(vcdir, 'bin') + |
+ ';' + os.path.join(vcdir, r'..\Common7\IDE')) |
+ |
+ # Switch to our own dir. |
+ os.chdir(os.path.dirname(os.path.abspath(__file__))) |
+ |
+ # Verify that we can find link.exe. |
+ link = os.path.join(vcdir, 'bin', 'link.exe') |
+ if not os.path.exists(link): |
+ print 'link.exe not found at %s' % link |
+ return 1 |
+ |
+ build('link', 'limiter.cpp') |
+ build('lib', 'limiter.cpp') |
+ |
+ return 0 |
+ |
+ |
+if __name__ == '__main__': |
+ sys.exit(main()) |