OLD | NEW |
---|---|
(Empty) | |
1 #!/usr/bin/env python | |
2 # Copyright (c) 2013 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 | |
11 | |
12 g_this_file = os.path.abspath(__file__) | |
M-A Ruel
2013/05/14 00:39:09
THIS_FILE, as per style. Or:
BASE_DIR = os.path.di
scottmg
2013/05/14 03:35:07
Done.
| |
13 | |
14 | |
15 if sys.platform == 'win32': | |
16 import _winreg | |
17 elif sys.platform == 'cygwin': | |
18 try: | |
19 import cygwinreg as _winreg | |
20 except ImportError: | |
21 print "Please install cygwinreg so I can access the registry." | |
22 print "Install setuptools and run 'easy_install cygwinreg'." | |
23 sys.exit(1) | |
24 | |
25 | |
26 def IsExe(fpath): | |
27 return os.path.isfile(fpath) and os.access(fpath, os.X_OK) | |
28 | |
29 | |
30 def FindInPath(program): | |
31 fpath, fname = os.path.split(program) | |
32 if fpath: | |
33 if IsExe(program): | |
34 return program | |
35 else: | |
36 for path in os.environ['PATH'].split(os.pathsep): | |
37 path = path.strip('"') | |
38 exe_file = os.path.join(path, program) | |
M-A Ruel
2013/05/14 00:39:09
if not path or not os.path.isabs(path):
continue
scottmg
2013/05/14 03:35:07
Done.
| |
39 if IsExe(exe_file): | |
40 return exe_file | |
41 return None | |
42 | |
43 | |
44 def EscapeForCommandLineAndCString(path): | |
45 """Quoted sufficiently to be passed on the compile command line as a define | |
46 to be turned into a string in the target C program.""" | |
47 path = '"' + path + '"' | |
48 return path.replace('\\', '\\\\').replace('"', '\\"') | |
49 | |
50 | |
51 def main(): | |
52 # Switch to our own dir. | |
53 os.chdir(os.path.dirname(g_this_file)) | |
54 | |
55 link = FindInPath('link.exe') | |
56 if not link: | |
57 print("Couldn't find link.exe in PATH. Must run from Administrator " | |
M-A Ruel
2013/05/14 00:39:09
Sometimes you use ', sometimes ". Please use only
scottmg
2013/05/14 03:35:07
I normally use ' except when there's an embedded '
| |
58 "Visual Studio Command Prompt.") | |
59 return 1 | |
60 | |
61 link_backup = os.path.join(os.path.split(link)[0], 'link.exe.split_link.exe') | |
62 | |
63 # Don't re-backup link.exe, so only copy link.exe to backup if it's | |
64 # not there already. | |
65 if not os.path.exists(link_backup): | |
66 try: | |
67 print 'Saving original link.exe...' | |
68 shutil.copyfile(link, link_backup) | |
69 except IOError: | |
70 print (('Wasn\'t able to back up %s to %s. ' | |
71 'Not running with Administrator privileges?') | |
72 % (link, link_backup)) | |
73 return 1 | |
74 | |
75 # Build our linker shim. | |
76 print 'Building split_link.exe...' | |
77 split_link_py = os.path.abspath('split_link.py') | |
78 script_path = EscapeForCommandLineAndCString(split_link_py) | |
79 python = EscapeForCommandLineAndCString(sys.executable) | |
80 subprocess.check_call('cl /nologo /Ox /Zi /W4 /WX /D_UNICODE /DUNICODE' | |
81 ' /D_CRT_SECURE_NO_WARNINGS /EHsc split_link.cc' | |
82 ' /DPYTHON_PATH="%s"' | |
83 ' /DSPLIT_LINK_SCRIPT_PATH="%s"' | |
84 ' /link shell32.lib shlwapi.lib /out:split_link.exe' % ( | |
85 python, script_path), | |
86 shell=True) | |
87 | |
88 # Copy shim into place. | |
89 print 'Copying split_link.exe over link.exe...' | |
90 try: | |
91 shutil.copyfile('split_link.exe', link) | |
92 _winreg.SetValue(_winreg.HKEY_CURRENT_USER, | |
93 'Software\\Chromium\\split_link_installed', | |
94 _winreg.REG_SZ, | |
95 link_backup) | |
96 except IOError: | |
97 print ('Wasn\'t able to copy split_link.exe over %s. ' | |
98 'Not running with Administrator privileges?' % link) | |
99 return 1 | |
100 | |
101 return 0 | |
102 | |
103 | |
104 if __name__ == '__main__': | |
105 sys.exit(main()) | |
OLD | NEW |