X-Git-Url: http://www.project-moonshot.org/gitweb/?a=blobdiff_plain;f=debian-builder;h=c778fd4b85e870d2da699a98ceff4d2a2e161215;hb=refs%2Fheads%2Fdebian;hp=1a1830da2a518712d2492d7ad364fdce16f92781;hpb=da4e2fa65e9a3017b695a00d55f00a6c5392b225;p=moonshot.git diff --git a/debian-builder b/debian-builder index 1a1830d..c778fd4 100755 --- a/debian-builder +++ b/debian-builder @@ -19,9 +19,15 @@ import debian.changelog, debian.deb822 # These variables can be overridden by options. If packages is not # set, then it is read from the source_packages file packages = [] # Set of packages to build -distribution = "sid" +distribution = "unstable" build_place = os.path.join(os.getcwd(), 'debian_build') +suffix_map = { + 'wheezy': 'deb70', + 'jessie': 'deb80', + 'unstable': 'sid', + 'sid': 'sid'} + class CommandError(exceptions.StandardError): pass @@ -59,13 +65,17 @@ def build(package): with current_directory(package): cl = debian.changelog.Changelog(open('debian/changelog')) package_name = cl.package - package_version = str(cl.version) - orig_tgz = package_name+'_'+ cl.upstream_version + ".orig.tar.gz" - dsc_name = package_name+"_"+package_version + ".dsc" + package_version = re.sub('^\d+:','',str(cl.version)) + orig_tar = package_name+'_'+ cl.upstream_version + ".orig.tar" + dsc_name = package_name+"_"+package_version + '~' + version_suffix+ ".dsc" + run_cmd(['dch', '-b', '-v' +str(cl.version)+'~'+version_suffix, '-D'+distribution, 'Autobuilt package']) print "==> Package: ", package_name source_format = command_output(('dpkg-source', '--print-format', '.')) if "native" not in source_format: - run_cmd( ('pristine-tar', 'checkout', '../'+orig_tgz)) + run_cmd( ('git', 'fetch', 'origin', 'pristine-tar:pristine-tar')) + for file in command_output(( 'pristine-tar', 'list')).split("\n"): + if file.startswith(orig_tar): orig_tar = file + run_cmd( ('pristine-tar', 'checkout', '../'+orig_tar)) package_path = os.path.split(package) with current_directory(os.path.join ('.', *package_path[0:len(package_path)-1])) : package_path = package_path[len(package_path)-1] @@ -77,6 +87,7 @@ def build(package): for f in dsc_files(dsc_name): try: os.unlink(f) except OSError: pass + with current_directory(package_path): run_cmd('git checkout debian/changelog', shell=True) with current_directory(build_place): sb = ['sbuild', '-n', '-d', distribution, '--setup-hook', build_place + '/add_source'] @@ -89,21 +100,10 @@ def build(package): def gen_package_files() : '''Generate package files in build_place and a script build_place/add_source that can be used as a sbuild setup hook to - include the package files. Unfortunately, apt doesn't have a - mechanism for asserting that a package file is trusted when it is - local. We could generate a unique gpg key, generate signed - releases files and trust that key. It's easier to simply touch the - release.gpg in apt's lists directory, which turns out to do what - we need.''' - # Rather than substuting the release file directly, we create gpg - # release files for any local package list. That's easier than - # encoding apt's ideas about what characters to escape. + include the package files. Use the sbuild key to sign our packages''' script = '''#!/bin/sh set -e - echo deb file:{build_place} ./ >>/etc/apt/sources.list - apt-get update - touch $(ls /var/lib/apt/lists/_*Packages \ - |sed -e s:Packages\$:Release.gpg:) + sudo -u root /usr/local/sbin/add-source {build_place} '''.format ( build_place = build_place ) @@ -114,6 +114,10 @@ def gen_package_files() : run_cmd(('chmod', 'a+x', 'add_source')) run_cmd( 'dpkg-scanpackages . >Packages', shell = True) + run_cmd('apt-ftparchive release . >Release', shell=True) + try: os.unlink('Release.gpg') + except OSError: pass + run_cmd( 'gpg -sabt -o Release.gpg --secret-keyring /var/lib/sbuild/apt-keys/sbuild-key.sec --keyring /var/lib/sbuild/apt-keys/sbuild-key.pub Release', shell=True) def read_packages(): @@ -137,6 +141,7 @@ opt = OptionParser() opt.add_option('-b', '--build-place', dest='build_place', help="Write resulting packages to BUILD_PLACE", default=build_place) +opt.add_option('--version-suffix', dest ='version_suffix') opt.add_option('-d', '--distribution', help="Set the Debian distribution to DISTRIBUTION", dest="distribution", @@ -145,23 +150,37 @@ opt.add_option('-d', '--distribution', opt.add_option('-s', '--sbuild-opt', action='append', dest='sbuild_opts', help='Specify an option to be sent to sbuild') +opt.add_option('--tar-file', + dest='tar_file', + help = 'Tar up resulting packages in given tar file', + default = None) opt.usage = "%prog [options] [packages]" (options, packages) = opt.parse_args() build_place = options.build_place distribution = options.distribution +version_suffix = options.version_suffix +if not version_suffix: version_suffix = suffix_map.get(distribution, '0') sbuild_opts = options.sbuild_opts +tar_file = options.tar_file + if len(packages) == 0: packages = read_packages() try: os.makedirs(build_place) except OSError: pass +code = 0 try: for p in packages: gen_package_files() build(p) except CommandError as c: print "Error:" + str(c.args) - exit(1) - - + code = 1 +finally: + if tar_file is not None: + with current_directory(build_place): + run_cmd('tar -cf '+tar_file+' .', + shell=True) + +sys.exit(code)