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

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: Incorporate feedback from thestig 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..464d30c57b24f56efd96bf8abff0f74d78d11779
--- /dev/null
+++ b/tools/win/link_limiter/build_link_limiter.py
@@ -0,0 +1,99 @@
+#!/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 glob
+import os
+import shutil
+import subprocess
+import sys
+import tempfile
+
+BUILD_DIR = 'build'
+
+
+def run_with_vsvars(cmd, tmpdir=None):
+ 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"'
+ if tmpdir:
+ print >> f, r'cd %s' % tmpdir
+ 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(infile):
+ if not os.path.exists(BUILD_DIR):
+ os.makedirs(BUILD_DIR)
+ outfile = 'limiter.exe'
+ outpath = os.path.join(BUILD_DIR, outfile)
+ cpptime = os.path.getmtime(infile)
+ if not os.path.exists(outpath) or cpptime > os.path.getmtime(outpath):
+ print 'Building %s...' % outfile
+ rc, out = run_with_vsvars(
+ 'cl /nologo /Ox /Zi /W4 /WX /D_UNICODE /DUNICODE'
+ ' /D_CRT_SECURE_NO_WARNINGS /EHsc %s /link /out:%s'
+ % (os.path.join('..', infile), outfile), BUILD_DIR)
+ if rc:
+ print out
+ print 'Failed to build %s' % outfile
+ sys.exit(1)
+ else:
+ print '%s already built' % outfile
+ return outpath
+
+
+def main():
+ # Switch to our own dir.
+ os.chdir(os.path.dirname(os.path.abspath(__file__)))
+
+ if sys.argv[-1] == 'clean':
+ if os.path.exists(BUILD_DIR):
+ shutil.rmtree(BUILD_DIR)
+ for exe in glob.glob('*.exe'):
+ os.unlink(exe)
+ return 0
+
+ vcdir = os.environ.get('VCINSTALLDIR')
+ if not vcdir:
+ vcdir = get_vc_dir()
+ if not vcdir:
+ print 'Could not get VCINSTALLDIR. Run vsvars32.bat?'
+ return 1
+ os.environ['PATH'] += (';' + os.path.join(vcdir, 'bin') +
+ ';' + os.path.join(vcdir, r'..\Common7\IDE'))
+
+ # 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
+
+ exe_name = build('limiter.cc')
+ for shim_exe in ('lib.exe', 'link.exe'):
+ newpath = '%s__LIMITER.exe' % shim_exe
+ shutil.copyfile(exe_name, newpath)
+ print '%s shim built. Use with msbuild like: "/p:LinkToolExe=%s"' \
+ % (shim_exe, os.path.abspath(newpath))
+
+ return 0
+
+
+if __name__ == '__main__':
+ sys.exit(main())
« no previous file with comments | « .gitignore ('k') | tools/win/link_limiter/limiter.cc » ('j') | tools/win/link_limiter/limiter.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698