Chromium Code Reviews| Index: tools/win/supalink/install_supalink.py |
| diff --git a/tools/win/supalink/install_supalink.py b/tools/win/supalink/install_supalink.py |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..81e6f0c912fb1cd4acec80203607ec1eafb23130 |
| --- /dev/null |
| +++ b/tools/win/supalink/install_supalink.py |
| @@ -0,0 +1,98 @@ |
| +#!/usr/bin/env python |
| +# Copyright (c) 2011 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 shutil |
| +import subprocess |
| +import _winreg |
| + |
| + |
| +VSVARS_PATH = ('C:\\Program Files (x86)\\Microsoft Visual Studio 9.0\\' |
| + 'Common7\\Tools\\vsvars32.bat') |
| + |
| + |
| +def run_with_vsvars(cmd): |
| + f = open('temp.bat', 'w') |
|
M-A Ruel
2011/09/28 00:33:27
I'd prefer to use tempfile instead of creating a f
scottmg
2011/09/28 15:59:42
Done.
|
| + f.write('@echo off\n') |
| + f.write('call "%s"\n' % VSVARS_PATH) |
| + f.write(cmd + '\n') |
| + f.close() |
| + p = subprocess.Popen(['temp.bat'], shell=True, stdout=subprocess.PIPE, |
| + universal_newlines=True) |
| + out, err = p.communicate() |
| + os.unlink('temp.bat') |
| + return p.returncode, out |
| + |
| + |
| +def get_vc_dir(): |
| + rc, out = run_with_vsvars('echo VCINSTALLDIR=%VCINSTALLDIR%') |
| + for line in out.split('\n'): |
|
M-A Ruel
2011/09/28 00:33:27
splitlines()
scottmg
2011/09/28 15:59:42
Done.
|
| + if line.startswith('VCINSTALLDIR='): |
| + return line[len('VCINSTALLDIR='):] |
| + raise SystemExit('Couldn\'t get VCINSTALLDIR. Run vsvars32.bat?') |
|
M-A Ruel
2011/09/28 00:33:27
I'd remove this line and do the check at line 40.
scottmg
2011/09/28 15:59:42
Done.
|
| + |
| + |
| +def main(): |
| + vcdir = os.environ['VCINSTALLDIR'] |
|
M-A Ruel
2011/09/28 00:33:27
os.environ.get('VCINSTALLDIR')
otherwise it'll th
scottmg
2011/09/28 15:59:42
Done.
|
| + if not vcdir: |
| + vcdir = get_vc_dir() |
|
M-A Ruel
2011/09/28 00:33:27
if not vcdir:
print 'Couldn\'t get ...'
return
scottmg
2011/09/28 21:47:56
Done.
|
| + os.environ['PATH'] += (';' + os.path.join(vcdir, 'bin') + |
| + ';' + os.path.join(vcdir, '../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') |
| + link_backup = os.path.join(vcdir, 'bin', 'link.exe.supalink_orig.exe') |
| + if not os.path.exists(link): |
| + print 'link.exe not found at %s' % link |
| + return 1 |
| + |
| + # Don't re-backup link.exe, so only copy link.exe to backup if it's |
| + # not there already. |
| + if not os.path.exists(link_backup): |
| + try: |
| + print 'Saving original link.exe...' |
| + shutil.copyfile(link, link_backup) |
| + except IOError: |
| + print ('Wasn\'t able to back up %s to %s. ' |
| + 'Not running with Administrator privileges?' |
|
M-A Ruel
2011/09/28 00:33:27
append ) otherwise it'll fail.
scottmg
2011/09/28 15:59:42
Not sure what you mean?
M-A Ruel
2011/09/28 18:17:14
% has a higher precedence than string concatenatio
scottmg
2011/09/28 21:47:56
Done. As adjacent string literals behaviour is def
|
| + % (link, link_backup)) |
| + |
| + # Build supalink.exe but only if it's out of date. |
| + cpptime = os.path.getmtime('supalink.cpp') |
| + if (not os.path.exists('supalink.exe') |
|
M-A Ruel
2011/09/28 00:33:27
'or' at the end of the line
scottmg
2011/09/28 15:59:42
Done.
|
| + or cpptime > os.path.getmtime('supalink.exe')): |
| + print 'Building supalink.exe...' |
| + rc, out = run_with_vsvars('cl /nologo /Ox /Zi /W4 /WX /D_UNICODE /DUNICODE' |
| + ' /D_CRT_SECURE_NO_WARNINGS /EHsc supalink.cpp' |
| + ' /link /out:supalink.exe') |
| + if rc: |
| + print out |
| + print 'Failed to build supalink.exe' |
| + return 1 |
| + |
| + # Copy supalink into place if it's been updated since last time we ran. |
| + exetime = os.path.getmtime('supalink.exe') |
| + if exetime > os.path.getmtime(link): |
| + print 'Copying supalink.exe over link.exe...' |
| + try: |
| + shutil.copyfile('supalink.exe', link) |
| + except IOError: |
| + print ('Wasn\'t able to copy supalink.exe over %s. ' |
| + 'Not running with Administrator privileges?' % link) |
| + return 1 |
| + |
| + _winreg.SetValue(_winreg.HKEY_CURRENT_USER, |
| + 'Software\\Chromium\\supalink_installed', |
| + _winreg.REG_SZ, |
| + link_backup) |
| + |
| + print 'Linker shim installed. Regenerate via gyp: "gclient runhooks".' |
|
M-A Ruel
2011/09/28 00:33:27
return 0
scottmg
2011/09/28 15:59:42
Done.
|
| + |
| + |
| +if __name__ == '__main__': |
| + main() |
|
M-A Ruel
2011/09/28 00:33:27
sys.exit(main())
scottmg
2011/09/28 15:59:42
Done.
|