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.
12 BASE_DIR
= os
.path
.dirname(os
.path
.abspath(__file__
))
16 return os
.path
.isfile(fpath
) and os
.access(fpath
, os
.X_OK
)
19 def FindInPath(program
):
20 fpath
, _
= os
.path
.split(program
)
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
):
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('"', '\\"')
43 # Switch to our own dir.
46 link
= FindInPath('link.exe')
47 mt
= FindInPath('mt.exe')
48 if not link
or not mt
:
49 print("Couldn't find link.exe or mt.exe in PATH. "
50 "Must run from Administrator Visual Studio Command Prompt.")
53 link_backup
= os
.path
.join(os
.path
.split(link
)[0], 'link.exe.split_link.exe')
55 # Don't re-backup link.exe, so only copy link.exe to backup if it's
57 if not os
.path
.exists(link_backup
):
59 print 'Saving original link.exe...'
60 shutil
.copyfile(link
, link_backup
)
62 print(("Wasn't able to back up %s to %s. "
63 "Not running with Administrator privileges?")
64 % (link
, link_backup
))
67 # Build our linker shim.
68 print 'Building split_link.exe...'
69 split_link_py
= os
.path
.abspath('split_link.py')
70 script_path
= EscapeForCommandLineAndCString(split_link_py
)
71 python
= EscapeForCommandLineAndCString(sys
.executable
)
72 subprocess
.check_call('cl.exe /nologo /Ox /Zi /W4 /WX /D_UNICODE /DUNICODE'
73 ' /D_CRT_SECURE_NO_WARNINGS /EHsc split_link.cc'
75 ' /DSPLIT_LINK_SCRIPT_PATH="%s"'
76 ' /link shell32.lib shlwapi.lib /out:split_link.exe' % (
79 # Copy shim into place.
80 print 'Copying split_link.exe over link.exe...'
82 shutil
.copyfile('split_link.exe', link
)
83 _winreg
.SetValue(_winreg
.HKEY_CURRENT_USER
,
84 'Software\\Chromium\\split_link_installed',
87 _winreg
.SetValue(_winreg
.HKEY_CURRENT_USER
,
88 'Software\\Chromium\\split_link_mt_path',
92 print("Wasn't able to copy split_link.exe over %s. "
93 "Not running with Administrator privileges?" % link
)
99 if __name__
== '__main__':