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

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: fixes per review 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 #!/usr/bin/env python
2 # Copyright (c) 2011 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 shutil
8 import subprocess
9 import _winreg
10
11
12 VSVARS_PATH = ('C:\\Program Files (x86)\\Microsoft Visual Studio 9.0\\'
13 'Common7\\Tools\\vsvars32.bat')
14
15
16 def run_with_vsvars(cmd):
17 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.
18 f.write('@echo off\n')
19 f.write('call "%s"\n' % VSVARS_PATH)
20 f.write(cmd + '\n')
21 f.close()
22 p = subprocess.Popen(['temp.bat'], shell=True, stdout=subprocess.PIPE,
23 universal_newlines=True)
24 out, err = p.communicate()
25 os.unlink('temp.bat')
26 return p.returncode, out
27
28
29 def get_vc_dir():
30 rc, out = run_with_vsvars('echo VCINSTALLDIR=%VCINSTALLDIR%')
31 for line in out.split('\n'):
M-A Ruel 2011/09/28 00:33:27 splitlines()
scottmg 2011/09/28 15:59:42 Done.
32 if line.startswith('VCINSTALLDIR='):
33 return line[len('VCINSTALLDIR='):]
34 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.
35
36
37 def main():
38 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.
39 if not vcdir:
40 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.
41 os.environ['PATH'] += (';' + os.path.join(vcdir, 'bin') +
42 ';' + os.path.join(vcdir, '../Common7/IDE'))
43
44 # Switch to our own dir.
45 os.chdir(os.path.dirname(os.path.abspath(__file__)))
46
47 # Verify that we can find link.exe.
48 link = os.path.join(vcdir, 'bin', 'link.exe')
49 link_backup = os.path.join(vcdir, 'bin', 'link.exe.supalink_orig.exe')
50 if not os.path.exists(link):
51 print 'link.exe not found at %s' % link
52 return 1
53
54 # Don't re-backup link.exe, so only copy link.exe to backup if it's
55 # not there already.
56 if not os.path.exists(link_backup):
57 try:
58 print 'Saving original link.exe...'
59 shutil.copyfile(link, link_backup)
60 except IOError:
61 print ('Wasn\'t able to back up %s to %s. '
62 '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
63 % (link, link_backup))
64
65 # Build supalink.exe but only if it's out of date.
66 cpptime = os.path.getmtime('supalink.cpp')
67 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.
68 or cpptime > os.path.getmtime('supalink.exe')):
69 print 'Building supalink.exe...'
70 rc, out = run_with_vsvars('cl /nologo /Ox /Zi /W4 /WX /D_UNICODE /DUNICODE'
71 ' /D_CRT_SECURE_NO_WARNINGS /EHsc supalink.cpp'
72 ' /link /out:supalink.exe')
73 if rc:
74 print out
75 print 'Failed to build supalink.exe'
76 return 1
77
78 # Copy supalink into place if it's been updated since last time we ran.
79 exetime = os.path.getmtime('supalink.exe')
80 if exetime > os.path.getmtime(link):
81 print 'Copying supalink.exe over link.exe...'
82 try:
83 shutil.copyfile('supalink.exe', link)
84 except IOError:
85 print ('Wasn\'t able to copy supalink.exe over %s. '
86 'Not running with Administrator privileges?' % link)
87 return 1
88
89 _winreg.SetValue(_winreg.HKEY_CURRENT_USER,
90 'Software\\Chromium\\supalink_installed',
91 _winreg.REG_SZ,
92 link_backup)
93
94 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.
95
96
97 if __name__ == '__main__':
98 main()
M-A Ruel 2011/09/28 00:33:27 sys.exit(main())
scottmg 2011/09/28 15:59:42 Done.
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698