Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 # Copyright (c) 2013 The Chromium Authors. All rights reserved. | |
| 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 _winreg | |
| 6 import os | |
| 7 import shutil | |
| 8 import subprocess | |
| 9 import sys | |
| 10 | |
| 11 | |
| 12 BASE_DIR = os.path.dirname(os.path.abspath(__file__)) | |
| 13 | |
| 14 | |
| 15 def IsExe(fpath): | |
| 16 return os.path.isfile(fpath) and os.access(fpath, os.X_OK) | |
| 17 | |
| 18 | |
| 19 def FindInPath(program): | |
| 20 fpath, _ = os.path.split(program) | |
| 21 if fpath: | |
| 22 if IsExe(program): | |
| 23 return program | |
| 24 else: | |
| 25 for path in os.environ['PATH'].split(os.pathsep): | |
| 26 path = path.strip('"') | |
| 27 exe_file = os.path.join(path, program) | |
| 28 if not path or not os.path.isabs(path): | |
| 29 continue | |
| 30 if IsExe(exe_file): | |
| 31 return exe_file | |
| 32 return None | |
| 33 | |
| 34 | |
| 35 def EscapeForCommandLineAndCString(path): | |
| 36 """Quoted sufficiently to be passed on the compile command line as a define | |
| 37 to be turned into a string in the target C program.""" | |
| 38 path = '"' + path + '"' | |
| 39 return path.replace('\\', '\\\\').replace('"', '\\"') | |
| 40 | |
| 41 | |
| 42 def main(): | |
| 43 # Switch to our own dir. | |
| 44 os.chdir(BASE_DIR) | |
| 45 | |
| 46 link = FindInPath('link.exe') | |
| 47 if not link: | |
| 48 print("Couldn't find link.exe in PATH. Must run from Administrator " | |
| 49 "Visual Studio Command Prompt.") | |
| 50 return 1 | |
| 51 | |
| 52 link_backup = os.path.join(os.path.split(link)[0], 'link.exe.split_link.exe') | |
| 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?") | |
| 63 % (link, link_backup)) | |
| 64 return 1 | |
| 65 | |
| 66 # Build our linker shim. | |
| 67 print 'Building split_link.exe...' | |
| 68 split_link_py = os.path.abspath('split_link.py') | |
| 69 script_path = EscapeForCommandLineAndCString(split_link_py) | |
| 70 python = EscapeForCommandLineAndCString(sys.executable) | |
| 71 subprocess.check_call('cl /nologo /Ox /Zi /W4 /WX /D_UNICODE /DUNICODE' | |
|
M-A Ruel
2013/05/14 19:38:08
cl.exe
scottmg
2013/05/14 19:45:51
Done.
| |
| 72 ' /D_CRT_SECURE_NO_WARNINGS /EHsc split_link.cc' | |
| 73 ' /DPYTHON_PATH="%s"' | |
| 74 ' /DSPLIT_LINK_SCRIPT_PATH="%s"' | |
| 75 ' /link shell32.lib shlwapi.lib /out:split_link.exe' % ( | |
| 76 python, script_path), | |
| 77 shell=True) | |
|
M-A Ruel
2013/05/14 19:38:08
Is shell=True necessary? I'd prefer not to set it
scottmg
2013/05/14 19:45:51
Done.
| |
| 78 | |
| 79 # Copy shim into place. | |
| 80 print 'Copying split_link.exe over link.exe...' | |
| 81 try: | |
| 82 shutil.copyfile('split_link.exe', link) | |
| 83 _winreg.SetValue(_winreg.HKEY_CURRENT_USER, | |
| 84 'Software\\Chromium\\split_link_installed', | |
| 85 _winreg.REG_SZ, | |
| 86 link_backup) | |
| 87 except IOError: | |
| 88 print("Wasn't able to copy split_link.exe over %s. " | |
| 89 "Not running with Administrator privileges?" % link) | |
| 90 return 1 | |
| 91 | |
| 92 return 0 | |
| 93 | |
| 94 | |
| 95 if __name__ == '__main__': | |
| 96 sys.exit(main()) | |
| OLD | NEW |