Commit bfe32f19 authored by Guido Günther's avatar Guido Günther

buildpackage-rpm: add support for mock chroot builder

Try:

  gbp buildpackage-rpm --git-mock --git-dist=epel-6

Results will be under ../rpmbuild/results/

This is very heavily based on a patch from Tzafrir Cohen.
parent 82a847df
#!/bin/sh
#
# Helper to invoke mock from 'gbp buildpackage-rpm'
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, please see
# <http://www.gnu.org/licenses/>
#
# Copyright (C) 2015 Tzafrir Cohen
# (C) 2015 Guido Günther
set -e
# There must be a saner way to do that or a reason why this is not required
fix_arch() {
GBP_BUILDER_MOCK_ARCH=${GBP_BUILDER_MOCK_ARCH:-`uname -m`}
case "$ARCH" in
amd64) ARCH='x86_64';;
esac
}
usage() {
EXIT=${1:-1}
echo >&2 "$0: Must be run via 'gbp buildpackage-rpm', see manpage for details"
exit $EXIT
}
while [ $# != 0 ]; do
case "$1" in
--help|-h|-?) usage 0;;
*.spec) SPEC="$1";;
esac
shift
done
# 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
gbp_builder_mock() {
if [ -z "$GBP_BUILDER_MOCK_DIST" ]; then
usage
fi
local root=${GBP_BUILDER_MOCK_ROOT:-${GBP_BUILDER_MOCK_DIST}-${GBP_BUILDER_MOCK_ARCH}}
if [ ! -d "$GBP_BUILDER_MOCK_EXPORT_DIR" ]; then
echo >&2 "$0: Missing output directory (GBP_BUILDER_MOCK_EXPORT_DIR). Aborting."
usage
fi
if [ -z "$SPEC" ]; then
echo >&2 "$0: No specfile given."
exit 1
fi
export_dir="$PWD"
spec="$export_dir/SPECS/$SPEC"
sources="$export_dir/SOURCES"
srpms="$export_dir/SRPMS"
pat="${GBP_BUILDER_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"
$mock --buildsrpm
# Assuming that nothing was built in this directory since the previous command:
local srpm=`ls -t $PWD/SRPMS/*.src.rpm 2>/dev/null| head -n1`
if [ -z $srpm ]; then
echo >&2 "$0: failed to create srpm"
exit 1
fi
$mock --no-cleanup-after --resultdir $resultdir --rebuild "$srpm"
}
fix_arch
gbp_builder_mock
......@@ -73,7 +73,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
......
usr/bin/gbp-builder-mock /usr/share/git-buildpackage/
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
......
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
......
......@@ -34,6 +34,7 @@
<!ENTITY gbp-import-srpm "<command>gbp&nbsp;import-srpm</command>">
<!ENTITY gbp-pq-rpm "<command>gbp&nbsp;pq-rpm</command>">
<!ENTITY rpmbuild "<command>rpmbuild</command>">
<!ENTITY gbp-builder-mock "<command>gbp-builder-mock</command>">
<!ENTITY wget "<command>wget</command>">
<!ENTITY debian "<productname>Debian</productname>">
......@@ -51,5 +52,6 @@
<!ENTITY apt-get "<productname>apt-get</productname>">
<!ENTITY dget "<productname>dget</productname>">
<!ENTITY lintian "<productname>lintian</productname>">
<!ENTITY mock "<productname>mock</productname>">
<!ENTITY gnu "<acronym>GNU</acronym>">
<!ENTITY gpl "&gnu; <acronym>GPL</acronym>">
......@@ -57,6 +57,11 @@
<arg><option>--git-[no-]pristine-tar-commit</option></arg>
<arg><option>--git-tag-only</option></arg>
<arg><option>--git-retag</option></arg>
<arg><option>--git-mock</option></arg>
<arg><option>--git-dist</option>=<replaceable>DISTRIBUTION</replaceable></arg>
<arg><option>--git-arch</option>=<replaceable>ARCHITECTURE</replaceable></arg>
<arg><option>--git-mock-options</option>=<replaceable>OPTIONS</replaceable></arg>
<arg><option>--git-mock-root</option>=<replaceable>ROOT</replaceable></arg>
</cmdsynopsis>
</refsynopsisdiv>
<refsect1>
......@@ -544,6 +549,55 @@
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>--git-mock</option>
</term>
<listitem>
<para>
Use &mock; to build the rpms by invoking &gbp-builder-mock;.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>--git-dist</option>
</term>
<listitem>
<para>
Build for this distribution when using &mock; (e.g.: epel-6).
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>--git-arch</option>
</term>
<listitem>
<para>
Build for this architecture when using mock, default is to build
for the current host architecture.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>--git-mock-root</option>
</term>
<listitem>
<para>
The mock root to use. Defaults
to <replaceable>DIST</replaceable>-<replaceable>ARCH</replaceable>
from above.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>--git-mock-options</option>
</term>
<listitem>
<para>
Additional options to pass to mock. Default is to pass no
additional options.
</para>
</listitem>
</varlistentry>
</variablelist>
</refsect1>
<refsect1>
......@@ -577,6 +631,10 @@
<refentrytitle>rpmbuild</refentrytitle>
<manvolnum>8</manvolnum>
</citerefentry>,
<citerefentry>
<refentrytitle>mock</refentrytitle>
<manvolnum>1</manvolnum>
</citerefentry>,
<xref linkend="man.gbp.conf"/>,
&man.seealso.common;
</para>
......
......@@ -642,6 +642,11 @@ class GbpOptionParserRpm(GbpOptionParser):
'export-dir' : '../rpmbuild',
'builder' : 'rpmbuild',
'spec-file' : '',
'mock' : 'False',
'dist' : '',
'arch' : '',
'mock-root' : '',
'mock-options' : '',
})
help = dict(GbpOptionParser.help)
......@@ -674,6 +679,21 @@ class GbpOptionParserRpm(GbpOptionParser):
'export-specdir':
"Subdir (under EXPORT_DIR) where package spec file is "
"exported default is '%(export-specdir)s'",
'mock':
("Invoke mock for building using gbp-builder-mock, "
"default is '%(mock)s'"),
'dist':
("Build for this distribution when using mock. E.g.: epel-6, "
"default is '%(dist)s'"),
'arch':
("Build for this architecture when using mock, "
"default is '%(arch)s'"),
'mock-root':
("The mock root (-r) name for building with mock: <dist>-<arch>, "
"default is '%(mock-root)s'"),
'mock-options':
("Options to pass to mock, "
"default is '%(mock-options)s'"),
})
# vim:et:ts=4:sw=4:et:sts=4:ai:set list listchars=tab\:»·,trail\:·:
......@@ -275,7 +275,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 gbp-builder-mock"""
if options.use_mock:
options.builder = '/usr/share/git-buildpackage/gbp-builder-mock'
options.cleaner = '/bin/true'
os.environ['GBP_BUILDER_MOCK_DIST'] = options.mock_dist
if options.mock_arch:
os.environ['GBP_BUILDER_MOCK_ARCH'] = options.mock_arch
if options.mock_root:
os.environ['GBP_BUILDER_MOCK_ROOT'] = options.mock_root
os.environ['GBP_BUILDER_MOCK_EXPORT_DIR'] = options.export_dir
if options.mock_options:
os.environ['GBP_BUILDER_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)
......@@ -395,6 +410,11 @@ 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_boolean_config_file_option(option_name="mock", dest="use_mock")
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",
......@@ -507,6 +527,8 @@ def main(argv):
if not options.tag_only:
# Setup builder opts
setup_builder(options, builder_args)
if options.use_mock:
setup_mock(options)
# Prepare final export dirs
export_dir = makedir(options.export_dir)
......
......@@ -156,6 +156,8 @@ GIT_CEILING_DIRECTORIES=%{_builddir} \
%install
rm -rf %{buildroot}
WITHOUT_NOSETESTS=1 %{__python} ./setup.py install --root=%{buildroot} --prefix=/usr
mkdir -p %{buildroot}/usr/share/%{name}
mv %{buildroot}/usr/bin/gbp-builder-mock %{buildroot}/usr/share/%{name}/
%if %{with docs}
# Install man pages
......@@ -239,6 +241,7 @@ done
%dir %{python_sitelib}/gbp/rpm
%{python_sitelib}/gbp/scripts/*rpm*.py*
%{python_sitelib}/gbp/rpm/*py*
/usr/share/git-buildpackage/gbp-builder-mock
%if %{with docs}
%{_mandir}/man1/gbp-buildpackage-rpm.1*
%{_mandir}/man1/gbp-pq-rpm.1*
......
......@@ -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/gbp-builder-mock'],
packages = find_packages(exclude=['tests', 'tests.*']),
data_files = [("/etc/git-buildpackage/", ["gbp.conf"]),],
requires = ["six"],
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment