OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/env python |
| 2 # Copyright 2014 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 # Takes in a Ubuntu Precise dpkg admin directory (typically /var/lib/dpkg) and |
| 7 # outputs a dpkg admin directory appropriate for use with dpkg-shlibdeps on |
| 8 # Ubuntu Trusty. |
| 9 # |
| 10 # Example usage: |
| 11 # generate_precise_dpkg_admin_dir.py --arch i386 \ |
| 12 # /path/to/precise_32-bit_chroot/var/lib/dpkg /path/to/dest_dir |
| 13 |
| 14 import optparse |
| 15 import os |
| 16 import shutil |
| 17 import string |
| 18 import subprocess |
| 19 import sys |
| 20 |
| 21 |
| 22 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) |
| 23 |
| 24 |
| 25 def ParseStatusFile(status_file): |
| 26 package_map = {} |
| 27 lines = open(status_file).readlines() |
| 28 current_package_name = '' |
| 29 current_package_data = '' |
| 30 for line in lines: |
| 31 if (not line or |
| 32 line[0] not in string.ascii_uppercase or |
| 33 line.startswith('Homepage: ') or |
| 34 line.startswith('Original-Maintainer: ')): |
| 35 continue |
| 36 if line.startswith('Package: '): |
| 37 if current_package_name: |
| 38 package_map[current_package_name] = current_package_data |
| 39 current_package_name = line[len('Package: '):].strip() |
| 40 current_package_data = '' |
| 41 else: |
| 42 current_package_data += line |
| 43 if current_package_name: |
| 44 package_map[current_package_name] = current_package_data |
| 45 return package_map |
| 46 |
| 47 |
| 48 def main(): |
| 49 if options.arch not in ['amd64', 'i386']: |
| 50 print 'Unknown architecture: %s' % options.arch |
| 51 return 1 |
| 52 |
| 53 if len(args) != 2: |
| 54 print 'Wrong number of arguments.' |
| 55 return 1 |
| 56 |
| 57 src_dir = args[0] |
| 58 dest_dir = args[1] |
| 59 |
| 60 sysroot_script = os.path.join(SCRIPT_DIR, 'sysroot-creator-precise.sh') |
| 61 sysroot_arg = {'amd64': 'ListPackagesAmd64', 'i386': 'ListPackagesI386'} \ |
| 62 [options.arch] |
| 63 packages_file = os.path.join(dest_dir, 'packagelist.' + options.arch) |
| 64 subprocess.check_call([sysroot_script, sysroot_arg, packages_file]) |
| 65 packages = open(packages_file, 'r').read().splitlines() |
| 66 os.remove(packages_file) |
| 67 |
| 68 # Remove dev packages. This does not get rid of all packages that we don't |
| 69 # need, but is conservative. |
| 70 packages = [package for package in packages if not package.endswith('-dev')] |
| 71 |
| 72 src_status_file = os.path.join(src_dir, 'status') |
| 73 src_info_dir = os.path.join(src_dir, 'info') |
| 74 src_info_format_file = os.path.join(src_info_dir, 'format') |
| 75 src_triggers_dir = os.path.join(src_dir, 'triggers') |
| 76 src_updates_dir = os.path.join(src_dir, 'updates') |
| 77 if not os.path.isfile(src_status_file): |
| 78 print 'status file not found. (%s)' % src_status_file |
| 79 return 1 |
| 80 if not os.path.isdir(src_info_dir): |
| 81 print 'info dir not found. (%s)' % src_info_dir |
| 82 return 1 |
| 83 if not os.path.isfile(src_info_format_file): |
| 84 print 'info format file not found. (%s)' % src_info_format_file |
| 85 return 1 |
| 86 if not os.path.isdir(src_triggers_dir): |
| 87 print 'triggers dir not found. (%s)' % src_triggers_dir |
| 88 return 1 |
| 89 if not os.path.isdir(src_updates_dir): |
| 90 print 'updates dir not found. (%s)' % src_updates_dir |
| 91 return 1 |
| 92 |
| 93 package_map = ParseStatusFile(src_status_file) |
| 94 missing_packages = [] |
| 95 for package in packages: |
| 96 if package not in package_map: |
| 97 missing_packages.append(package) |
| 98 if missing_packages: |
| 99 print 'Missing packages: %s' % ','.join(missing_packages) |
| 100 return 1 |
| 101 |
| 102 dest_status_file = os.path.join(dest_dir, 'status') |
| 103 dest_info_dir = os.path.join(dest_dir, 'info') |
| 104 dest_info_format_file = os.path.join(dest_info_dir, 'format') |
| 105 dest_triggers_dir = os.path.join(dest_dir, 'triggers') |
| 106 dest_updates_dir = os.path.join(dest_dir, 'updates') |
| 107 |
| 108 os.makedirs(dest_info_dir) |
| 109 shutil.copy(src_info_format_file, dest_info_format_file) |
| 110 shutil.copytree(src_triggers_dir, dest_triggers_dir, |
| 111 ignore=shutil.ignore_patterns('Lock')) |
| 112 shutil.copytree(src_updates_dir, dest_updates_dir) |
| 113 |
| 114 with open(dest_status_file, 'w') as dest_status_file_handle: |
| 115 for package in packages: |
| 116 dest_status_file_handle.write('Package: %s\n' % package) |
| 117 dest_status_file_handle.write(package_map[package]) |
| 118 dest_status_file_handle.write('\n') |
| 119 |
| 120 for package in packages: |
| 121 for extension in ('shlibs', 'symbols'): |
| 122 dest_filename = '%s:%s.%s' % (package, options.arch, extension) |
| 123 src_filename = dest_filename |
| 124 src_file = os.path.join(src_info_dir, src_filename) |
| 125 dest_file = os.path.join(dest_info_dir, dest_filename) |
| 126 if not os.path.isfile(src_file): |
| 127 continue |
| 128 shutil.copy(src_file, dest_file) |
| 129 |
| 130 return 0 |
| 131 |
| 132 |
| 133 if __name__ == '__main__': |
| 134 parser = optparse.OptionParser('usage: %prog --arch ARCH SRC DEST') |
| 135 parser.add_option('--arch', help='Sysroot architecture: i386 or amd64') |
| 136 options, args = parser.parse_args() |
| 137 sys.exit(main()) |
OLD | NEW |