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

Unified Diff: tools/win/supalink/install_supalink.py

Issue 8059024: Mostly automatic incremental link enabling (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: { wrong line, reinterpret instead of C-style, banish capitals, del owners Created 9 years, 3 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/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..d3712585e2b3ca9c0e4c9d07268753921469eff6
--- /dev/null
+++ b/tools/win/supalink/install_supalink.py
@@ -0,0 +1,90 @@
+# Copyright (c) 2011 The Chromium Authors. All rights reserved.
M-A Ruel 2011/09/27 23:21:33 shebang
scottmg 2011/09/28 00:19:38 Done.
+# 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\
M-A Ruel 2011/09/27 23:21:33 use () instead of \
scottmg 2011/09/28 00:19:38 Done.
+\\Common7\\Tools\\vsvars32.bat'
+
M-A Ruel 2011/09/27 23:21:33 two lines between file level symbols
scottmg 2011/09/28 00:19:38 Done.
+def run_with_vsvars(cmd):
+ f = open('temp.bat', 'w')
+ 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)
M-A Ruel 2011/09/27 23:21:33 I'd prefer an option to not have to write a tempfi
scottmg 2011/09/28 00:19:38 I couldn't figure out the quoting required to get
+ out, err = p.communicate()
+ os.unlink('temp.bat')
+ out = out.replace('\r', '')
M-A Ruel 2011/09/27 23:21:33 universal_newlines=True?
scottmg 2011/09/28 00:19:38 Done.
+ return p.returncode, out
+
+
+def get_vc_dir():
+ rc, out = run_with_vsvars('echo VCINSTALLDIR=%VCINSTALLDIR%')
+ for line in out.split('\n'):
+ if line.startswith('VCINSTALLDIR='):
+ return line[len('VCINSTALLDIR='):]
+ raise SystemExit('Couldn\'t get VCINSTALLDIR. Run vsvars32.bat?')
+
+def main():
M-A Ruel 2011/09/27 23:21:33 vcdir = os.environ.get('VCINSTALLDIR') if not vcdi
scottmg 2011/09/28 00:19:38 Done.
+ if 'VCINSTALLDIR' not in os.environ:
+ vcdir = get_vc_dir()
+ os.environ['PATH'] += ';' + os.path.join(vcdir, 'bin') + \
M-A Ruel 2011/09/27 23:21:33 use ()
scottmg 2011/09/28 00:19:38 Done.
+ ';' + os.path.join(vcdir, '../Common7/IDE')
+ else:
+ vcdir = os.environ['VCINSTALLDIR']
+
+ # 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):
+ raise SystemExit('link.exe not found at %s' % link)
M-A Ruel 2011/09/27 23:21:33 print 'link.exe not found at %s' % link return 1
scottmg 2011/09/28 00:19:38 Done.
+
+ # 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:
+ raise SystemExit('Wasn\'t able to back up %s to %s.\
M-A Ruel 2011/09/27 23:21:33 same
scottmg 2011/09/28 00:19:38 Done.
+ Not running with Administrator privileges?' % (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')
+ or cpptime > os.path.getmtime('supalink.exe')):
+ print 'Building supalink.exe...'
+ rc, out = run_with_vsvars('cl /nologo /Ox /Zi /W4 /WX\
M-A Ruel 2011/09/27 23:21:33 same
scottmg 2011/09/28 00:19:38 Done.
+ /D_CRT_SECURE_NO_WARNINGS /EHsc supalink.cpp\
+ /link /out:supalink.exe')
+ if rc != 0:
M-A Ruel 2011/09/27 23:21:33 if rc:
scottmg 2011/09/28 00:19:38 Done.
+ print out
+ raise SystemExit('Failed to build supalink.exe')
M-A Ruel 2011/09/27 23:21:33 same
scottmg 2011/09/28 00:19:38 Done.
+
+ # 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:
+ raise SystemExit('Wasn\'t able to copy supalink.exe over %s.\
M-A Ruel 2011/09/27 23:21:33 same
scottmg 2011/09/28 00:19:38 Done.
+ Not running with Administrator privileges?' % link)
+
+ _winreg.SetValue(_winreg.HKEY_CURRENT_USER,
+ 'Software\\Chromium\\supalink_installed',
M-A Ruel 2011/09/27 23:21:33 weird alignment.
scottmg 2011/09/28 00:19:38 Done.
+ _winreg.REG_SZ,
+ link_backup)
+
+ print 'Linker shim installed. Regenerate via gyp: "gclient runhooks".'
M-A Ruel 2011/09/27 23:21:33 return 0
scottmg 2011/09/28 00:19:38 Done.
+
M-A Ruel 2011/09/27 23:21:33 two lines between file level symbols
scottmg 2011/09/28 00:19:38 Done.
+if __name__ == '__main__':
+ main()
M-A Ruel 2011/09/27 23:21:33 sys.exit(main())
scottmg 2011/09/28 00:19:38 Done.

Powered by Google App Engine
This is Rietveld 408576698