From c847fd7d8f61fec3e7f36b5b060dfa58cd176636 Mon Sep 17 00:00:00 2001 From: Benjamin Drung Date: Thu, 12 Dec 2013 17:27:23 +0100 Subject: [PATCH] Replace git-buildpackage by gitpkg and pbuilder. This should fix #2744. --- debian_build.py | 33 ++++++++++-------- gitpkg-exit-hook | 4 +++ lib/gitpkg.py | 87 ++++++++++++++++++++++++++++++++++++++++++++++++ lib/pbuilder.py | 87 ++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 198 insertions(+), 13 deletions(-) create mode 100644 gitpkg-exit-hook create mode 100644 lib/gitpkg.py create mode 100644 lib/pbuilder.py diff --git a/debian_build.py b/debian_build.py index 12df0c2..4c1e2a5 100755 --- a/debian_build.py +++ b/debian_build.py @@ -25,8 +25,9 @@ from cidb import * from common_code import * from db_add import * from lib import dput -from lib import git_buildpackage from lib import git_helper +from lib import gitpkg +from lib import pbuilder # from common_code @@ -470,19 +471,25 @@ if __name__ == '__main__': logger.info(' ' + line) # - # ACT IV: preparations are done, let's build + # ACT IV: preparations are done, let's build the source # - gbp = git_buildpackage.GitBuildPackage( - upstream_branch=local_branch, - debian_branch=local_branch, + logger.info('Start building the source package with gitpkg...\n') + source_builder = gitpkg.GitPkg(gitrepo, 'HEAD') + ret = source_builder.build() + + # + # ACT V: build the binary with pbuilder from the created source tarball + # + builder = pbuilder.Pbuilder( + dsc_file=source_builder.dsc_file, dist=curr_dist, arch='amd64', pb_suite=pb_suite, git_commit_id=curr_commit_id[0:7], ) - logger.info('Current environment:\n\n{env}\n'.format(env=gbp.env)) - logger.info('Start building ...\n') - ret = gbp.build() + logger.info('Current environment:\n\n{env}\n'.format(env=builder.env)) + logger.info('Start building the binary package with pbuilder...\n') + ret = builder.build() # .. remove last commit (the one where we added the changelog entry) # FIXME: when 'merge': reset only on original branch? @@ -500,7 +507,7 @@ if __name__ == '__main__': ### cd {jenkins_workspace} -export {gbp_env} FORCE_SHELL=TRUE +export {builder_env} FORCE_SHELL=TRUE {command} ### @@ -511,10 +518,10 @@ export {gbp_env} FORCE_SHELL=TRUE hostname=socket.gethostname(), jenkins_user=ENV['USER'], jenkins_workspace=ENV['WORKSPACE'], - gbp_env=' '.join(['{k}="{v}"'.format(k=key, v=gbp.env[key],) - for key in gbp.env.keys() + builder_env=' '.join(['{k}="{v}"'.format(k=key, v=builder.env[key],) + for key in builder.env.keys() ]), - command=' '.join(gbp.command), + command=' '.join(builder.command), orig_branch=ENV['GIT_BRANCH'], )) @@ -535,7 +542,7 @@ export {gbp_env} FORCE_SHELL=TRUE figlet('Build OK') # - # ACT V: post-build actions + # ACT VI: post-build actions # # .. make test results available in jenkins: diff --git a/gitpkg-exit-hook b/gitpkg-exit-hook new file mode 100644 index 0000000..8b41dec --- /dev/null +++ b/gitpkg-exit-hook @@ -0,0 +1,4 @@ +#!/bin/sh +set -e + +echo $DEB_DSC > $REPO_DIR/../debian_dsc diff --git a/lib/gitpkg.py b/lib/gitpkg.py new file mode 100644 index 0000000..8ef6c58 --- /dev/null +++ b/lib/gitpkg.py @@ -0,0 +1,87 @@ +# -*- coding: utf-8 -*- +""" +Created on Thu Dec 12 13:41:03 2013 + +@author: Benjamin Drung +""" + +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +import os +import sys +import logging +import subprocess + +logger = logging.getLogger(__file__) + +BIN_GITPKG = '/usr/bin/gitpkg' + +class GitPkg(object): + def __init__(self, gitrepo, debian_branch=None, upstream_branch=None): + ''' + TODO + ''' + self.gitrepo = gitrepo + self.debian_branch = debian_branch + self.upstream_branch = upstream_branch + + @property + def env(self): + ''' + TODO + ''' + result = os.environ + return result + + @property + def command(self): + ''' + TODO + ''' + result = [ + BIN_GITPKG, + self.debian_branch, + ] + if self.upstream_branch: + result.append(self.upstream_branch) + return result + + def build(self): + ''' + TODO + ''' + + # gitpkg-exit-hook is stored in the same directory than the + # debian_build.py script. + base_dir = os.path.dirname(os.path.realpath(sys.argv[0])) + config_writer = self.gitrepo.config_writer() + config_writer.set_value('gitpkg', 'create-fake-orig', 'true') + config_writer.set_value('gitpkg', 'gitpkg.exit-hook', + os.path.join(base_dir, 'gitpkg-exit-hook')) + + cmdobj = subprocess.Popen( + self.command, + shell=False, + close_fds=True, + #stdout=subprocess.PIPE, + #stderr=subprocess.PIPE, + stdout=sys.stdout, + stderr=sys.stderr, + env=self.env, + cwd=os.getcwd(), + ) + + ret = cmdobj.wait() + return ret + + @property + def dsc_file(self): + dsc_file = None + debian_dsc = os.path.join(os.getcwd(), "../debian_dsc") + if os.path.isfile(debian_dsc): + dsc_file = open(debian_dsc).read() + if not os.path.isfile(dsc_file): + logger.error("Generated source package " + dsc_file + + " not found.") + return dsc_file \ No newline at end of file diff --git a/lib/pbuilder.py b/lib/pbuilder.py new file mode 100644 index 0000000..a65d9c3 --- /dev/null +++ b/lib/pbuilder.py @@ -0,0 +1,87 @@ +# -*- coding: utf-8 -*- +""" +Created on Thu Dec 12 16:12:51 2013 + +@author: Benjamin Drung +""" + +import os +import sys +import subprocess + +BIN_PBUILDER = '/usr/bin/pbuilder' +BIN_SUDO = '/usr/bin/sudo' + +class Pbuilder(object): + def __init__(self, + dsc_file=None, + dist=None, + arch=None, + pb_suite=None, + git_commit_id=None, + ): + ''' + TODO + ''' + self.dsc_file = dsc_file + self.dist = dist + self.arch = arch + self.pb_suite = pb_suite + self.git_commit_id = git_commit_id + + @property + def env(self): + ''' + TODO + ''' + result = os.environ + result['DIST'] = self.dist + result['ARCH'] = self.arch + result['PB_SUITE'] = self.pb_suite + result['GIT_COMMIT_ID'] = self.git_commit_id + return result + + @property + def command(self): + ''' + TODO + ''' + result = [ + BIN_SUDO, + BIN_PBUILDER, + '--build', + '--buildresult=../build-area/result/', + '--debbuildopts', '-b', # don't build source packages... + # see directly below + self.dsc_file, + ] + return result + + def build(self): + ''' + TODO + ''' + # if we would build orig.tar.gz we would need to be able to access + # them later, which we probably could achieve with using pristine-tar + # and storing that in the git repo - but this has the downside that + # the jenkins build job would need to push this back into the git repo + # (so this makes things complicated) and then still, we could not + # gurantee that this orig.tar.gz actually reflects the git repo at + # that point. + # So in summary, it would be expensive and buys as nothing, as we + # can always generate the source from said git repos... + + cmdobj = subprocess.Popen( + self.command, + shell=False, + close_fds=True, + #stdout=subprocess.PIPE, + #stderr=subprocess.PIPE, + stdout=sys.stdout, + stderr=sys.stderr, + env=self.env, + cwd=os.getcwd(), + ) + + ret = cmdobj.wait() + return ret \ No newline at end of file -- 2.39.5