From 9230db41952b8cf95e3b814455c7f268d485829a Mon Sep 17 00:00:00 2001 From: Sergio Durigan Junior Date: Fri, 31 Jul 2020 11:31:03 -0300 Subject: Fix dh_bash-completion for debhelper 13 As reported in bug #965225, dh_bash-completion fails with debhelper 13. Patch submitted via BTS [2]. [1] https://bugs.debian.org/965225 [2] https://bugs.debian.org/965225#19 --- debian/changelog | 3 ++ debian/extra/debhelper/dh_bash-completion | 63 +++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) (limited to 'debian') diff --git a/debian/changelog b/debian/changelog index eb65c105..546eedd7 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,5 +1,8 @@ bash-completion (1:2.10-2) UNRELEASED; urgency=medium + [ Sergio Durigan Junior ] + * Fix dh_bash-completion for debhelper 13 (Closes: #965225). + [ Gabriel F. T. Gomes ] * Update standards version to 4.5.0, no changes needed. * Bump debhelper from 12 to 13. diff --git a/debian/extra/debhelper/dh_bash-completion b/debian/extra/debhelper/dh_bash-completion index f96704b0..d1d9bf2e 100755 --- a/debian/extra/debhelper/dh_bash-completion +++ b/debian/extra/debhelper/dh_bash-completion @@ -33,6 +33,60 @@ completion snippet after. The file format is as follows: =cut +# This helper function tries to determine (using some poor man's +# heuristics) whether $file (its first and only argument) is a +# filelist containing a list of files to be installed by us, or a +# bash-completion script, which should itself be installed. +# +# If we're dealing with a filelist, return 1. Otherwise, return 0. +sub is_filelist { + # The file to be checked. + my ($file) = @_; + + open (DH_FILE, '<', $file) || error("cannot read $file: $!"); + + while () { + # Get rid of lines containing just spaces or comments. + chomp; + s/^\s++//; + next if /^#/; + s/\s++$//; + + # We always ignore/permit empty lines + next if $_ eq ''; + + # This is the heart of the script. Here, we check for some + # well-known idioms on bash scripts, and try to determine if + # they're present in the file we're examining. We assume that + # if they are, then this means the file is a bash-completion + # script. + # + # The regexes check: + # + # - If we're calling the bash function "complete", which is a + # pretty common thing to do in bash-completion scripts, or + # + # - If we're using the $(program) way of executing a program. + # We don't take into account multi-line statements. Or + # + # - If we're calling the bash function "compgen", which is + # also a pretty common thing that bash-completion scripts + # do. Or + # + # - If we see an "if...then" construction in the file. We + # take into account multi-line statements. + if (/\s*complete.*-[A-Za-z].*/ + || /\$\(.*\)/ + || /\s*compgen.*-[A-Za-z].*/ + || /\s*if.*;.*then/s) { + return 0; + } + } + + # If we reached the end, this is not a bash-completion script. + return 1; +} + init(); my $srcdir = '.'; @@ -53,6 +107,15 @@ PKG: foreach my $package (@{$dh{DOPACKAGES}}) { if ($completions) { install_dir($bc_dir); + # Invoke our heuristic function to try and determine + # if we're dealing with a filelist or with a + # bash-completion script. + if (!is_filelist($completions)) { + verbose_print "detected $completions as a bash-completion script"; + install_file($completions, "$bc_dir/$package"); + next PKG + } + # try parsing a list of files @install = filedoublearray($completions); foreach my $set (@install) { -- cgit v1.2.1