Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(15)

Side by Side Diff: tools/win/split_link/install_split_link.py

Issue 15067010: split_link tool, config, and scripts for windows build (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: linebreak() Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 if sys.platform == 'win32':
13 import _winreg
14 elif sys.platform == 'cygwin':
15 try:
16 import cygwinreg as _winreg
17 except ImportError:
18 print "Please install cygwinreg so I can access the registry."
19 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.
20
21
22 def IsExe(fpath):
23 return os.path.isfile(fpath) and os.access(fpath, os.X_OK)
24
25
26 def FindInPath(program):
27 fpath, fname = os.path.split(program)
28 if fpath:
29 if IsExe(program):
30 return program
31 else:
32 for path in os.environ['PATH'].split(os.pathsep):
33 path = path.strip('"')
34 exe_file = os.path.join(path, program)
35 if IsExe(exe_file):
36 return exe_file
37 return None
38
39
40 def Run(command):
41 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.
42 universal_newlines=True)
M-A Ruel 2013/05/13 21:23:42 It's an unconventional alignment, I usually put ev
43 out, err = p.communicate()
44 return p.returncode, out
45
46
47 def EscapeForCommandLineAndCString(path):
48 """Quoted sufficiently to be passed on the compile command line as a define
49 to be turned into a string in the target C program."""
50 path = '"' + path + '"'
51 return path.replace('\\', '\\\\').replace('"', '\\"')
52
53
54 def main():
55 # Switch to our own dir.
56 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.
57
58 link = FindInPath('link.exe')
59 if not link:
60 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.
61 "Visual Studio Command Prompt.")
62 return 1
63
64 link_backup = os.path.join(os.path.split(link)[0], 'link.exe.split_link.exe')
65
66 # Don't re-backup link.exe, so only copy link.exe to backup if it's
67 # not there already.
68 if not os.path.exists(link_backup):
69 try:
70 print 'Saving original link.exe...'
71 shutil.copyfile(link, link_backup)
72 except IOError:
73 print (('Wasn\'t able to back up %s to %s. '
74 'Not running with Administrator privileges?')
75 % (link, link_backup))
76 return 1
77
78 # Build our linker shim.
79 print 'Building split_link.exe...'
80 split_link_py = os.path.abspath('split_link.py')
81 script_path = EscapeForCommandLineAndCString(split_link_py)
82 python = EscapeForCommandLineAndCString(sys.executable)
83 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
84 ' /D_CRT_SECURE_NO_WARNINGS /EHsc split_link.cc'
85 ' /DPYTHON_PATH="%s"'
86 ' /DSPLIT_LINK_SCRIPT_PATH="%s"'
87 ' /link shell32.lib shlwapi.lib /out:split_link.exe' % (
88 python, script_path),
89 shell=True)
90
91 # Copy shim into place.
92 print 'Copying split_link.exe over link.exe...'
93 try:
94 shutil.copyfile('split_link.exe', link)
95 _winreg.SetValue(_winreg.HKEY_CURRENT_USER,
96 'Software\\Chromium\\split_link_installed',
97 _winreg.REG_SZ,
98 link_backup)
99 except IOError:
100 print ('Wasn\'t able to copy split_link.exe over %s. '
101 'Not running with Administrator privileges?' % link)
102 return 1
103
104 return 0
105
106
107 if __name__ == '__main__':
108 sys.exit(main())
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698