Index: tools/win/split_link/install_split_link.py |
diff --git a/tools/win/split_link/install_split_link.py b/tools/win/split_link/install_split_link.py |
new file mode 100644 |
index 0000000000000000000000000000000000000000..87c98175648547171d49848d7334ba948b169d43 |
--- /dev/null |
+++ b/tools/win/split_link/install_split_link.py |
@@ -0,0 +1,108 @@ |
+#!/usr/bin/env python |
+# Copyright (c) 2013 The Chromium Authors. All rights reserved. |
+# Use of this source code is governed by a BSD-style license that can be |
+# found in the LICENSE file. |
+ |
+import os |
+import shutil |
+import subprocess |
+import sys |
+ |
+ |
+if sys.platform == 'win32': |
+ import _winreg |
+elif sys.platform == 'cygwin': |
+ try: |
+ import cygwinreg as _winreg |
+ except ImportError: |
+ print "Please install cygwinreg so I can access the registry." |
+ print "Install setuptools and run 'easy_install cygwinreg'." |
M-A Ruel
2013/05/13 21:23:42
add raise at the end or sys.exit(1) ?
scottmg
2013/05/13 21:30:22
Done.
|
+ |
+ |
+def IsExe(fpath): |
+ return os.path.isfile(fpath) and os.access(fpath, os.X_OK) |
+ |
+ |
+def FindInPath(program): |
+ fpath, fname = os.path.split(program) |
+ if fpath: |
+ if IsExe(program): |
+ return program |
+ else: |
+ for path in os.environ['PATH'].split(os.pathsep): |
+ path = path.strip('"') |
+ exe_file = os.path.join(path, program) |
+ if IsExe(exe_file): |
+ return exe_file |
+ return None |
+ |
+ |
+def Run(command): |
+ p = subprocess.Popen([], shell=True, stdout=subprocess.PIPE, |
M-A Ruel
2013/05/13 21:23:42
That's weird. :)
scottmg
2013/05/13 21:30:22
Oops, this is dead code (obviously). Deleted.
|
+ universal_newlines=True) |
M-A Ruel
2013/05/13 21:23:42
It's an unconventional alignment, I usually put ev
|
+ out, err = p.communicate() |
+ return p.returncode, out |
+ |
+ |
+def EscapeForCommandLineAndCString(path): |
+ """Quoted sufficiently to be passed on the compile command line as a define |
+ to be turned into a string in the target C program.""" |
+ path = '"' + path + '"' |
+ return path.replace('\\', '\\\\').replace('"', '\\"') |
+ |
+ |
+def main(): |
+ # Switch to our own dir. |
+ os.chdir(os.path.dirname(os.path.abspath(__file__))) |
M-A Ruel
2013/05/13 21:23:42
It's preferable to create a global variable instea
scottmg
2013/05/13 21:30:22
Done.
|
+ |
+ link = FindInPath('link.exe') |
+ if not link: |
+ print ("Couldn't find link.exe in PATH. Must run from Administrator " |
M-A Ruel
2013/05/13 21:23:42
print(
scottmg
2013/05/13 21:30:22
Done.
|
+ "Visual Studio Command Prompt.") |
+ return 1 |
+ |
+ link_backup = os.path.join(os.path.split(link)[0], 'link.exe.split_link.exe') |
+ |
+ # Don't re-backup link.exe, so only copy link.exe to backup if it's |
+ # not there already. |
+ if not os.path.exists(link_backup): |
+ try: |
+ print 'Saving original link.exe...' |
+ shutil.copyfile(link, link_backup) |
+ except IOError: |
+ print (('Wasn\'t able to back up %s to %s. ' |
+ 'Not running with Administrator privileges?') |
+ % (link, link_backup)) |
+ return 1 |
+ |
+ # Build our linker shim. |
+ print 'Building split_link.exe...' |
+ split_link_py = os.path.abspath('split_link.py') |
+ script_path = EscapeForCommandLineAndCString(split_link_py) |
+ python = EscapeForCommandLineAndCString(sys.executable) |
+ subprocess.check_call('cl /nologo /Ox /Zi /W4 /WX /D_UNICODE /DUNICODE' |
M-A Ruel
2013/05/13 21:23:42
It's preferable to use an array in general. Unless
scottmg
2013/05/13 21:30:22
I wanted to be clear about what was happening to "
M-A Ruel
2013/05/13 21:55:59
That's fine
|
+ ' /D_CRT_SECURE_NO_WARNINGS /EHsc split_link.cc' |
+ ' /DPYTHON_PATH="%s"' |
+ ' /DSPLIT_LINK_SCRIPT_PATH="%s"' |
+ ' /link shell32.lib shlwapi.lib /out:split_link.exe' % ( |
+ python, script_path), |
+ shell=True) |
+ |
+ # Copy shim into place. |
+ print 'Copying split_link.exe over link.exe...' |
+ try: |
+ shutil.copyfile('split_link.exe', link) |
+ _winreg.SetValue(_winreg.HKEY_CURRENT_USER, |
+ 'Software\\Chromium\\split_link_installed', |
+ _winreg.REG_SZ, |
+ link_backup) |
+ except IOError: |
+ print ('Wasn\'t able to copy split_link.exe over %s. ' |
+ 'Not running with Administrator privileges?' % link) |
+ return 1 |
+ |
+ return 0 |
+ |
+ |
+if __name__ == '__main__': |
+ sys.exit(main()) |