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

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

Powered by Google App Engine
This is Rietveld 408576698