| Index: build/linux/sysroot_scripts/generate_precise_dpkg_admin_dir.py
|
| diff --git a/build/linux/sysroot_scripts/generate_precise_dpkg_admin_dir.py b/build/linux/sysroot_scripts/generate_precise_dpkg_admin_dir.py
|
| new file mode 100755
|
| index 0000000000000000000000000000000000000000..70723428f9af8e768a5fbe45a5144e0f7d98cbb3
|
| --- /dev/null
|
| +++ b/build/linux/sysroot_scripts/generate_precise_dpkg_admin_dir.py
|
| @@ -0,0 +1,137 @@
|
| +#!/usr/bin/env python
|
| +# Copyright 2014 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.
|
| +
|
| +# Takes in a Ubuntu Precise dpkg admin directory (typically /var/lib/dpkg) and
|
| +# outputs a dpkg admin directory appropriate for use with dpkg-shlibdeps on
|
| +# Ubuntu Trusty.
|
| +#
|
| +# Example usage:
|
| +# generate_precise_dpkg_admin_dir.py --arch i386 \
|
| +# /path/to/precise_32-bit_chroot/var/lib/dpkg /path/to/dest_dir
|
| +
|
| +import optparse
|
| +import os
|
| +import shutil
|
| +import string
|
| +import subprocess
|
| +import sys
|
| +
|
| +
|
| +SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
|
| +
|
| +
|
| +def ParseStatusFile(status_file):
|
| + package_map = {}
|
| + lines = open(status_file).readlines()
|
| + current_package_name = ''
|
| + current_package_data = ''
|
| + for line in lines:
|
| + if (not line or
|
| + line[0] not in string.ascii_uppercase or
|
| + line.startswith('Homepage: ') or
|
| + line.startswith('Original-Maintainer: ')):
|
| + continue
|
| + if line.startswith('Package: '):
|
| + if current_package_name:
|
| + package_map[current_package_name] = current_package_data
|
| + current_package_name = line[len('Package: '):].strip()
|
| + current_package_data = ''
|
| + else:
|
| + current_package_data += line
|
| + if current_package_name:
|
| + package_map[current_package_name] = current_package_data
|
| + return package_map
|
| +
|
| +
|
| +def main():
|
| + if options.arch not in ['amd64', 'i386']:
|
| + print 'Unknown architecture: %s' % options.arch
|
| + return 1
|
| +
|
| + if len(args) != 2:
|
| + print 'Wrong number of arguments.'
|
| + return 1
|
| +
|
| + src_dir = args[0]
|
| + dest_dir = args[1]
|
| +
|
| + sysroot_script = os.path.join(SCRIPT_DIR, 'sysroot-creator-precise.sh')
|
| + sysroot_arg = {'amd64': 'ListPackagesAmd64', 'i386': 'ListPackagesI386'} \
|
| + [options.arch]
|
| + packages_file = os.path.join(dest_dir, 'packagelist.' + options.arch)
|
| + subprocess.check_call([sysroot_script, sysroot_arg, packages_file])
|
| + packages = open(packages_file, 'r').read().splitlines()
|
| + os.remove(packages_file)
|
| +
|
| + # Remove dev packages. This does not get rid of all packages that we don't
|
| + # need, but is conservative.
|
| + packages = [package for package in packages if not package.endswith('-dev')]
|
| +
|
| + src_status_file = os.path.join(src_dir, 'status')
|
| + src_info_dir = os.path.join(src_dir, 'info')
|
| + src_info_format_file = os.path.join(src_info_dir, 'format')
|
| + src_triggers_dir = os.path.join(src_dir, 'triggers')
|
| + src_updates_dir = os.path.join(src_dir, 'updates')
|
| + if not os.path.isfile(src_status_file):
|
| + print 'status file not found. (%s)' % src_status_file
|
| + return 1
|
| + if not os.path.isdir(src_info_dir):
|
| + print 'info dir not found. (%s)' % src_info_dir
|
| + return 1
|
| + if not os.path.isfile(src_info_format_file):
|
| + print 'info format file not found. (%s)' % src_info_format_file
|
| + return 1
|
| + if not os.path.isdir(src_triggers_dir):
|
| + print 'triggers dir not found. (%s)' % src_triggers_dir
|
| + return 1
|
| + if not os.path.isdir(src_updates_dir):
|
| + print 'updates dir not found. (%s)' % src_updates_dir
|
| + return 1
|
| +
|
| + package_map = ParseStatusFile(src_status_file)
|
| + missing_packages = []
|
| + for package in packages:
|
| + if package not in package_map:
|
| + missing_packages.append(package)
|
| + if missing_packages:
|
| + print 'Missing packages: %s' % ','.join(missing_packages)
|
| + return 1
|
| +
|
| + dest_status_file = os.path.join(dest_dir, 'status')
|
| + dest_info_dir = os.path.join(dest_dir, 'info')
|
| + dest_info_format_file = os.path.join(dest_info_dir, 'format')
|
| + dest_triggers_dir = os.path.join(dest_dir, 'triggers')
|
| + dest_updates_dir = os.path.join(dest_dir, 'updates')
|
| +
|
| + os.makedirs(dest_info_dir)
|
| + shutil.copy(src_info_format_file, dest_info_format_file)
|
| + shutil.copytree(src_triggers_dir, dest_triggers_dir,
|
| + ignore=shutil.ignore_patterns('Lock'))
|
| + shutil.copytree(src_updates_dir, dest_updates_dir)
|
| +
|
| + with open(dest_status_file, 'w') as dest_status_file_handle:
|
| + for package in packages:
|
| + dest_status_file_handle.write('Package: %s\n' % package)
|
| + dest_status_file_handle.write(package_map[package])
|
| + dest_status_file_handle.write('\n')
|
| +
|
| + for package in packages:
|
| + for extension in ('shlibs', 'symbols'):
|
| + dest_filename = '%s:%s.%s' % (package, options.arch, extension)
|
| + src_filename = dest_filename
|
| + src_file = os.path.join(src_info_dir, src_filename)
|
| + dest_file = os.path.join(dest_info_dir, dest_filename)
|
| + if not os.path.isfile(src_file):
|
| + continue
|
| + shutil.copy(src_file, dest_file)
|
| +
|
| + return 0
|
| +
|
| +
|
| +if __name__ == '__main__':
|
| + parser = optparse.OptionParser('usage: %prog --arch ARCH SRC DEST')
|
| + parser.add_option('--arch', help='Sysroot architecture: i386 or amd64')
|
| + options, args = parser.parse_args()
|
| + sys.exit(main())
|
|
|