diff options
author | Ben Hutchings <ben@decadent.org.uk> | 2019-10-23 20:28:16 +0100 |
---|---|---|
committer | Ben Hutchings <ben@decadent.org.uk> | 2019-10-23 21:47:25 +0100 |
commit | c5e1ff85ebc20da2f2b79ea728a76756f997c5e8 (patch) | |
tree | 3a44fcec1e9c1f0e60a0e9bd54b70a9a7522ebbf | |
parent | 90d4cf3fc79784e029999d44b8d2c2a1f438f739 (diff) | |
download | kernel_replicant_linux-c5e1ff85ebc20da2f2b79ea728a76756f997c5e8.tar.gz kernel_replicant_linux-c5e1ff85ebc20da2f2b79ea728a76756f997c5e8.tar.bz2 kernel_replicant_linux-c5e1ff85ebc20da2f2b79ea728a76756f997c5e8.zip |
gencontrol: Generalise substitution of debhelper config template
Currently we have two copies of the _substitute_file() method, and
lots of somewhat similar invocations of it since different binary
packages need different sets of debhelper configs.
We already name the templates in a fairly consistent way, so we can
replace this with a loop that tries to expand all possible templates
for a package and ignores those that are missing. Add a method for
this to the Gencontrol base class and use it in both subclasses
where we prevously used _substitute_file().
-rwxr-xr-x | debian/bin/gencontrol.py | 51 | ||||
-rwxr-xr-x | debian/bin/gencontrol_signed.py | 21 | ||||
-rw-r--r-- | debian/changelog | 1 | ||||
-rw-r--r-- | debian/lib/python/debian_linux/gencontrol.py | 16 |
4 files changed, 45 insertions, 44 deletions
diff --git a/debian/bin/gencontrol.py b/debian/bin/gencontrol.py index 9b8f36c29cd5..316e50af4538 100755 --- a/debian/bin/gencontrol.py +++ b/debian/bin/gencontrol.py @@ -73,10 +73,6 @@ class Gencontrol(Base): if src in data or not optional: makeflags[dst] = data[src] - def _substitute_file(self, template, vars, target, append=False): - with open(target, 'a' if append else 'w') as f: - f.write(self.substitute(self.templates[template], vars)) - def do_main_setup(self, vars, makeflags, extra): super(Gencontrol, self).do_main_setup(vars, makeflags, extra) makeflags.update({ @@ -191,9 +187,8 @@ class Gencontrol(Base): if self.config.merge('packages').get('tools-versioned', True): packages.extend(self.process_packages( self.templates["control.tools-versioned"], vars)) - self._substitute_file( - 'perf.lintian-overrides', vars, - 'debian/linux-perf-%(version)s.lintian-overrides' % vars) + self.substitute_debhelper_config('perf', vars, + 'linux-perf-%(version)s' % vars) if do_meta: packages.extend(self.process_packages( self.templates["control.tools-versioned.meta"], vars)) @@ -493,12 +488,9 @@ class Gencontrol(Base): if do_meta and not build_signed: packages_own.extend(self.process_packages( self.templates["control.image.meta"], vars)) - - # Include a bug presubj message directing reporters to the real - # image package. - self._substitute_file( - "image.meta.bug-presubj", vars, - "debian/linux-image%(localversion)s.bug-presubj" % vars) + self.substitute_debhelper_config( + "image.meta", vars, + "linux-image%(localversion)s" % vars) package_headers = self.process_package(headers[0], vars) package_headers['Depends'].extend(relations_compiler_headers) @@ -533,10 +525,9 @@ class Gencontrol(Base): if do_meta: packages_own.extend(self.process_packages( self.templates["control.image-dbg.meta"], vars)) - self._substitute_file( - 'image-dbg.meta.lintian-overrides', vars, - 'debian/linux-image%(localversion)s-dbg.lintian-overrides' - % vars) + self.substitute_debhelper_config( + 'image-dbg.meta', vars, + 'linux-image%(localversion)s-dbg' % vars) merge_packages(packages, packages_own, arch) @@ -630,22 +621,18 @@ class Gencontrol(Base): cmds=["$(MAKE) -f debian/rules.real %s %s" % (merged_config, makeflags)]) - # Substitute kernel version etc. into maintainer scripts, - # translations and lintian overrides - self._substitute_file( - 'headers.postinst', vars, - 'debian/linux-headers-%(abiname)s%(localversion)s.postinst' % vars) - for name in ['postinst', 'postrm', 'preinst', 'prerm']: - self._substitute_file('image.%s' % name, vars, - 'debian/%s.%s' % - (image_main['Package'], name)) + self.substitute_debhelper_config( + 'headers', vars, + 'linux-headers-%(abiname)s%(localversion)s' % vars) + self.substitute_debhelper_config('image', vars, image_main['Package']) if build_debug: - debug_lintian_over = \ - 'debian/linux-image-%(abiname)s%(localversion)s-dbg' \ - '.lintian-overrides' % vars - self._substitute_file('image-dbg.lintian-overrides', vars, - debug_lintian_over) - os.chmod(debug_lintian_over, 0o755) + self.substitute_debhelper_config( + 'image-dbg', vars, + 'linux-image-%(abiname)s%(localversion)s-dbg' % vars) + # XXX Should be done automatically based on template perms? + os.chmod('debian/linux-image-%(abiname)s%(localversion)s-dbg' + '.lintian-overrides' % vars, + 0o755) def process_changelog(self): version = self.version = self.changelog[0].version diff --git a/debian/bin/gencontrol_signed.py b/debian/bin/gencontrol_signed.py index 729309705fea..6b6e192b0c8a 100755 --- a/debian/bin/gencontrol_signed.py +++ b/debian/bin/gencontrol_signed.py @@ -54,10 +54,6 @@ class Gencontrol(Base): self.image_packages = [] - def _substitute_file(self, template, vars, target, append=False): - with codecs.open(target, 'a' if append else 'w', 'utf-8') as f: - f.write(self.substitute(self.templates[template], vars)) - def do_main_setup(self, vars, makeflags, extra): makeflags['VERSION'] = self.version.linux_version makeflags['GENCONTROL_ARGS'] = ( @@ -216,17 +212,20 @@ class Gencontrol(Base): "PACKAGE_NAME='%s' %s" % (packages_meta[0]['Package'], makeflags)] - # Include a bug presubj message directing reporters to the real - # image package. - self._substitute_file( - "image.meta.bug-presubj", vars, - self.template_debian_dir - + "/linux-image%(localversion)s.bug-presubj" % vars) + self.substitute_debhelper_config( + 'image', vars, + 'linux-image%(localversion)s' % vars, + output_dir=self.template_debian_dir) merge_packages(packages, packages_own, arch) makefile.add('binary-arch_%s_%s_%s_real' % (arch, featureset, flavour), cmds=cmds_binary_arch) + self.substitute_debhelper_config( + 'image', vars, + 'linux-image-%(abiname)s%(localversion)s' % vars, + output_dir=self.template_debian_dir) + os.makedirs(self.package_dir + '/usr/share/lintian/overrides', 0o755, exist_ok=True) with open(self.package_dir @@ -237,8 +236,6 @@ class Gencontrol(Base): + '/linux-image-%s%s.%s' % (vars['abiname'], vars['localversion'], script_base)) - self._substitute_file('image.%s' % script_base, vars, - script_name) lintian_overrides.write('%s: script-not-executable %s\n' % (vars['template'], os.path.relpath(script_name, diff --git a/debian/changelog b/debian/changelog index e2605493673b..7398cea6b988 100644 --- a/debian/changelog +++ b/debian/changelog @@ -6,6 +6,7 @@ linux (5.3.7-2) UNRELEASED; urgency=medium * debian/bin/gencontrol{,_signed}.py: Use vars parameter instead of self.vars * debian/bin/gencontrol{,_signed}.py: Use %(name)s to format template vars * debian/.gitignore, debian/rules: Generalise patterns for generated files + * gencontrol: Generalise substitution of debhelper config template -- Ben Hutchings <ben@decadent.org.uk> Wed, 23 Oct 2019 18:32:15 +0100 diff --git a/debian/lib/python/debian_linux/gencontrol.py b/debian/lib/python/debian_linux/gencontrol.py index 69619da3ee10..a49b21faa199 100644 --- a/debian/lib/python/debian_linux/gencontrol.py +++ b/debian/lib/python/debian_linux/gencontrol.py @@ -350,6 +350,22 @@ class Gencontrol(object): return re.sub(r'@([-_a-z0-9]+)@', subst, str(s)) + # Substitute kernel version etc. into maintainer scripts, + # bug presubj message and lintian overrides + def substitute_debhelper_config(self, prefix, vars, package_name, + output_dir='debian'): + for id in ['bug-presubj', 'lintian-overrides', + 'postinst', 'postrm', 'preinst', 'prerm']: + name = '%s.%s' % (prefix, id) + try: + template = self.templates[name] + except KeyError: + continue + else: + target = '%s/%s.%s' % (output_dir, package_name, id) + with open(target, 'w') as f: + f.write(self.substitute(template, vars)) + def merge_build_depends(self, packages): # Merge Build-Depends pseudo-fields from binary packages into the # source package |