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.exe /nologo /Ox /Zi /W4 /WX /D_UNICODE /DUNICODE' |
| 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 |
| 78 # Copy shim into place. |
| 79 print 'Copying split_link.exe over link.exe...' |
| 80 try: |
| 81 shutil.copyfile('split_link.exe', link) |
| 82 _winreg.SetValue(_winreg.HKEY_CURRENT_USER, |
| 83 'Software\\Chromium\\split_link_installed', |
| 84 _winreg.REG_SZ, |
| 85 link_backup) |
| 86 except IOError: |
| 87 print("Wasn't able to copy split_link.exe over %s. " |
| 88 "Not running with Administrator privileges?" % link) |
| 89 return 1 |
| 90 |
| 91 return 0 |
| 92 |
| 93 |
| 94 if __name__ == '__main__': |
| 95 sys.exit(main()) |
OLD | NEW |