diff options
author | Markus Lehtonen <markus.lehtonen@linux.intel.com> | 2012-09-25 17:10:26 +0300 |
---|---|---|
committer | Markus Lehtonen <markus.lehtonen@linux.intel.com> | 2012-09-25 17:10:26 +0300 |
commit | 5c2df79cb330de317c31d7b43988fcbdd9a6ec0b (patch) | |
tree | 24bd34dbe4f320ebb73e8400be9a80a3b10b87a4 | |
parent | 7ee1dae099d2ab7f3627122400889d0592e99d6f (diff) | |
download | git-buildpackage-5c2df79cb330de317c31d7b43988fcbdd9a6ec0b.tar.gz git-buildpackage-5c2df79cb330de317c31d7b43988fcbdd9a6ec0b.tar.bz2 git-buildpackage-5c2df79cb330de317c31d7b43988fcbdd9a6ec0b.zip |
rpm: refine prefix guessing from setup macro
If some macros cannot be expanded, use the filename base as the prefix.
Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
-rw-r--r-- | gbp/rpm/__init__.py | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/gbp/rpm/__init__.py b/gbp/rpm/__init__.py index 47797b5d..8c6ef661 100644 --- a/gbp/rpm/__init__.py +++ b/gbp/rpm/__init__.py @@ -48,6 +48,9 @@ class NoSpecError(Exception): """no changelog found""" pass +class MacroExpandError(Exception): + pass + class RpmUpstreamSource(UpstreamSource): """Upstream source class for Debian""" @@ -224,8 +227,7 @@ class SpecFile(object): if matchobj.group(2) in macro_dict: return macro_dict[matchobj.group(2)] - gbp.log.debug("Could not expanded macro '%s'" % matchobj.group(0)) - return matchobj.group(0) + raise MacroExpandError("Unknown macro '%s'" % matchobj.group(0)) def macro_expand(self, text): @@ -530,16 +532,24 @@ class SpecFile(object): # Refine our guess about the prefix if orig_num != None: - setup_opts = self.sources[orig_num]['setup_options'] + orig = self.sources[orig_num] + setup_opts = orig['setup_options'] if setup_opts: if setup_opts.create_dir: - self.sources[orig_num]['prefix'] = '' + orig['prefix'] = '' elif setup_opts.name: - self.sources[orig_num]['prefix'] = self.macro_expand(setup_opts.name) + '/' + try: + orig['prefix'] = self.macro_expand(setup_opts.name) + \ + '/' + except MacroExpandError as err: + gbp.log.warn("Couldn't determine prefix from %%setup "\ + "macro (%s). Using filename base as a " \ + "fallback" % err) + orig['prefix'] = orig['filename_base'] + '/' else: # RPM default - self.sources[orig_num]['prefix'] = "%s-%s/" % (self.name, - self.upstreamversion) + orig['prefix'] = "%s-%s/" % (self.name, + self.upstreamversion) return orig_num |