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

Side by Side Diff: third_party/instrumented_libraries/download_build_install.py

Issue 723033006: Instrumented libraries: overhaul RPATH handling. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month 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
« no previous file with comments | « no previous file | third_party/instrumented_libraries/fix_rpaths.sh » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/python 1 #!/usr/bin/python
2 # Copyright 2013 The Chromium Authors. All rights reserved. 2 # Copyright 2013 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """Downloads, builds (with instrumentation) and installs shared libraries.""" 6 """Downloads, builds (with instrumentation) and installs shared libraries."""
7 7
8 import argparse 8 import argparse
9 import os 9 import os
10 import platform 10 import platform
(...skipping 12 matching lines...) Expand all
23 23
24 def __enter__(self): 24 def __enter__(self):
25 self.old_path = os.getcwd() 25 self.old_path = os.getcwd()
26 os.chdir(self.path) 26 os.chdir(self.path)
27 return self 27 return self
28 28
29 def __exit__(self, exc_type, exc_value, traceback): 29 def __exit__(self, exc_type, exc_value, traceback):
30 os.chdir(self.old_path) 30 os.chdir(self.old_path)
31 31
32 32
33 script_absolute_path = os.path.dirname(os.path.abspath(__file__))
Alexander Potapenko 2014/11/17 19:29:00 I think global variables are named in CAPITAL_CASE
34
33 def get_script_absolute_path(): 35 def get_script_absolute_path():
34 return os.path.dirname(os.path.abspath(__file__)) 36 return script_absolute_path
35
36 37
37 def get_package_build_dependencies(package): 38 def get_package_build_dependencies(package):
38 command = 'apt-get -s build-dep %s | grep Inst | cut -d " " -f 2' % package 39 command = 'apt-get -s build-dep %s | grep Inst | cut -d " " -f 2' % package
39 command_result = subprocess.Popen(command, stdout=subprocess.PIPE, 40 command_result = subprocess.Popen(command, stdout=subprocess.PIPE,
40 shell=True) 41 shell=True)
41 if command_result.wait(): 42 if command_result.wait():
42 raise Exception('Failed to determine build dependencies for %s' % package) 43 raise Exception('Failed to determine build dependencies for %s' % package)
43 build_dependencies = [l.strip() for l in command_result.stdout] 44 build_dependencies = [l.strip() for l in command_result.stdout]
44 return build_dependencies 45 return build_dependencies
45 46
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 print stdout 80 print stdout
80 if child.returncode: 81 if child.returncode:
81 raise Exception('Failed to run: %s' % command) 82 raise Exception('Failed to run: %s' % command)
82 83
83 84
84 def run_shell_commands(commands, verbose=False, environment=None): 85 def run_shell_commands(commands, verbose=False, environment=None):
85 for command in commands: 86 for command in commands:
86 shell_call(command, verbose, environment) 87 shell_call(command, verbose, environment)
87 88
88 89
90 def fix_rpaths(destdir):
91 # TODO(earthdok): reimplement fix_rpaths.sh in Python.
92 shell_call("%s/fix_rpaths.sh %s/lib" % (get_script_absolute_path(), destdir))
93
94
89 def destdir_configure_make_install(parsed_arguments, environment, 95 def destdir_configure_make_install(parsed_arguments, environment,
90 install_prefix): 96 install_prefix):
91 configure_command = './configure %s' % parsed_arguments.extra_configure_flags 97 configure_command = './configure %s' % parsed_arguments.extra_configure_flags
92 configure_command += ' --libdir=/lib/' 98 configure_command += ' --libdir=/lib/'
93 # Installing to a temporary directory allows us to safely clean up the .la 99 # Installing to a temporary directory allows us to safely clean up the .la
94 # files below. 100 # files below.
95 destdir = '%s/debian/instrumented_build' % os.getcwd() 101 destdir = '%s/debian/instrumented_build' % os.getcwd()
96 # Some makefiles use BUILDROOT instead of DESTDIR. 102 # Some makefiles use BUILDROOT instead of DESTDIR.
97 make_command = 'make DESTDIR=%s BUILDROOT=%s' % (destdir, destdir) 103 make_command = 'make DESTDIR=%s BUILDROOT=%s' % (destdir, destdir)
98 run_shell_commands([ 104 run_shell_commands([
99 configure_command, 105 configure_command,
100 '%s -j%s' % (make_command, parsed_arguments.jobs), 106 '%s -j%s' % (make_command, parsed_arguments.jobs),
101 # Parallel install is flaky for some packages. 107 # Parallel install is flaky for some packages.
102 '%s install -j1' % make_command, 108 '%s install -j1' % make_command,
103 # Kill the .la files. They contain absolute paths, and will cause build 109 # Kill the .la files. They contain absolute paths, and will cause build
104 # errors in dependent libraries. 110 # errors in dependent libraries.
105 'rm %s/lib/*.la -f' % destdir, 111 'rm %s/lib/*.la -f' % destdir],
112 parsed_arguments.verbose, environment)
Alexander Potapenko 2014/11/17 19:29:00 Please fix the indentation.
113 fix_rpaths(destdir)
114 shell_call(
106 # Now move the contents of the temporary destdir to their final place. 115 # Now move the contents of the temporary destdir to their final place.
107 'cp %s/* %s/ -rdf' % (destdir, install_prefix)], 116 'cp %s/* %s/ -rdf' % (destdir, install_prefix),
108 parsed_arguments.verbose, environment) 117 parsed_arguments.verbose, environment)
109 118
110 119
111 def nss_make_and_copy(parsed_arguments, environment, install_prefix): 120 def nss_make_and_copy(parsed_arguments, environment, install_prefix):
112 # NSS uses a build system that's different from configure/make/install. All 121 # NSS uses a build system that's different from configure/make/install. All
113 # flags must be passed as arguments to make. 122 # flags must be passed as arguments to make.
114 make_args = [] 123 make_args = []
115 # Do an optimized build. 124 # Do an optimized build.
116 make_args.append('BUILD_OPT=1') 125 make_args.append('BUILD_OPT=1')
117 # Set USE_64=1 on x86_64 systems. 126 # Set USE_64=1 on x86_64 systems.
118 if platform.architecture()[0] == '64bit': 127 if platform.architecture()[0] == '64bit':
(...skipping 10 matching lines...) Expand all
129 make_args.append('NSPR_INCLUDE_DIR=/usr/include/nspr') 138 make_args.append('NSPR_INCLUDE_DIR=/usr/include/nspr')
130 make_args.append('NSPR_LIB_DIR=%s/lib' % install_prefix) 139 make_args.append('NSPR_LIB_DIR=%s/lib' % install_prefix)
131 make_args.append('NSS_ENABLE_ECC=1') 140 make_args.append('NSS_ENABLE_ECC=1')
132 # Make sure we don't override the default flags. 141 # Make sure we don't override the default flags.
133 for variable in ['CFLAGS', 'CXXFLAGS', 'LDFLAGS']: 142 for variable in ['CFLAGS', 'CXXFLAGS', 'LDFLAGS']:
134 del environment[variable] 143 del environment[variable]
135 with ScopedChangeDirectory('nss') as cd_nss: 144 with ScopedChangeDirectory('nss') as cd_nss:
136 # -j is not supported 145 # -j is not supported
137 shell_call('make %s' % ' '.join(make_args), parsed_arguments.verbose, 146 shell_call('make %s' % ' '.join(make_args), parsed_arguments.verbose,
138 environment) 147 environment)
148 fix_rpaths(os.getcwd())
139 # 'make install' is not supported. Copy the DSOs manually. 149 # 'make install' is not supported. Copy the DSOs manually.
140 install_dir = '%s/lib/' % install_prefix 150 install_dir = '%s/lib/' % install_prefix
141 for (dirpath, dirnames, filenames) in os.walk('./lib/'): 151 for (dirpath, dirnames, filenames) in os.walk('./lib/'):
142 for filename in filenames: 152 for filename in filenames:
143 if filename.endswith('.so'): 153 if filename.endswith('.so'):
144 full_path = os.path.join(dirpath, filename) 154 full_path = os.path.join(dirpath, filename)
145 if parsed_arguments.verbose: 155 if parsed_arguments.verbose:
146 print 'download_build_install.py: installing %s' % full_path 156 print 'download_build_install.py: installing %s' % full_path
147 shutil.copy(full_path, install_dir) 157 shutil.copy(full_path, install_dir)
148 158
149 159
150 def libcap2_make_install(parsed_arguments, environment, install_prefix): 160 def libcap2_make_install(parsed_arguments, environment, install_prefix):
151 # libcap2 doesn't come with a configure script 161 # libcap2 doesn't come with a configure script
152 make_args = [ 162 make_args = [
153 '%s="%s"' % (name, environment[name]) 163 '%s="%s"' % (name, environment[name])
154 for name in['CC', 'CXX', 'CFLAGS', 'CXXFLAGS', 'LDFLAGS']] 164 for name in['CC', 'CXX', 'CFLAGS', 'CXXFLAGS', 'LDFLAGS']]
155 shell_call('make -j%s %s' % (parsed_arguments.jobs, ' '.join(make_args)), 165 shell_call('make -j%s %s' % (parsed_arguments.jobs, ' '.join(make_args)),
156 parsed_arguments.verbose, environment) 166 parsed_arguments.verbose, environment)
167 destdir = '%s/debian/instrumented_build' % os.getcwd()
157 install_args = [ 168 install_args = [
158 'DESTDIR=%s' % install_prefix, 169 'DESTDIR=%s' % destdir,
159 # Do not install in lib64/. 170 # Do not install in lib64/.
160 'lib=lib', 171 'lib=lib',
161 # Skip a step that requires sudo. 172 # Skip a step that requires sudo.
162 'RAISE_SETFCAP=no' 173 'RAISE_SETFCAP=no'
163 ] 174 ]
164 shell_call('make -j%s install %s' % 175 shell_call('make -j%s install %s' %
165 (parsed_arguments.jobs, ' '.join(install_args)), 176 (parsed_arguments.jobs, ' '.join(install_args)),
166 parsed_arguments.verbose, environment) 177 parsed_arguments.verbose, environment)
178 fix_rpaths(destdir)
179 shell_call([
180 # Now move the contents of the temporary destdir to their final place.
181 'cp %s/* %s/ -rdf' % (destdir, install_prefix)],
182 parsed_arguments.verbose, environment)
167 183
168 184
169 def libpci3_make_install(parsed_arguments, environment, install_prefix): 185 def libpci3_make_install(parsed_arguments, environment, install_prefix):
170 # pciutils doesn't have a configure script 186 # pciutils doesn't have a configure script
171 # This build script follows debian/rules. 187 # This build script follows debian/rules.
172 188
173 # Find out the package version. We'll use this when creating symlinks. 189 # Find out the package version. We'll use this when creating symlinks.
174 dir_name = os.path.split(os.getcwd())[-1] 190 dir_name = os.path.split(os.getcwd())[-1]
175 match = re.match('pciutils-(\d+\.\d+\.\d+)', dir_name) 191 match = re.match('pciutils-(\d+\.\d+\.\d+)', dir_name)
176 if match is None: 192 if match is None:
(...skipping 19 matching lines...) Expand all
196 'IDSDIR=/usr/share/misc', 212 'IDSDIR=/usr/share/misc',
197 ] 213 ]
198 install_args = ['DESTDIR=%s' % destdir] 214 install_args = ['DESTDIR=%s' % destdir]
199 run_shell_commands([ 215 run_shell_commands([
200 'mkdir -p %s-udeb/usr/bin' % destdir, 216 'mkdir -p %s-udeb/usr/bin' % destdir,
201 'make -j%s %s' % (parsed_arguments.jobs, ' '.join(make_args + paths)), 217 'make -j%s %s' % (parsed_arguments.jobs, ' '.join(make_args + paths)),
202 'make -j%s %s install' % ( 218 'make -j%s %s install' % (
203 parsed_arguments.jobs, 219 parsed_arguments.jobs,
204 ' '.join(install_args + paths))], 220 ' '.join(install_args + paths))],
205 parsed_arguments.verbose, environment) 221 parsed_arguments.verbose, environment)
222 fix_rpaths(destdir)
206 # Now move the contents of the temporary destdir to their final place. 223 # Now move the contents of the temporary destdir to their final place.
207 run_shell_commands([ 224 run_shell_commands([
208 'cp %s/* %s/ -rd' % (destdir, install_prefix), 225 'cp %s/* %s/ -rd' % (destdir, install_prefix),
209 'install -m 644 lib/libpci.so* %s/lib/' % install_prefix, 226 'install -m 644 lib/libpci.so* %s/lib/' % install_prefix,
210 'ln -sf libpci.so.%s %s/lib/libpci.so.3' % (version, install_prefix)], 227 'ln -sf libpci.so.%s %s/lib/libpci.so.3' % (version, install_prefix)],
211 parsed_arguments.verbose, environment) 228 parsed_arguments.verbose, environment)
212 229
213 230
214 def build_and_install(parsed_arguments, environment, install_prefix): 231 def build_and_install(parsed_arguments, environment, install_prefix):
215 if parsed_arguments.build_method == 'destdir': 232 if parsed_arguments.build_method == 'destdir':
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 os.chdir(get_script_absolute_path()) 391 os.chdir(get_script_absolute_path())
375 # Ensure all build dependencies are installed. 392 # Ensure all build dependencies are installed.
376 if parsed_arguments.check_build_deps: 393 if parsed_arguments.check_build_deps:
377 check_package_build_dependencies(parsed_arguments.package) 394 check_package_build_dependencies(parsed_arguments.package)
378 395
379 download_build_install(parsed_arguments) 396 download_build_install(parsed_arguments)
380 397
381 398
382 if __name__ == '__main__': 399 if __name__ == '__main__':
383 main() 400 main()
OLDNEW
« no previous file with comments | « no previous file | third_party/instrumented_libraries/fix_rpaths.sh » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698