OLD | NEW |
(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()) |
OLD | NEW |