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

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: make sure tmp file is unlink'd 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)
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 try:
26 p = subprocess.Popen([filename], shell=True, stdout=subprocess.PIPE,
27 universal_newlines=True)
28 out, err = p.communicate()
29 return p.returncode, out
30 finally:
31 os.unlink(filename)
32
33
34 def get_vc_dir():
35 rc, out = run_with_vsvars('echo VCINSTALLDIR=%VCINSTALLDIR%')
36 for line in out.splitlines():
37 if line.startswith('VCINSTALLDIR='):
38 return line[len('VCINSTALLDIR='):]
39 return None
40
41
42 def main():
43 vcdir = os.environ.get('VCINSTALLDIR')
44 if not vcdir:
45 vcdir = get_vc_dir()
46 if not vcdir:
47 print 'Couldn\'t get VCINSTALLDIR. Run vsvars32.bat?'
48 return 1
49 os.environ['PATH'] += (';' + os.path.join(vcdir, 'bin') +
50 ';' + os.path.join(vcdir, '..\\Common7\\IDE'))
51
52 # Switch to our own dir.
53 os.chdir(os.path.dirname(os.path.abspath(__file__)))
54
55 # Verify that we can find link.exe.
56 link = os.path.join(vcdir, 'bin', 'link.exe')
57 link_backup = os.path.join(vcdir, 'bin', 'link.exe.supalink_orig.exe')
58 if not os.path.exists(link):
59 print 'link.exe not found at %s' % link
60 return 1
61
62 # Don't re-backup link.exe, so only copy link.exe to backup if it's
63 # not there already.
64 if not os.path.exists(link_backup):
65 try:
66 print 'Saving original link.exe...'
67 shutil.copyfile(link, link_backup)
68 except IOError:
69 print (('Wasn\'t able to back up %s to %s. '
70 'Not running with Administrator privileges?')
71 % (link, link_backup))
72 return 1
73
74 # Build supalink.exe but only if it's out of date.
75 cpptime = os.path.getmtime('supalink.cpp')
76 if (not os.path.exists('supalink.exe') or
77 cpptime > os.path.getmtime('supalink.exe')):
78 print 'Building supalink.exe...'
79 rc, out = run_with_vsvars('cl /nologo /Ox /Zi /W4 /WX /D_UNICODE /DUNICODE'
80 ' /D_CRT_SECURE_NO_WARNINGS /EHsc supalink.cpp'
81 ' /link /out:supalink.exe')
82 if rc:
83 print out
84 print 'Failed to build supalink.exe'
85 return 1
86
87 # Copy supalink into place if it's been updated since last time we ran.
88 exetime = os.path.getmtime('supalink.exe')
89 if exetime > os.path.getmtime(link):
90 print 'Copying supalink.exe over link.exe...'
91 try:
92 shutil.copyfile('supalink.exe', link)
93 except IOError:
94 print ('Wasn\'t able to copy supalink.exe over %s. '
95 'Not running with Administrator privileges?' % link)
96 return 1
97
98 _winreg.SetValue(_winreg.HKEY_CURRENT_USER,
99 'Software\\Chromium\\supalink_installed',
100 _winreg.REG_SZ,
101 link_backup)
102
103 print 'Linker shim installed. Regenerate via gyp: "gclient runhooks".'
104 return 0
105
106
107 if __name__ == '__main__':
108 sys.exit(main())
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698