aheinecke@376: # Copyright (C) 2010 by Intevation GmbH aheinecke@376: # Authors: aheinecke@376: # Andre Heinecke aheinecke@376: # aheinecke@376: # This program is free software under the GPL (>=v2) aheinecke@376: # Read the file COPYING coming with the software for details. aheinecke@376: aheinecke@376: """Recipe to build DBus from Git""" aheinecke@376: aheinecke@376: import os aheinecke@376: import re aheinecke@376: import inspect aheinecke@376: import new aheinecke@376: aheinecke@376: import treepkg.util aheinecke@376: import treepkg.packager aheinecke@376: import treepkg.run as run aheinecke@376: from treepkg.cmdexpand import cmdexpand aheinecke@376: aheinecke@376: class SourcePackager(treepkg.packager.SourcePackager): aheinecke@376: aheinecke@376: """SourcePackager that uses pbuilder to create the source tarball""" aheinecke@376: aheinecke@376: tarball_dependencies=set(["autoconf", "automake","git-core", "git", aheinecke@376: "libexpat-ce-arm-dev"]) aheinecke@376: createtarball_script = """\ aheinecke@376: #! /bin/bash aheinecke@376: #set -e aheinecke@376: aheinecke@376: apt-get --assume-yes --force-yes install %(builddeps)s aheinecke@376: aheinecke@376: # copy the source tree to a directory that's under pbuilder control so aheinecke@376: # that it gets removed along with the build environment. Otherwise we aheinecke@376: # end up with a directory containing files that cannot be removed by aheinecke@376: # treepkg aheinecke@376: workdir=/tmp/work aheinecke@376: cp -a %(basedir)s $workdir aheinecke@376: cd $workdir aheinecke@376: aheinecke@376: export MINGWPATH=/opt/mingw32ce aheinecke@376: export INCLUDE=$MINGWPATH/arm-mingw32ce/include:$MINGWPATH/include:$INCLUDE aheinecke@376: export LIB=$MINGWPATH/arm-mingw32ce/lib:$MINGWPATH/lib:$LIB aheinecke@376: export PATH=:$PATH:$MINGWPATH/bin:$MINGWPATH/arm-mingw32ce/bin:\ aheinecke@376: $MINGWPATH/libexec/gcc/arm-mingw32ce/4.4.0 aheinecke@376: export LDFLAGS=-L$MINGWPATH/lib aheinecke@376: export CFLAGS=-I$MINGWPATH/include aheinecke@376: export CPPFLAGS=-I$MINGWPATH/include aheinecke@376: aheinecke@376: ./autogen.sh --enable-maintainer-mode --host=arm-mingw32ce aheinecke@376: %(make_dist_command)s aheinecke@376: echo "origtargz " %(origtargz)s aheinecke@376: mv *.tar.gz %(origtargz)s aheinecke@376: """ aheinecke@376: aheinecke@376: make_dist_command = "make dist" aheinecke@376: aheinecke@376: def __init__(self, *args): aheinecke@376: super(SourcePackager, self).__init__(*args) aheinecke@376: self.pkgbasename = None aheinecke@376: self.pkgbaseversion = None aheinecke@376: self.origtargz = None aheinecke@376: aheinecke@376: def orig_source_version(self, directory): aheinecke@376: """Determines the version from configure.in""" aheinecke@376: major = run.capture_output(cmdexpand("/bin/sh -c \"cat configure.in | \ aheinecke@376: grep dbus_major_version\] | \ aheinecke@376: awk -F \[ '{print $$3}'\""), aheinecke@376: cwd=directory)[:1] aheinecke@376: minor = run.capture_output(cmdexpand("/bin/sh -c \"cat configure.in | \ aheinecke@376: grep dbus_minor_version\] | \ aheinecke@376: awk -F \[ '{print $$3}'\""), aheinecke@376: cwd=directory)[:1] aheinecke@376: micro = run.capture_output(cmdexpand("/bin/sh -c \"cat configure.in | \ aheinecke@376: grep dbus_micro_version\] | \ aheinecke@376: awk -F \[ '{print $$3}'\""), aheinecke@376: cwd=directory)[:1] aheinecke@376: if not major or not minor or not micro: aheinecke@376: raise RuntimeError("Could not determine version from \ aheinecke@376: %s/configure.in" % directory) aheinecke@376: return "%s.%s.%s" % (major[:1],minor[:1],micro[:1]) aheinecke@376: aheinecke@376: def determine_package_version(self, directory): aheinecke@376: """ Returns a Git package Name """ aheinecke@376: date = run.capture_output(cmdexpand("/bin/sh -c \" git log --date=iso \ aheinecke@376: -n 1 | grep Date \ aheinecke@376: | awk \'{print $$2}\'\""), aheinecke@376: cwd=directory) aheinecke@376: time = run.capture_output(cmdexpand("/bin/sh -c \" git log --date=iso \ aheinecke@376: -n 1 | grep Date \ aheinecke@376: | awk \'{print $$3}\'\""), aheinecke@376: cwd=directory) aheinecke@376: date = date.replace('-','') aheinecke@376: time = time.replace(':','') aheinecke@376: return "%s-%s%s.%s" % (self.orig_source_version(directory), aheinecke@376: date[:8], time[:4], self.revision[:7]) aheinecke@376: aheinecke@376: def copy_workingcopy(self, dest): aheinecke@376: treepkg.util.copytree(self.track.checkout_dir, dest) aheinecke@376: aheinecke@376: def create_original_tarball(self): aheinecke@376: copied_working_copy = os.path.join(self.work_dir, "copied_working_copy") aheinecke@376: self.copy_workingcopy(copied_working_copy) aheinecke@376: aheinecke@376: self.pkgbaseversion = \ aheinecke@376: self.determine_package_version(copied_working_copy) aheinecke@376: self.pkgbasename = self.pkg_basename + "_" + self.pkgbaseversion aheinecke@376: self.origtargz = os.path.join(self.work_dir, aheinecke@376: self.pkgbasename + ".orig.tar.gz") aheinecke@376: aheinecke@376: script = (self.createtarball_script aheinecke@376: % dict(builddeps=" ".join(self.track.dependencies_required() aheinecke@376: | self.tarball_dependencies), aheinecke@376: basedir=copied_working_copy, aheinecke@376: origtargz=self.origtargz, aheinecke@376: make_dist_command=self.make_dist_command)) aheinecke@376: script_name = os.path.join(self.work_dir, "createtarball") aheinecke@376: treepkg.util.writefile(script_name, script, 0755) aheinecke@376: aheinecke@376: treepkg.util.ensure_directory(self.src_dir) aheinecke@376: treepkg.util.ensure_directory(self.log_dir) aheinecke@376: self.track.builder.run_script([script_name], aheinecke@376: logfile=os.path.join(self.log_dir, aheinecke@376: "tarball_log.txt"), aheinecke@376: bindmounts=[self.work_dir, self.src_dir]) aheinecke@376: aheinecke@376: def create_orig_dir(self): aheinecke@376: """Unpacks the tarball created by create_original_tarball into work_dir aheinecke@376: """ aheinecke@376: unpack_dir = os.path.join(self.work_dir, "unpack") aheinecke@376: treepkg.util.ensure_directory(unpack_dir) aheinecke@376: run.call(cmdexpand("tar xzf $origtargz -C $unpack_dir", aheinecke@376: unpack_dir=unpack_dir, origtargz=self.origtargz)) aheinecke@376: unpacked_files = treepkg.util.listdir_abs(unpack_dir) aheinecke@376: if len(unpacked_files) != 1: aheinecke@376: raise RuntimeError("%s should have extracted to a single directory", aheinecke@376: origtargz) aheinecke@376: unpacked_dir = unpacked_files[0] aheinecke@376: aheinecke@376: orig_dir = os.path.join(self.work_dir, os.path.basename(unpacked_dir)) aheinecke@376: os.rename(unpacked_dir, orig_dir) aheinecke@376: return orig_dir aheinecke@376: aheinecke@376: def do_package(self): aheinecke@376: self.create_original_tarball() aheinecke@376: orig_dir = self.create_orig_dir() aheinecke@376: aheinecke@376: changemsg = ("Update to change: %s" % self.revision) aheinecke@376: aheinecke@376: self.copy_debian_directory(orig_dir, self.pkgbaseversion, changemsg) aheinecke@376: aheinecke@376: self.create_source_package(orig_dir, self.origtargz) aheinecke@376: self.move_source_package(self.pkgbasename) aheinecke@376: