Add an option to exclude copying some of the files from the source tree
to the packaging directory (a single regular expression).

This can be handy when running gbp buildpackage-rpm from a complete
source tree in a non-native mode and and some files in the top-level
directory can't or should not be copies to the packaging directory.

Signed-off-by: Tzafrir Cohen <tzaf...@debian.org>
---
 gbp/config.py                                |  1 +
 gbp/scripts/buildpackage_rpm.py              |  7 +++++++
 tests/component/rpm/test_buildpackage_rpm.py | 14 ++++++++++++++
 3 files changed, 22 insertions(+)

diff --git a/gbp/config.py b/gbp/config.py
index 3d254ee..bc43485 100644
--- a/gbp/config.py
+++ b/gbp/config.py
@@ -651,6 +651,7 @@ class GbpOptionParserRpm(GbpOptionParser):
             'vendor'                    : 'Downstream',
             'packaging-branch'          : 'master',
             'packaging-dir'             : '',
+            'packaging-exclude'             : '',
             'packaging-tag-msg'         : ('%(pkg)s (vendor)s release '
                                                          '%(version)s'),
             'packaging-tag'             : 'packaging/%(version)s',
diff --git a/gbp/scripts/buildpackage_rpm.py b/gbp/scripts/buildpackage_rpm.py
index 00582df..340f130 100644
--- a/gbp/scripts/buildpackage_rpm.py
+++ b/gbp/scripts/buildpackage_rpm.py
@@ -21,6 +21,7 @@
 from six.moves import configparser
 import os
 import shutil
+import re
 import sys
 
 import gbp.log
@@ -438,6 +439,10 @@ def build_parser(name, prefix=None, git_treeish=None):
                          "'%(export)s'")
     export_group.add_config_file_option(option_name="packaging-dir",
                     dest="packaging_dir")
+    export_group.add_config_file_option(option_name="packaging-exclude",
+                    dest="packaging_exclude",
+                    help="pattern of files to exclude from exporting from " +
+                    "top-level source directory to packaging directory")
     export_group.add_config_file_option(option_name="spec-file",
                     dest="spec_file")
     return parser
@@ -548,6 +553,8 @@ def main(argv):
                 src = os.path.join(dump_dir, fname)
                 if fname == spec.specfile:
                     dst = os.path.join(spec_dir, fname)
+                elif re.match(options.packaging_exclude, fname):
+                    continue
                 else:
                     dst = os.path.join(source_dir, fname)
                 try:
diff --git a/tests/component/rpm/test_buildpackage_rpm.py 
b/tests/component/rpm/test_buildpackage_rpm.py
index 4f0c290..6dd5317 100644
--- a/tests/component/rpm/test_buildpackage_rpm.py
+++ b/tests/component/rpm/test_buildpackage_rpm.py
@@ -24,6 +24,7 @@ import re
 import shutil
 import stat
 import subprocess
+import tempfile
 
 from nose import SkipTest
 from nose.tools import assert_raises, eq_, ok_ # pylint: disable=E0611
@@ -369,6 +370,19 @@ class TestGbpRpm(RpmRepoTestBase):
         eq_(mock_gbp(['--git-builder=true']), 1)
         eq_(mock_gbp(['--git-ignore-branch', '--git-builder=true']), 0)
 
+    def test_packaging_exclude_option(self):
+        """Test the --packaging-exclude option"""
+        repo = self.init_test_repo('gbp-test')
+
+        packaging_dir = tempfile.mkdtemp(prefix='gbp_packaging-')
+        eq_(mock_gbp(['--git-no-build', '--git-packaging-exclude=\.patch',
+                      '--git-packaging-dir=' + packaging_dir]), 0)
+
+        # Test building when not on any branch
+        repo.set_branch(repo.rev_parse('HEAD'))
+        eq_(glob.glob("../rpmbuild/SOURCES/*.patch"), [])
+        shutil.rmtree(packaging_dir)
+
     def test_option_submodules(self):
         """Test the --git-submodules option"""
         repo = self.init_test_repo('gbp-test')
-- 
2.7.0


-- 
Tzafrir Cohen         | tzaf...@jabber.org | VIM is
http://tzafrir.org.il |                    | a Mutt's
tzaf...@cohens.org.il |                    |  best
tzaf...@debian.org    |                    | friend
_______________________________________________
git-buildpackage mailing list
git-buildpackage@lists.sigxcpu.org
http://lists.sigxcpu.org/mailman/listinfo/git-buildpackage

Reply via email to