From 73ee012e2e9a5b5ccb02b7c612f0a01a93536b14 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 | 99 +++++++++++++++++++++++++++++++++++++ debian/control | 2 +- debian/git-buildpackage-rpm.install | 1 + debian/git-buildpackage.install | 3 +- gbp/config.py | 24 +++++++++ gbp/scripts/buildpackage_rpm.py | 26 +++++++++- setup.py | 2 +- 7 files changed, 153 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..120daa4 --- /dev/null +++ b/bin/git-mock @@ -0,0 +1,99 @@ +#!/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 + +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 [options] package.spec - Build package.spec with mock + + Options: + --define STRING - Currently ignored + + Environment: + ARCH: The architecture of the mock root. Defaults to the oen + of the host system. + DIST: The distribution of the mock host. + GIT_MOCK_ROOT: The mock root. Defaults to "$DIST-$ARCH" + GIT_MOCK_EXPORT_DIR: The top-level directory of the git- + buildpackage results tree. + GIT_MOCK_RESULTS_PAT: The directory template for results under + the exports dir. A default is provided. +" +} + +# 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 + # 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 985b7d8..95572c7 100644 --- a/debian/control +++ b/debian/control @@ -68,7 +68,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..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 1fcdf04..ac5e2ff 100644 --- a/gbp/config.py +++ b/gbp/config.py @@ -612,6 +612,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) @@ -666,6 +672,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 9216805..1e173ce 100644 --- a/setup.py +++ b/setup.py @@ -61,7 +61,7 @@ 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"], -- cgit v1.2.3