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().
This commit is contained in:
Ben Hutchings
2019-10-23 20:28:16 +01:00
parent 90d4cf3fc7
commit c5e1ff85eb
4 changed files with 45 additions and 44 deletions

View File

@@ -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

View File

@@ -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,

1
debian/changelog vendored
View File

@@ -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

View File

@@ -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