Skip to content

Commit

Permalink
Added preexport option (not completed).
Browse files Browse the repository at this point in the history
  • Loading branch information
KrullBorg committed Jan 21, 2017
1 parent f30bb98 commit 40936d2
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 3 deletions.
2 changes: 1 addition & 1 deletion debian/gbp.completion
Expand Up @@ -54,7 +54,7 @@ _gbp_comp ()
local cbdist_opts=${5:-"--git-dist\="}
local remote_config_opts="--remote-config\="
local file_opts="--postimport\= --git-builder\= --git-cleaner\= \
--git-export-dir\= --git-postbuild\= --git-postexport\= \
--git-export-dir\= --git-postbuild\= --git-preexport\= --git-postexport\= \
--git-posttag\= --git-prebuild\= --git-tarball-dir\="
local start_opt=""

Expand Down
17 changes: 17 additions & 0 deletions docs/manpages/gbp-buildpackage.sgml
Expand Up @@ -40,6 +40,7 @@
<arg><option>--git-keyid=</option><replaceable>GPG-KEYID</replaceable></arg>
<arg><option>--git-posttag=</option><replaceable>COMMAND</replaceable></arg>
<arg><option>--git-postbuild=</option><replaceable>COMMAND</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-[no-]hooks</option></arg>
Expand Down Expand Up @@ -394,6 +395,22 @@
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>--git-preexport=</option><replaceable>COMMAND</replaceable>
</term>
<listitem>
<para>
Execute <replaceable>COMMAND</replaceable> before exporting the source
tree, but after export dir is created - 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_EXPORT_DIR</envar> (the directory where the sources
will be exported).
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>--git-postexport=</option><replaceable>COMMAND</replaceable>
</term>
Expand Down
1 change: 1 addition & 0 deletions gbp/config.py
Expand Up @@ -117,6 +117,7 @@ class GbpOptionParser(OptionParser):
'postbuild': '',
'prebuild': '',
'postclone': '',
'preexport': '',
'postexport': '',
'postimport': '',
'hooks': 'True',
Expand Down
13 changes: 12 additions & 1 deletion gbp/scripts/buildpackage.py
Expand Up @@ -488,7 +488,7 @@ def setup_pbuilder(options, repo, native):

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, '')
Expand Down Expand Up @@ -583,6 +583,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 but after export dir is created, "
"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'")
Expand Down Expand Up @@ -701,6 +704,14 @@ def main(argv):
output_dir = prepare_output_dir(options.export_dir)
tarball_dir = options.tarball_dir or output_dir

# 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_EXPORT_DIR': output_dir})
)(dir=output_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)
Expand Down
13 changes: 12 additions & 1 deletion gbp/scripts/buildpackage_rpm.py
Expand Up @@ -292,7 +292,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, '')
Expand Down Expand Up @@ -391,6 +391,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 but after export dir is created, "
"default is '%(preexport)s'")
cmd_group.add_config_file_option(option_name="postexport",
dest="postexport",
help="command to run after exporting the source tree, "
Expand Down Expand Up @@ -527,6 +531,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.reexport, shell=True,
extra_env={'GBP_GIT_DIR': repo.git_dir,
'GBP_EXPORT_DIR': export_dir}
)(dir=export_dir)

# Move packaging files to final export dir
gbp.log.debug("Exporting packaging files from '%s' to '%s'" %
(dump_dir, export_dir))
Expand Down
7 changes: 7 additions & 0 deletions tests/component/deb/test_buildpackage.py
Expand Up @@ -180,3 +180,10 @@ def test_tarball_max_compression(self, repo):
self._test_buildpackage(repo, ['--git-no-pristine-tar', '--git-compression-level=9'])
out = subprocess.check_output(["file", "../hello-debhelper_2.8.orig.tar.gz"])
ok_("max compression" in out)

@RepoFixtures.quilt30
def test_pre_export_buildpackage(self):
"""Test that building with a pre export command works"""
self._test_buildpackage(repo, ['--git-export-dir=../foo/bar',
'--git-preexport="date > $(GBP_EXPORT_DIR)/preexported"'])
ok_(os.path.isfile('../foo/bar/preexported'))

0 comments on commit 40936d2

Please sign in to comment.