aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuca Boccassi <bluca@debian.org>2018-06-25 23:37:02 +0100
committerGuido G√ľnther <agx@sigxcpu.org>2018-10-28 12:30:25 +0100
commitce6b1e755fbd999156dbe8c0bf28ccb180641ba2 (patch)
tree3424f5f53b51c244af83bf2c4d21aec1379c76a0
parent6b1342253eecd83e514400fccc531205450b13d3 (diff)
buildpackage{,-rpm}: add preexport hook
Sometimes it is necessary to perform operations before preparing the tarballs and exporting to the build directory. One such case is when having to handle extremely large binary assets in the orig tarball and at the same time complex packaging code, which makes it desirable to separate the two into different repositories for easier handling. A pre-export hook allows to ensure that the tarball repository is present and checked out at the correct branch. Closes: #909266 Signed-off-by: Luca Boccassi <bluca@debian.org>
-rw-r--r--debian/gbp.completion2
-rw-r--r--docs/chapters/building.xml12
-rw-r--r--docs/manpages/gbp-buildpackage-rpm.xml18
-rw-r--r--docs/manpages/gbp-buildpackage.xml18
-rw-r--r--gbp/config.py1
-rwxr-xr-xgbp/scripts/buildpackage.py13
-rw-r--r--gbp/scripts/buildpackage_rpm.py13
-rw-r--r--tests/component/deb/test_buildpackage.py9
-rw-r--r--tests/component/rpm/test_buildpackage_rpm.py6
9 files changed, 85 insertions, 7 deletions
diff --git a/debian/gbp.completion b/debian/gbp.completion
index 706cfdf..37e85ea 100644
--- a/debian/gbp.completion
+++ b/debian/gbp.completion
@@ -55,7 +55,7 @@ _gbp_comp ()
local remote_config_opts="--remote-config\="
local file_opts="--postimport\= --git-builder\= --git-cleaner\= \
--git-export-dir\= --git-postbuild\= --git-postexport\= \
- --git-posttag\= --git-prebuild\= --git-tarball-dir\= \
+ --git-posttag\= --git-prebuild\= --git-preexport\= --git-tarball-dir\= \
--posttag\= --tarball-dir\="
local start_opt=""
diff --git a/docs/chapters/building.xml b/docs/chapters/building.xml
index 1fbd5ae..af1fe31 100644
--- a/docs/chapters/building.xml
+++ b/docs/chapters/building.xml
@@ -267,5 +267,17 @@ rm -f rules.* control.*
exit 0
</programlisting>
</sect2>
+ <sect2 id="gbp.building.preexport">
+ <title>Running preexport hook</title>
+ <para>&gbp-buildpackage; exports several variables into the
+ <option>preexport</option>'s environment (for details see
+ the <xref linkend="man.gbp.buildpackage"/> manual page). The motivation
+ for the preexport action is to allow further actions before preparing and
+ exporting the orig tarballs to the build directory.
+ A usecase could be having the orig tarballs in a separate repository due to
+ very large binary assets, that need to be checked out to the correct branch
+ before creating the tarballs.
+ </para>
+ </sect2>
</sect1>
</chapter>
diff --git a/docs/manpages/gbp-buildpackage-rpm.xml b/docs/manpages/gbp-buildpackage-rpm.xml
index 9f8f438..18a0a1e 100644
--- a/docs/manpages/gbp-buildpackage-rpm.xml
+++ b/docs/manpages/gbp-buildpackage-rpm.xml
@@ -39,6 +39,7 @@
<arg><option>--git-postbuild=</option><replaceable>COMMAND</replaceable></arg>
<arg><option>--git-postexport=</option><replaceable>COMMAND</replaceable></arg>
<arg><option>--git-prebuild=</option><replaceable>COMMAND</replaceable></arg>
+ <arg><option>--git-preexport=</option><replaceable>COMMAND</replaceable></arg>
<arg><option>--git-[no-]build</option></arg>
<arg><option>--git-[no-]hooks</option></arg>
<arg><option>--git-packaging-tag=</option><replaceable>TAG-FORMAT</replaceable></arg>
@@ -336,6 +337,21 @@
</listitem>
</varlistentry>
<varlistentry>
+ <term><option>--git-preexport=</option><replaceable>COMMAND</replaceable>
+ </term>
+ <listitem>
+ <para>
+ Execute <replaceable>COMMAND</replaceable> before exporting the source
+ tree.
+ </para>
+ <para>
+ Exported environment variables are: <envar>GBP_GIT_DIR</envar> (the
+ repository the package is being built from),
+ <envar>GBP_BUILD_DIR</envar> (the build dir).
+ </para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
<term><option>--git-postexport=</option><replaceable>COMMAND</replaceable>
</term>
<listitem>
@@ -382,7 +398,7 @@
</term>
<listitem>
<para>
- Enable running all (cleaner, postexport, prebuild, postbuild, and
+ Enable running all (cleaner, preexport, postexport, prebuild, postbuild, and
posttag) hooks. Note: the <option>--git-builder</option> command is
not affected by this option.
</para>
diff --git a/docs/manpages/gbp-buildpackage.xml b/docs/manpages/gbp-buildpackage.xml
index 9b6bcce..d25f5c8 100644
--- a/docs/manpages/gbp-buildpackage.xml
+++ b/docs/manpages/gbp-buildpackage.xml
@@ -39,6 +39,7 @@
<arg><option>--git-pbuilder-options</option>=<replaceable>PBUILDER_OPTIONS</replaceable></arg>
<arg><option>--git-[no-]sign-tags</option></arg>
<arg><option>--git-keyid=</option><replaceable>GPG-KEYID</replaceable></arg>
+ <arg><option>--git-preexport=</option><replaceable>COMMAND</replaceable></arg>
<arg><option>--git-postexport=</option><replaceable>COMMAND</replaceable></arg>
<arg><option>--git-prebuild=</option><replaceable>COMMAND</replaceable></arg>
<arg><option>--git-postbuild=</option><replaceable>COMMAND</replaceable></arg>
@@ -460,6 +461,21 @@
</para>
<variablelist>
<varlistentry>
+ <term><option>--git-preexport=</option><replaceable>COMMAND</replaceable>
+ </term>
+ <listitem>
+ <para>
+ Execute <replaceable>COMMAND</replaceable> before exporting the source
+ tree. Valid only if --git-export-dir has been specified.
+ </para>
+ <para>
+ Exported environment variables are: <envar>GBP_GIT_DIR</envar> (the
+ repository the package is being built from),
+ <envar>GBP_BUILD_DIR</envar> (the build dir).
+ </para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
<term><option>--git-postexport=</option><replaceable>COMMAND</replaceable>
</term>
<listitem>
@@ -531,7 +547,7 @@
</term>
<listitem>
<para>
- Enable running all (cleaner, postexport, prebuild, postbuild, and
+ Enable running all (cleaner, preexport, postexport, prebuild, postbuild, and
posttag) hooks. Note: the <option>--git-builder</option> command is
not affected by this option.
</para>
diff --git a/gbp/config.py b/gbp/config.py
index 76a850d..5041180 100644
--- a/gbp/config.py
+++ b/gbp/config.py
@@ -163,6 +163,7 @@ class GbpOptionParser(OptionParser):
'posttag': '',
'pq-from': 'DEBIAN',
'prebuild': '',
+ 'preexport': '',
'pristine-tar': 'False',
'pristine-tar-commit': 'False',
'purge': 'True',
diff --git a/gbp/scripts/buildpackage.py b/gbp/scripts/buildpackage.py
index d345b46..d3a3222 100755
--- a/gbp/scripts/buildpackage.py
+++ b/gbp/scripts/buildpackage.py
@@ -277,7 +277,7 @@ def mangle_export_wc_opts(options):
def disable_hooks(options):
"""Disable all hooks (except for builder)"""
- for hook in ['cleaner', 'postexport', 'prebuild', 'postbuild', 'posttag']:
+ for hook in ['cleaner', 'preexport', 'postexport', 'prebuild', 'postbuild', 'posttag']:
if getattr(options, hook):
gbp.log.info("Disabling '%s' hook" % hook)
setattr(options, hook, '')
@@ -406,6 +406,9 @@ def build_parser(name, prefix=None):
cmd_group.add_config_file_option(option_name="prebuild", dest="prebuild",
help="hook to run before a build, "
"default is '%(prebuild)s'")
+ cmd_group.add_config_file_option(option_name="preexport", dest="preexport",
+ help="hook to run before exporting the source tree, "
+ "default is '%(preexport)s'")
cmd_group.add_config_file_option(option_name="postexport", dest="postexport",
help="hook to run after exporting the source tree, "
"default is '%(postexport)s'")
@@ -505,6 +508,14 @@ def main(argv):
build_dir = export_dir if options.export_dir else repo.path
changes_file = changes_file_name(source, build_dir, options.builder, dpkg_args)
+ # Run preexport hook
+ if options.export_dir and options.preexport:
+ Hook('Preexport', options.preexport,
+ extra_env=Hook.md(hook_env,
+ {'GBP_GIT_DIR': repo.git_dir,
+ 'GBP_BUILD_DIR': build_dir})
+ )()
+
# Get/build the upstream tarball if necessary. We delay this in
# case of a postexport hook so the hook gets a chance to modify the
# sources and create different tarballs (#640382)
diff --git a/gbp/scripts/buildpackage_rpm.py b/gbp/scripts/buildpackage_rpm.py
index 16b5eb5..952ff24 100644
--- a/gbp/scripts/buildpackage_rpm.py
+++ b/gbp/scripts/buildpackage_rpm.py
@@ -296,7 +296,7 @@ def create_packaging_tag(repo, commit, name, version, options):
def disable_hooks(options):
"""Disable all hooks (except for builder)"""
- for hook in ['cleaner', 'postexport', 'prebuild', 'postbuild', 'posttag']:
+ for hook in ['cleaner', 'preexport', 'postexport', 'prebuild', 'postbuild', 'posttag']:
if getattr(options, hook):
gbp.log.info("Disabling '%s' hook" % hook)
setattr(options, hook, '')
@@ -395,6 +395,10 @@ def build_parser(name, prefix=None, git_treeish=None):
cmd_group.add_config_file_option(option_name="prebuild", dest="prebuild",
help="command to run before a build, default is "
"'%(prebuild)s'")
+ cmd_group.add_config_file_option(option_name="preexport",
+ dest="preexport",
+ help="command to run before exporting the source tree, "
+ "default is '%(preexport)s'")
cmd_group.add_config_file_option(option_name="postexport",
dest="postexport",
help="command to run after exporting the source tree, "
@@ -532,6 +536,13 @@ def main(argv):
options.export_sourcedir))
spec_dir = makedir(os.path.join(export_dir, options.export_specdir))
+ # Run preexport hook
+ if options.preexport:
+ RunAtCommand(options.preexport, shell=True,
+ extra_env={'GBP_GIT_DIR': repo.git_dir,
+ 'GBP_BUILD_DIR': export_dir}
+ )()
+
# Move packaging files to final export dir
gbp.log.debug("Exporting packaging files from '%s' to '%s'" %
(dump_dir, export_dir))
diff --git a/tests/component/deb/test_buildpackage.py b/tests/component/deb/test_buildpackage.py
index 7aa8577..c8a31e7 100644
--- a/tests/component/deb/test_buildpackage.py
+++ b/tests/component/deb/test_buildpackage.py
@@ -303,3 +303,12 @@ class TestBuildpackage(ComponentTestBase):
'--git-tarball-dir=../tarballs'])
eq_(ret, 1)
self._check_log(-1, "gbp:error: Non-native package 'hello-debhelper' has invalid version '3.0'")
+
+ @RepoFixtures.quilt30()
+ def test_preexport(self, repo):
+ """Test the pre-export hook """
+ preexport_out = os.path.join(repo.path, '..', 'preexport.out')
+ self._test_buildpackage(repo, ['--git-export-dir=../export-dir',
+ '--git-preexport=printenv > %s' % preexport_out])
+ ok_(os.path.exists(preexport_out))
+ self.check_hook_vars('../preexport', ["GBP_BUILD_DIR", "GBP_GIT_DIR"])
diff --git a/tests/component/rpm/test_buildpackage_rpm.py b/tests/component/rpm/test_buildpackage_rpm.py
index 78e9ff3..51c76cb 100644
--- a/tests/component/rpm/test_buildpackage_rpm.py
+++ b/tests/component/rpm/test_buildpackage_rpm.py
@@ -467,11 +467,13 @@ class TestGbpRpm(RpmRepoTestBase):
self.init_test_repo('gbp-test-native')
cleaner = 'echo -n cleaner >> ../hooks'
+ preexport = 'echo -n preexport >> $GBP_TMP_DIR/../hooks'
postexport = 'echo -n postexport >> $GBP_TMP_DIR/../hooks'
prebuild = 'echo -n prebuild >> $GBP_BUILD_DIR/../hooks'
postbuild = 'echo -n postbuild >> $GBP_BUILD_DIR/../hooks'
posttag = 'echo -n posttag >> ../hooks'
args = ['--git-cleaner=%s' % cleaner,
+ '--git-preexport=%s' % preexport,
'--git-postexport=%s' % postexport,
'--git-prebuild=%s' % prebuild,
'--git-postbuild=%s' % postbuild,
@@ -483,13 +485,13 @@ class TestGbpRpm(RpmRepoTestBase):
# Export and build scripts are run when not tagging
eq_(mock_gbp(args), 0)
- self.check_and_rm_file('../hooks', 'cleanerpostexportprebuildpostbuild')
+ self.check_and_rm_file('../hooks', 'cleanerpreexportpostexportprebuildpostbuild')
shutil.rmtree('../rpmbuild')
# All hooks are run when building
eq_(mock_gbp(args + ['--git-tag', '--git-packaging-tag=tag2']), 0)
self.check_and_rm_file('../hooks',
- 'cleanerpostexportprebuildpostbuildposttag')
+ 'cleanerpreexportpostexportprebuildpostbuildposttag')
shutil.rmtree('../rpmbuild')
# Run with hooks disabled