[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

[lintian] 01/01: c/triggers: New check



This is an automated email from the git hooks/post-receive script.

nthykier pushed a commit to branch master
in repository lintian.

commit e064821cef7a88868f378d07145c87aa9ac08439
Author: Niels Thykier <niels@thykier.net>
Date:   Fri Apr 21 16:44:30 2017 +0000

    c/triggers: New check
    
    Signed-off-by: Niels Thykier <niels@thykier.net>
---
 checks/triggers.desc                            | 36 ++++++++++++
 checks/triggers.pm                              | 78 +++++++++++++++++++++++++
 data/triggers/trigger-types                     | 19 ++++++
 debian/changelog                                |  2 +
 profiles/debian/main.profile                    |  4 +-
 t/tests/legacy-maintainer-scripts/tags          |  2 +
 t/tests/triggers-general/debian/debian/triggers | 11 ++++
 t/tests/triggers-general/desc                   |  7 +++
 t/tests/triggers-general/tags                   |  2 +
 9 files changed, 159 insertions(+), 2 deletions(-)

diff --git a/checks/triggers.desc b/checks/triggers.desc
new file mode 100644
index 0000000..9382a0e
--- /dev/null
+++ b/checks/triggers.desc
@@ -0,0 +1,36 @@
+Check-Script: triggers
+Author: Niels Thykier <niels@thykier.net>
+Type: binary, udeb
+Info: Check of trigger files in the binary package.
+Needs-Info: bin-pkg-control
+
+Tag: unknown-trigger
+Severity: important
+Certainty: possible
+Info: The package has a trigger that Lintian does not recognise in its
+ control file.
+ .
+ The package may be uninstallable  if dpkg does not support the trigger.
+ .
+ If this is a new type of trigger, then Lintian may simply be out of date.
+ Please verify if the latest version of Lintian know of the trigger or file
+ a bug against Lintian.
+Ref: deb-triggers(5)
+
+Tag: uses-implicit-await-trigger
+Severity: normal
+Certainty: possible
+Info: The listed trigger is present in the control file of the package.
+ The trigger is an await trigger, which may be not obvious from its name.
+ .
+ Await triggers puts rather strong requirements on dpkg that often lead
+ to trigger cycles due to changes in other packages.
+ .
+ If the package does not need the guarantees that dpkg provide to await
+ triggers, please use the "-noawait" variant of the trigger.  This is often
+ the case for packages that use the trigger to compile a form of cache.
+ .
+ If the package do need the guarantees provided by dpkg, then please
+ document the rationale in a comment above the trigger and use the
+ "-await" variant of the trigger to avoid this warning.
+Ref: deb-triggers(5), #774559
diff --git a/checks/triggers.pm b/checks/triggers.pm
new file mode 100644
index 0000000..f891634
--- /dev/null
+++ b/checks/triggers.pm
@@ -0,0 +1,78 @@
+# triggers -- lintian check script -*- perl -*-
+
+# Copyright (C) 2017 Niels Thykier
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, you can find it on the World Wide
+# Web at http://www.gnu.org/copyleft/gpl.html, or write to the Free
+# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
+# MA 02110-1301, USA.
+
+package Lintian::triggers;
+
+use strict;
+use warnings;
+
+use Lintian::Data;
+use Lintian::Tags qw(tag);
+use Lintian::Util qw(fail strip);
+
+sub _parse_trigger_types {
+    my ($key, $val) = @_;
+    my %values;
+    for my $kvstr (split(m/\s*,\s*/, $val)) {
+        my ($k, $v) = split(m/\s*=\s*/, $kvstr, 2);
+        $values{$k} = $v;
+    }
+    if (exists($values{'implicit-await'})) {
+        fail(
+            join(q{ },
+                'Invalid trigger-types data file:',
+                "$key is defined as implicit-await trigger,",
+                'but is not defined as an await trigger')
+        ) if $values{'implicit-await'} and not $values{'await'};
+    }
+    return \%values;
+}
+
+my $TRIGGER_TYPES = Lintian::Data->new('triggers/trigger-types',
+    qr/\s*\Q=>\E\s*/, \&_parse_trigger_types);
+
+sub run {
+    my (undef, undef, $info) = @_;
+    my $triggers_file = $info->control_index('triggers');
+    return if not $triggers_file or not $triggers_file->is_open_ok;
+    my $fd = $triggers_file->open;
+    while (my $line = <$fd>) {
+        strip($line);
+        next if $line =~ m/^(?:\s*)(?:#.*)?$/;
+        my ($trigger_type, $arg) = split(m/\s++/, $line, 2);
+        my $trigger_info = $TRIGGER_TYPES->value($trigger_type);
+        if (not $trigger_info) {
+            tag 'unknown-trigger', $line, "(line $.)";
+            next;
+        }
+        if ($trigger_info->{'implicit-await'}) {
+            tag 'uses-implicit-await-trigger', $line, "(line $.)";
+        }
+    }
+    return;
+}
+
+1;
+
+# Local Variables:
+# indent-tabs-mode: nil
+# cperl-indent-level: 4
+# End:
+# vim: syntax=perl sw=4 sts=4 sr et
diff --git a/data/triggers/trigger-types b/data/triggers/trigger-types
new file mode 100644
index 0000000..d2892fa
--- /dev/null
+++ b/data/triggers/trigger-types
@@ -0,0 +1,19 @@
+# List of known/supported triggers.
+# Format:
+#    <trigger-type> => key=value[, key2=value2, ...]
+#
+# Known key/values:
+#   await (bool): Whether this is an await trigger
+#   implicit-await (bool): Whether this is an implicit await trigger
+#
+# Manually sorted by name.
+#
+
+activate         => await=1, implicit-await=1
+activate-await   => await=1
+activate-noawait => await=0
+
+interest         => await=1, implicit-await=1
+interest-await   => await=1
+interest-noawait => await=0
+
diff --git a/debian/changelog b/debian/changelog
index 6f6a667..95d698f 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -69,6 +69,8 @@ lintian (2.5.51) UNRELEASED; urgency=medium
     + [NT] Fix false-positive "missing-runtime-test-file" when the
       "Tests-Directory" field is set to a single dot.  Thanks to
       Ian Jackson for reporting the issue.  (Closes: #849880)
+  * checks/triggers.{desc,pm}:
+    + [NT] New check.
 
   * coll/debian-readme{,desc}:
     + [NT] Remove.  Merge what little functionality it offers into the
diff --git a/profiles/debian/main.profile b/profiles/debian/main.profile
index 8cc7ce9..3dcd100 100644
--- a/profiles/debian/main.profile
+++ b/profiles/debian/main.profile
@@ -8,6 +8,6 @@ Enable-Tags-From-Check: apache2, application-not-library, automake, binaries,
  group-checks, huge-usr-share, infofiles, init.d, java, lintian, manpages,
  md5sums, menu-format, menus, nmu, obsolete-sites, ocaml, patch-systems, phppear,
  po-debconf, rules, scripts, shared-libs, source-copyright, standards-version,
- symlinks, systemd, testsuite, upstream-metadata, usrmerge, version-substvars,
- watch-file
+ symlinks, systemd, testsuite, triggers, upstream-metadata, usrmerge,
+ version-substvars, watch-file
 
diff --git a/t/tests/legacy-maintainer-scripts/tags b/t/tests/legacy-maintainer-scripts/tags
index 07ef0c4..5b4d80e 100644
--- a/t/tests/legacy-maintainer-scripts/tags
+++ b/t/tests/legacy-maintainer-scripts/tags
@@ -165,4 +165,6 @@ W: maintainer-scripts: possibly-insecure-handling-of-tmp-files-in-maintainer-scr
 W: maintainer-scripts: possibly-insecure-handling-of-tmp-files-in-maintainer-script postrm:40
 W: maintainer-scripts: postinst-does-not-load-confmodule
 W: maintainer-scripts: postrm-does-not-purge-debconf
+W: maintainer-scripts: uses-implicit-await-trigger activate foo (line 2)
+W: maintainer-scripts: uses-implicit-await-trigger interest bar (line 4)
 X: maintainer-scripts: maintainer-script-may-use-dir_to_symlink_helper postinst:5
diff --git a/t/tests/triggers-general/debian/debian/triggers b/t/tests/triggers-general/debian/debian/triggers
new file mode 100644
index 0000000..29179a0
--- /dev/null
+++ b/t/tests/triggers-general/debian/debian/triggers
@@ -0,0 +1,11 @@
+# -noawait: not an issue
+interest-noawait /usr/share/lintian/foo
+# explicit -await: Presumed informed decision (no tag)
+interest-await /usr/share/lintian/bar
+
+
+# implicit -await: Should trigger a tag
+interest /usr/share/lintian/baz
+
+# Not known by lintian
+random-trigger /bar
diff --git a/t/tests/triggers-general/desc b/t/tests/triggers-general/desc
new file mode 100644
index 0000000..6e5c68a
--- /dev/null
+++ b/t/tests/triggers-general/desc
@@ -0,0 +1,7 @@
+Testname: triggers-general
+Sequence: 6000
+Version: 1.0
+Description: Test of the triggers check
+Test-For:
+ unknown-trigger random-trigger
+ uses-implicit-await-trigger
diff --git a/t/tests/triggers-general/tags b/t/tests/triggers-general/tags
new file mode 100644
index 0000000..a984141
--- /dev/null
+++ b/t/tests/triggers-general/tags
@@ -0,0 +1,2 @@
+E: triggers-general: unknown-trigger random-trigger /bar (line 11)
+W: triggers-general: uses-implicit-await-trigger interest /usr/share/lintian/baz (line 8)

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/lintian/lintian.git


Reply to: