From 03e38ad87c882d62ce9f54709fcf8c535edc36fa Mon Sep 17 00:00:00 2001 From: Tzafrir Cohen Date: Mon, 29 Dec 2014 18:24:49 +0200 Subject: gbp rpm: mock chroot builder Initial version. Very rough and many shortcuts taken. Try: gbp buildpackage-rpm --git-mock --git-dist=epel-6 Results will be under ../rpmbuild/results/ --- bin/git-mock | 100 ++++++++++++++++++++++++++++++++++++ debian/control | 2 +- debian/git-buildpackage-rpm.install | 1 + debian/git-buildpackage.install | 12 ++++- gbp/config.py | 24 +++++++++ gbp/scripts/buildpackage_rpm.py | 26 +++++++++- setup.py | 1 + 7 files changed, 163 insertions(+), 3 deletions(-) create mode 100755 bin/git-mock diff --git a/bin/git-mock b/bin/git-mock new file mode 100755 index 0000000..c06cdb6 --- /dev/null +++ b/bin/git-mock @@ -0,0 +1,100 @@ +#!/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 + $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" + #for rel in $releases; do + # mock -r $rel --resultdir="$PWD/$rpms_pat" \ + # --no-cleanup-after \ + # --rebuild "$srpm" + #done +} + + +fix_arch + +git_builder diff --git a/debian/control b/debian/control index 45d28a9..fd5da72 100644 --- a/debian/control +++ b/debian/control @@ -66,7 +66,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 import-srpm: import existing RPM source packages into a git diff --git a/debian/git-buildpackage-rpm.install b/debian/git-buildpackage-rpm.install index 36bf4ef..28b8fd7 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/buildpackage_rpm.py usr/lib/python2.7/dist-packages/gbp/scripts/import_srpm.py diff --git a/debian/git-buildpackage.install b/debian/git-buildpackage.install index 1a25e1d..561c22a 100644 --- a/debian/git-buildpackage.install +++ b/debian/git-buildpackage.install @@ -1,4 +1,14 @@ -usr/bin/ +usr/bin/git-import-dscs +usr/bin/gbp-pq +usr/bin/gbp-clone +usr/bin/gbp +usr/bin/git-import-orig +usr/bin/git-buildpackage +usr/bin/git-import-dsc +usr/bin/git-pbuilder +usr/bin/gbp-create-remote-repo +usr/bin/git-dch +usr/bin/gbp-pull 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 02b9254..79404df 100644 --- a/gbp/config.py +++ b/gbp/config.py @@ -611,6 +611,12 @@ class GbpOptionParserRpm(GbpOptionParser): 'patch-export-squash-until' : '', 'spec-vcs-tag' : '', 'orig-prefix' : 'auto', + 'mock' : 'False', + 'mock-results-pat' : 'results/%(dist)s/%(target_arch)s/', + 'dist' : '', + 'arch' : '', + 'mock-root' : '', + 'mock-options' : '', }) help = dict(GbpOptionParser.help) @@ -665,6 +671,24 @@ class GbpOptionParserRpm(GbpOptionParser): 'orig-prefix': "Prefix (dir) to be used when generating/importing tarballs, " "default is '%(orig-prefix)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: -, " + "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 dcfa3ac..c29a83f 100644 --- a/gbp/scripts/buildpackage_rpm.py +++ b/gbp/scripts/buildpackage_rpm.py @@ -293,7 +293,7 @@ def is_native(repo, options): def setup_builder(options, builder_args): - """setup everything to use git-pbuilder""" + """setup everything pathes for rpmbuild""" if options.builder.startswith('rpmbuild'): if len(builder_args) == 0: builder_args.append('-ba') @@ -310,6 +310,23 @@ def setup_builder(options, builder_args): options.spec_dir = '' +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 + # FIXME: get that option defined: + #os.environ['GIT_MOCK_RESULTS_PAT'] = options.mock_results_pat + if options.mock_options: + os.environ['GIT_MOCK_OPTIONS'] = options.mock_options + + def update_tag_str_fields(fields, tag_format_str, repo, commit_info): """Update string format fields for packaging tag""" fields['nowtime'] = datetime.now().strftime(RpmPkgPolicy.tag_timestamp_format) @@ -447,6 +464,12 @@ def parse_args(argv, prefix, git_treeish=None): help="hook run after a successful build, default is '%(postbuild)s'") 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_boolean_config_file_option(option_name="mock", dest="use_mock") + #cmd_group.add_config_file_option(option_name="mock-results-pat", dest="mock_results_pat") + cmd_group.add_config_file_option(option_name="dist", dest="mock_dist") + cmd_group.add_config_file_option(option_name="arch", dest="mock_arch") + 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", @@ -568,6 +591,7 @@ def main(argv): if not options.tag_only: # Setup builder opts setup_builder(options, builder_args) + setup_mock(options) # Generate patches, if requested if options.patch_export and not is_native(repo, options): diff --git a/setup.py b/setup.py index 3337c21..02e6396 100644 --- a/setup.py +++ b/setup.py @@ -66,6 +66,7 @@ setup(name = "gbp", 'bin/git-import-orig', 'bin/git-dch', 'bin/git-import-dscs', + 'bin/git-mock', 'bin/gbp-pq', 'bin/gbp-pull', 'bin/gbp-clone', -- cgit v1.2.3