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

Unified 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, 5 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 side-by-side diff with in-line comments
Download patch
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())
« .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