summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergio Durigan Junior <sergiodj@debian.org>2020-07-31 11:31:03 -0300
committerGabriel F. T. Gomes <gabriel@inconstante.net.br>2020-07-31 11:35:55 -0300
commit9230db41952b8cf95e3b814455c7f268d485829a (patch)
tree852bb46210b09eee9d544231fb03b3e5caecbffc
parentaa50d1e4f10ef987d6971588f50e325cf9eae9a1 (diff)
downloadbash-completion-9230db41952b8cf95e3b814455c7f268d485829a.tar.gz
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
-rw-r--r--debian/changelog3
-rwxr-xr-xdebian/extra/debhelper/dh_bash-completion63
2 files changed, 66 insertions, 0 deletions
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 (<DH_FILE>) {
+ # 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) {