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

Side by Side 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, 2 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 # 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.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
4
5 import os
6 import shutil
7 import subprocess
8 import _winreg
9
10 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.
11 \\Common7\\Tools\\vsvars32.bat'
12
M-A Ruel 2011/09/27 23:21:33 two lines between file level symbols
scottmg 2011/09/28 00:19:38 Done.
13 def run_with_vsvars(cmd):
14 f = open('temp.bat', 'w')
15 f.write('@echo off\n')
16 f.write('call "%s"\n' % VSVARS_PATH)
17 f.write(cmd + '\n')
18 f.close()
19 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
20 out, err = p.communicate()
21 os.unlink('temp.bat')
22 out = out.replace('\r', '')
M-A Ruel 2011/09/27 23:21:33 universal_newlines=True?
scottmg 2011/09/28 00:19:38 Done.
23 return p.returncode, out
24
25
26 def get_vc_dir():
27 rc, out = run_with_vsvars('echo VCINSTALLDIR=%VCINSTALLDIR%')
28 for line in out.split('\n'):
29 if line.startswith('VCINSTALLDIR='):
30 return line[len('VCINSTALLDIR='):]
31 raise SystemExit('Couldn\'t get VCINSTALLDIR. Run vsvars32.bat?')
32
33 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.
34 if 'VCINSTALLDIR' not in os.environ:
35 vcdir = get_vc_dir()
36 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.
37 ';' + os.path.join(vcdir, '../Common7/IDE')
38 else:
39 vcdir = os.environ['VCINSTALLDIR']
40
41 # Switch to our own dir.
42 os.chdir(os.path.dirname(os.path.abspath(__file__)))
43
44 # Verify that we can find link.exe.
45 link = os.path.join(vcdir, 'bin', 'link.exe')
46 link_backup = os.path.join(vcdir, 'bin', 'link.exe.supalink_orig.exe')
47 if not os.path.exists(link):
48 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.
49
50 # Don't re-backup link.exe, so only copy link.exe to backup if it's
51 # not there already.
52 if not os.path.exists(link_backup):
53 try:
54 print 'Saving original link.exe...'
55 shutil.copyfile(link, link_backup)
56 except IOError:
57 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.
58 Not running with Administrator privileges?' % (link, link_backup))
59
60 # Build supalink.exe but only if it's out of date.
61 cpptime = os.path.getmtime('supalink.cpp')
62 if (not os.path.exists('supalink.exe')
63 or cpptime > os.path.getmtime('supalink.exe')):
64 print 'Building supalink.exe...'
65 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.
66 /D_CRT_SECURE_NO_WARNINGS /EHsc supalink.cpp\
67 /link /out:supalink.exe')
68 if rc != 0:
M-A Ruel 2011/09/27 23:21:33 if rc:
scottmg 2011/09/28 00:19:38 Done.
69 print out
70 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.
71
72 # Copy supalink into place if it's been updated since last time we ran.
73 exetime = os.path.getmtime('supalink.exe')
74 if exetime > os.path.getmtime(link):
75 print 'Copying supalink.exe over link.exe...'
76 try:
77 shutil.copyfile('supalink.exe', link)
78 except IOError:
79 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.
80 Not running with Administrator privileges?' % link)
81
82 _winreg.SetValue(_winreg.HKEY_CURRENT_USER,
83 'Software\\Chromium\\supalink_installed',
M-A Ruel 2011/09/27 23:21:33 weird alignment.
scottmg 2011/09/28 00:19:38 Done.
84 _winreg.REG_SZ,
85 link_backup)
86
87 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.
88
M-A Ruel 2011/09/27 23:21:33 two lines between file level symbols
scottmg 2011/09/28 00:19:38 Done.
89 if __name__ == '__main__':
90 main()
M-A Ruel 2011/09/27 23:21:33 sys.exit(main())
scottmg 2011/09/28 00:19:38 Done.
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698