Package: git-buildpackage Version: 0.6.34~2.gbpffdfcd Severity: wishlist Hi, now that we have buildpackage-rpm support on master it would be nice to add support for mock. I'm attatching a patch I extracted from Tzafrir's repo for that.
Since a rewrite of git-pbuilder in Python is planned it would be nice to make git-mock use Python from the beginning so we don't run into the same issues of parameter parsing there and we can proper integrate it into the build and test system. Just putting this here so we have everything in one place. Cheers, -- Guido -- System Information: Debian Release: 8.1 APT prefers stable APT policy: (990, 'stable'), (500, 'stable-updates'), (500, 'unstable'), (500, 'testing'), (1, 'experimental') Architecture: amd64 (x86_64) Foreign Architectures: i386 Kernel: Linux 4.1.0-1-amd64 (SMP w/4 CPU cores) Locale: LANG=de_DE.UTF-8, LC_CTYPE=de_DE.UTF-8 (charmap=UTF-8) Shell: /bin/sh linked to /bin/dash Init: systemd (via /run/systemd/system) Versions of packages git-buildpackage depends on: ii devscripts 2.15.8 ii git 1:2.1.4-2.1 ii man-db 2.7.0.2-5 ii python 2.7.9-1 ii python-dateutil 2.2-2 ii python-pkg-resources 5.5.1-1 ii python-six 1.8.0-1 Versions of packages git-buildpackage recommends: ii cowbuilder 0.73 ii pbuilder 0.215+nmu3 ii pristine-tar 1.33 ii python-requests 2.4.3-6 ii sbuild 0.65.2-1 Versions of packages git-buildpackage suggests: ii python-notify 0.1.1-4 ii unzip 6.0-16 -- no debconf information
>From 870b001446573f44c82081373b5cfe8bdab42239 Mon Sep 17 00:00:00 2001 Message-Id: <870b001446573f44c82081373b5cfe8bdab42239.1440062625.git....@sigxcpu.org> From: Tzafrir Cohen <[email protected]> Date: Mon, 29 Dec 2014 18:24:49 +0200 Subject: [PATCH] gbp rpm: mock chroot builder Initial version. Try: gbp buildpackage-rpm --git-mock --git-dist=epel-6 Results will be under ../rpmbuild/results/ --- bin/git-mock | 95 +++++++++++++++++++++++++++++++++++++ debian/control | 2 +- debian/git-buildpackage-rpm.install | 1 + debian/git-buildpackage.install | 3 +- gbp/config.py | 23 +++++++++ gbp/scripts/buildpackage_rpm.py | 20 +++++++- setup.py | 3 +- 7 files changed, 143 insertions(+), 4 deletions(-) create mode 100755 bin/git-mock diff --git a/bin/git-mock b/bin/git-mock new file mode 100755 index 0000000..7a40aff --- /dev/null +++ b/bin/git-mock @@ -0,0 +1,95 @@ +#!/bin/sh + +# Assumed directory layout: +# this script sits in the top-level directory. Under which there's +# a subdirectory for each package. There is also the special +# adminitrative subdirectory rpmbuild + +set -e + +# Make sure we have the necessary tools. +if [ ! -x /usr/bin/mock ]; then + echo "mock not found; you need to install the mock package" >&2 + exit 1 +fi + +#my_dir=`dirname $0` +#top_dir="$my_dir/.." +top_dir=".." +build_dir="$top_dir/rpmbuild" +specs_dir="$build_dir/SPECS" +sources_dir="$build_dir/SOURCES" +srpms_dir="$build_dir/SRPMS" +rpms_pat="results/%(dist)s/%(target_arch)s/" + +releases="cpbx-45-x86_64 cpbx-45-i386" + +usage() { + me=`basename $0` + echo \ +"Usage: + $me <export|build|clean> + $me import path/to/srpm + + export: export a source RPM package from git tree + build: build latest source RPM using mock + import: create/update a git repository from source RPM + clean: delete all produced RPM packages under $build_dir +" +} + +# There must be a saner way to do that or a reason why this is not required +fix_arch() { + ARCH=${ARCH:-`uname -m`} + case "$ARCH" in + amd64) ARCH='x86_64';; + esac +} + +while [ $# != 0 ]; do + case "$1" in + --define) shift ;; + *.spec) SPEC="$1" + esac + shift +done + +create_srpm() { + spec=`ls -t $specs_dir/*.spec | head -n1` + + mkdir -p "$srpms_dir" + rpmbuild -bs \ + --define "_sourcedir $sources_dir" \ + --define "_srcrpmdir $srpms_dir" \ + "$spec" +} + +# Mock wrapper: used internally +git_builder() { + local spec="$SPEC" + local root=${GIT_MOCK_ROOT:-${DIST}-${ARCH}} + if [ ! -d "$GIT_MOCK_EXPORT_DIR" ]; then + echo >&2 "$0: Missing outputs directory (GIT_MOCK_EXPORT_DIR). Aborting." + exit 1 + fi + #local export_dir="$GIT_MOCK_EXPORT_DIR" + export_dir="$PWD" + spec="$export_dir/SPECS/$spec" + sources="$export_dir/SOURCES" + srpms="$export_dir/SRPMS" + pat="${GIT_MOCK_RESULTS_PAT-results/%(dist)s/%(target_arch)s/}" + local resultdir="$export_dir/$pat" + local mock="mock -r $root --resultdir=$srpms --spec=$spec --sources=$sources" + set -e + + $mock --buildsrpm + #rpmbuild -bs --define "_topdir ." "SPECS/$spec" + # Assuming that nothing was built in this directory since the previous command: + local srpm=`ls -t $PWD/SRPMS/*.src.rpm | head -n1` + $mock --no-cleanup-after --resultdir $resultdir --rebuild "$srpm" +} + + +fix_arch + +git_builder diff --git a/debian/control b/debian/control index 47ccf29..d98c0dc 100644 --- a/debian/control +++ b/debian/control @@ -72,7 +72,7 @@ Depends: ${python:Depends}, python-rpm, rpm, Recommends: pristine-tar (>= 0.5) -Suggests: python-notify, unzip +Suggests: python-notify, unzip, mock Description: Suite to help with RPM packages in Git repositories This package contains the following tools: * gbp buildpackage-rpm: build a package out of a git repository, check for diff --git a/debian/git-buildpackage-rpm.install b/debian/git-buildpackage-rpm.install index 5178cb3..8cee78f 100644 --- a/debian/git-buildpackage-rpm.install +++ b/debian/git-buildpackage-rpm.install @@ -1,3 +1,4 @@ +usr/bin/git-mock usr/lib/python2.?/dist-packages/gbp/rpm/ usr/lib/python2.7/dist-packages/gbp/scripts/import_srpm.py usr/lib/python2.7/dist-packages/gbp/scripts/pq_rpm.py diff --git a/debian/git-buildpackage.install b/debian/git-buildpackage.install index 1a25e1d..1cf7c4c 100644 --- a/debian/git-buildpackage.install +++ b/debian/git-buildpackage.install @@ -1,4 +1,5 @@ -usr/bin/ +usr/bin/gbp +usr/bin/git-pbuilder usr/lib/python2.?/dist-packages/gbp-* usr/lib/python2.?/dist-packages/gbp/command_wrappers.py usr/lib/python2.?/dist-packages/gbp/config.py diff --git a/gbp/config.py b/gbp/config.py index 3b483c0..416612a 100644 --- a/gbp/config.py +++ b/gbp/config.py @@ -599,6 +599,11 @@ class GbpOptionParserRpm(GbpOptionParser): 'export-dir' : '../rpmbuild', 'builder' : 'rpmbuild', 'spec-file' : '', + 'mock' : 'False', + 'dist' : '', + 'arch' : '', + 'mock-root' : '', + 'mock-options' : '', }) help = dict(GbpOptionParser.help) @@ -631,6 +636,24 @@ class GbpOptionParserRpm(GbpOptionParser): 'export-specdir': "Subdir (under EXPORT_DIR) where package spec file is " "exported default is '%(export-specdir)s'", + 'mock': + ("Invoke git-mock for building, " + "default is '%(mock)s'"), + 'dist': + ("Build for this distribution when using git-mock. E.g.: epel-6, " + "default is '%(dist)s'"), + 'arch': + ("Build for this architecture when using git-mock, " + "default is '%(arch)s'"), + 'mock-root': + ("The mock root (-r) name for building with git-mock: <dist>-<arch>, " + "default is '%(mock-root)s'"), + 'mock-options': + ("Options to pass to mock, " + "default is '%(mock-options)s'"), + 'mock-result-pat': + ("Pattern describing the subdirectory under which mock will write results, " + "default is '%(mock-results-pat)s'"), }) # vim:et:ts=4:sw=4:et:sts=4:ai:set list listchars=tab\:»·,trail\:·: diff --git a/gbp/scripts/buildpackage_rpm.py b/gbp/scripts/buildpackage_rpm.py index d613e91..b48063c 100644 --- a/gbp/scripts/buildpackage_rpm.py +++ b/gbp/scripts/buildpackage_rpm.py @@ -277,7 +277,22 @@ def packaging_tag_data(repo, commit, name, version, options): return (tag_name, tag_msg) -def create_packaging_tag(repo, commit, name, version, options): +def setup_mock(options): + """setup everything to use git-mock""" + if options.use_mock: + options.builder = 'git-mock' + options.cleaner = '/bin/true' + os.environ['DIST'] = options.mock_dist + if options.mock_arch: + os.environ['ARCH'] = options.mock_arch + if options.mock_root: + os.environ['GIT_MOCK_ROOT'] = options.mock_root + os.environ['GIT_MOCK_EXPORT_DIR'] = options.export_dir + if options.mock_options: + os.environ['GIT_MOCK_OPTIONS'] = options.mock_options + + +def create_packaging_tag(repo, tag, commit, version, options): """Create a packaging/release Git tag""" tag_name, tag_msg = packaging_tag_data(repo, commit, name, version, options) @@ -397,6 +412,8 @@ def build_parser(name, prefix=None, git_treeish=None): cmd_group.add_config_file_option(option_name="posttag", dest="posttag", help="hook run after a successful tag operation, default " "is '%(posttag)s'") + cmd_group.add_config_file_option(option_name="mock-root", dest="mock_root") + cmd_group.add_config_file_option(option_name="mock-options", dest="mock_options") cmd_group.add_boolean_config_file_option(option_name="hooks", dest="hooks") export_group.add_option("--git-no-build", action="store_true", dest="no_build", @@ -509,6 +526,7 @@ def main(argv): if not options.tag_only: # Setup builder opts setup_builder(options, builder_args) + setup_mock(options) # Prepare final export dirs export_dir = makedir(options.export_dir) diff --git a/setup.py b/setup.py index 355b148..35dcaa8 100644 --- a/setup.py +++ b/setup.py @@ -61,7 +61,8 @@ setup(name = "gbp", 'Topic :: Software Development :: Version Control :: Git', 'Operating System :: POSIX :: Linux', ], - scripts = ['bin/git-pbuilder'], + scripts = ['bin/git-pbuilder', + 'bin/git-mock'], packages = find_packages(exclude=['tests', 'tests.*']), data_files = [("/etc/git-buildpackage/", ["gbp.conf"]),], requires = ["six"], -- 2.1.4

