OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # Copyright (c) 2010 The Native Client Authors. All rights reserved. | 2 # Copyright (c) 2010 The Native Client Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that be | 3 # Use of this source code is governed by a BSD-style license that be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """Install GTest and GMock that can be linked to a NaCl module. By default | 6 """Install GTest and GMock that can be linked to a NaCl module. By default |
7 this script builds both the 32- and 64-bit versions of the libraries, and | 7 this script builds both the 32- and 64-bit versions of the libraries, and |
8 installs them in <toolchain>/nacl/usr/lib and <toolchain>/nacl64/usr/lib. The | 8 installs them in <toolchain>/nacl/usr/lib and <toolchain>/nacl64/usr/lib. The |
9 header files are also installed in <toolchain>/<ncal_spec>/usr/include. | 9 header files are also installed in <toolchain>/<ncal_spec>/usr/include. |
10 """ | 10 """ |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 print "Error retrieving %s" % url | 66 print "Error retrieving %s" % url |
67 raise | 67 raise |
68 | 68 |
69 os.chdir(options.old_cwd) | 69 os.chdir(options.old_cwd) |
70 | 70 |
71 | 71 |
72 # Apply the patch files to the extracted GTest and GMock pacakges. | 72 # Apply the patch files to the extracted GTest and GMock pacakges. |
73 def PatchAll(options): | 73 def PatchAll(options): |
74 def Patch(abs_path, patch_file): | 74 def Patch(abs_path, patch_file): |
75 print "Patching %s with: %s" % (abs_path, patch_file) | 75 print "Patching %s with: %s" % (abs_path, patch_file) |
76 p = subprocess.Popen('chmod -R a+w . && patch -p0 < %s' % (patch_file), | 76 command = '' |
| 77 if (sys.platform == 'win32'): |
| 78 command = 'patch -p0 < %s' % (patch_file) |
| 79 else: |
| 80 command = 'chmod -R a+w . && patch -p0 < %s' % (patch_file) |
| 81 p = subprocess.Popen(command, |
77 cwd=abs_path, | 82 cwd=abs_path, |
78 env=options.shell_env, | 83 env=options.shell_env, |
79 shell=True) | 84 shell=True) |
80 assert p.wait() == 0 | 85 assert p.wait() == 0 |
81 | 86 |
82 Patch(options.working_dir, os.path.join(options.script_dir, GTEST_PATCH_FILE)) | 87 patch_path = os.path.join(options.script_dir, GTEST_PATCH_FILE) |
83 Patch(options.working_dir, os.path.join(options.script_dir, GMOCK_PATCH_FILE)) | 88 print 'about to patch with working_dir %s, patch: %s' % (options.working_dir, |
| 89 patch_path) |
| 90 Patch(options.working_dir, patch_path) |
| 91 Patch(options.working_dir, patch_path) |
84 | 92 |
85 | 93 |
86 # Build GTest and GMock, then install them into the toolchain. Note that | 94 # Build GTest and GMock, then install them into the toolchain. Note that |
87 # GTest has to be built and installed into the toolchain before GMock can be | 95 # GTest has to be built and installed into the toolchain before GMock can be |
88 # built, because GMock relies on headers from GTest. This method sets up all | 96 # built, because GMock relies on headers from GTest. This method sets up all |
89 # the necessary shell environment variables for the makefiles, such as CC and | 97 # the necessary shell environment variables for the makefiles, such as CC and |
90 # CXX. | 98 # CXX. |
91 def BuildAndInstallAll(options): | 99 def BuildAndInstallAll(options): |
92 def BuildInPath(abs_path, shell_env): | 100 def BuildInPath(abs_path, shell_env): |
93 # Run make clean and make in |abs_path|. Assumes there is a makefile in | 101 # Run make clean and make in |abs_path|. Assumes there is a makefile in |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 shell=True, | 187 shell=True, |
180 stdin=tar_cf.stdout) | 188 stdin=tar_cf.stdout) |
181 tar_copy_err = tar_xf.communicate()[1] | 189 tar_copy_err = tar_xf.communicate()[1] |
182 InstallLib('libgmock.a', gmock_path, nacl_usr_lib, build_env) | 190 InstallLib('libgmock.a', gmock_path, nacl_usr_lib, build_env) |
183 | 191 |
184 | 192 |
185 # Main driver method that creates a working directory, then downloads and | 193 # Main driver method that creates a working directory, then downloads and |
186 # extracts GTest and GMock, patches and builds them both, then installs them | 194 # extracts GTest and GMock, patches and builds them both, then installs them |
187 # into the toolchain specified in |options.toolchain|. | 195 # into the toolchain specified in |options.toolchain|. |
188 def InstallTestingLibs(options): | 196 def InstallTestingLibs(options): |
| 197 print 'Making working directory.' |
189 MakeWorkingDir(options) | 198 MakeWorkingDir(options) |
190 try: | 199 try: |
| 200 print 'Downloading and Extracting gtest.' |
191 DownloadAndExtractAll(options) | 201 DownloadAndExtractAll(options) |
| 202 print 'Patching gtest.' |
192 PatchAll(options) | 203 PatchAll(options) |
193 except: | 204 except: |
| 205 # TODO(mlinck) improve this error |
| 206 print 'An Error occurred' |
194 return 1 | 207 return 1 |
195 | 208 |
| 209 print 'Building and installing gtest.' |
196 BuildAndInstallAll(options) | 210 BuildAndInstallAll(options) |
197 # Clean up. | 211 # Clean up. |
| 212 print 'Cleaning up gtest install files.' |
198 shutil.rmtree(options.working_dir, ignore_errors=True) | 213 shutil.rmtree(options.working_dir, ignore_errors=True) |
199 return 0 | 214 return 0 |
200 | 215 |
201 | 216 |
202 # Parse the command-line args and set up the options object. There are two | 217 # Parse the command-line args and set up the options object. There are two |
203 # command-line switches: | 218 # command-line switches: |
204 # --toolchain=<path to the platform-specific toolchain> | 219 # --toolchain=<path to the platform-specific toolchain> |
205 # e.g.: --toolchain=../toolchain/mac-x86 | 220 # e.g.: --toolchain=../toolchain/mac-x86 |
206 # default is |TOOLCHAIN_AUTODETECT| which means try to determine | 221 # default is |TOOLCHAIN_AUTODETECT| which means try to determine |
207 # the toolchain dir from |sys.platform|. | 222 # the toolchain dir from |sys.platform|. |
(...skipping 24 matching lines...) Expand all Loading... |
232 options.shell_env = shell_env | 247 options.shell_env = shell_env |
233 options.script_dir = os.path.abspath(os.path.dirname(__file__)) | 248 options.script_dir = os.path.abspath(os.path.dirname(__file__)) |
234 options.toolchain = build_utils.NormalizeToolchain(options.toolchain) | 249 options.toolchain = build_utils.NormalizeToolchain(options.toolchain) |
235 print "Installing testing libs into toolchain %s" % options.toolchain | 250 print "Installing testing libs into toolchain %s" % options.toolchain |
236 | 251 |
237 return InstallTestingLibs(options) | 252 return InstallTestingLibs(options) |
238 | 253 |
239 | 254 |
240 if __name__ == '__main__': | 255 if __name__ == '__main__': |
241 main(sys.argv[1:]) | 256 main(sys.argv[1:]) |
OLD | NEW |