From patchwork Thu Apr 11 01:45:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emil Velikov via arch-projects X-Patchwork-Id: 1064 Return-Path: Delivered-To: patchwork@archlinux.org Received: from apollo.archlinux.org (localhost [127.0.0.1]) by apollo.archlinux.org (Postfix) with ESMTP id A57D3D2CEE4D for ; Thu, 11 Apr 2019 01:45:39 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on apollo X-Spam-Level: X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00=-1, DKIMWL_WL_HIGH=-0.001,DKIM_SIGNED=0.1,DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,MAILING_LIST_MULTI=-1,RCVD_IN_DNSWL_MED=-2.3, T_DMARC_POLICY_NONE=0.01 autolearn=ham autolearn_force=no version=3.4.2 X-Spam-BL-Results: [127.0.0.10] [127.0.9.2] Received: from orion.archlinux.org (orion.archlinux.org [88.198.91.70]) by apollo.archlinux.org (Postfix) with ESMTPS for ; Thu, 11 Apr 2019 01:45:39 +0000 (UTC) Received: from orion.archlinux.org (localhost [127.0.0.1]) by orion.archlinux.org (Postfix) with ESMTP id A5E7D11E265EBD; Thu, 11 Apr 2019 01:45:37 +0000 (UTC) Received: from luna.archlinux.org (luna.archlinux.org [5.9.250.164]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits)) (No client certificate requested) by orion.archlinux.org (Postfix) with ESMTPS; Thu, 11 Apr 2019 01:45:37 +0000 (UTC) Received: from luna.archlinux.org (luna.archlinux.org [127.0.0.1]) by luna.archlinux.org (Postfix) with ESMTP id 8218E2C580; Thu, 11 Apr 2019 01:45:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=archlinux.org; s=luna2; t=1554947137; bh=m/1zhNdhCFQ33o0DNDLBgPZUIn510obh1WkkQb+6x9k=; h=To:Date:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc; b=T3buD3wdzJVF4rp33b147Xqs0mNyQjQM/p1dS1FJzLKutHlIT1Pvv5V/QjP5IJCyq sCdxuNtGsDd+Su2ENx3ynQSCvTE+5aMAY/zcOqLOr/Q+EPsqXOPPl+XGzS/hAFrb6Z HHYmXfFwNHV3364hKAYozMx24QhcVVeNYkqVRMhJOzxU7gD+G4D175zKahnOb/6PkM aQCEASFiixKU13WF8HgO8ELaC90d7FNLbr4SJtYBjML9auaeZ30836s3S7eWdALkED wE3u+vwSB5FMtiOlikszr0ZwGiRS5VPi0RPLmlbOVO8vddDarYAym/cuKQRCmrUMji 1vxcZ83YAR1q9JgBeoQ1w3Bl4iTfWlezy07p6xzTW+t7bDlTM9JBb+q8dAnydj3kgf QbhA/ykB1fWYdblDEvEAozrbcbQMIgYS6zpX5xxRlrv0+mWEIS0abLiSIG8o0iHG6/ xJM2gEMqhy8ddiCey+KEDBZB8lRLMI+n/8NAWD9HnQEjaEhVhXe3Nf10vRhVXMZamM T5btikB0org11tZ/s1DxiIXoXkb4g8luDdX+9DijUZ+gu0kYkViyqOZHsCjOBp9/wb ObD7LkizMuMwGT2k1knR8WG5pdVhKcODyauCJFjfyTPHgT7reNJa31nb9Qqfxo3WxF kFeVklfEedOqCcNLSPu1UpLc= Received: from luna.archlinux.org (luna.archlinux.org [127.0.0.1]) by luna.archlinux.org (Postfix) with ESMTP id 662D32C57C for ; Thu, 11 Apr 2019 01:45:35 +0000 (UTC) Received: from orion.archlinux.org (orion.archlinux.org [88.198.91.70]) by luna.archlinux.org (Postfix) with ESMTPS for ; Thu, 11 Apr 2019 01:45:35 +0000 (UTC) Received: from orion.archlinux.org (localhost [127.0.0.1]) by orion.archlinux.org (Postfix) with ESMTP id 0638711E265EBA; Thu, 11 Apr 2019 01:45:34 +0000 (UTC) Received: from localhost.localdomain (ool-3f8fe1f1.dyn.optonline.net [63.143.225.241]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: eschwartz) by orion.archlinux.org (Postfix) with ESMTPSA id 798F811E265EB9; Thu, 11 Apr 2019 01:45:33 +0000 (UTC) To: arch-projects@archlinux.org Date: Wed, 10 Apr 2019 21:45:19 -0400 Message-Id: <20190411014519.25059-1-eschwartz@archlinux.org> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 Subject: [arch-projects] [namcap] [PATCH] Add rule to report on unneeded dependencies from hooks X-BeenThere: arch-projects@archlinux.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Arch Linux projects development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Eli Schwartz via arch-projects Reply-To: Arch Linux projects development discussion Cc: Eli Schwartz Errors-To: arch-projects-bounces@archlinux.org Sender: "arch-projects" Just as it is unnecessary to run certain commands in a post_upgrade script, if a hook already runs it, so too is it usually unnecessary to depend on the package that installs the hook. Sometimes these dependencies are left in even when the install script is removed, because people lack understanding in the true subtleties of hooks and the commands they run -- but the commands do not depend on the list of files which trigger them in order to function, and are fully operative when installed later. In fact, they will already be required by the software that uses the results. e.g. desktop-file-utils and shared-mime-info provide hooks to compile the mime and desktop file databases, but upon first installing the hook, a full database will already be compiled. The hook does not need to be triggered by the filepath, and thus does not need to be a dependency of every package that provides a desktop or mime file. Instead, desktop environments which need a mime/desktop file database will depend on the package and thereby ensure the database exists when needed. Signed-off-by: Eli Schwartz --- With this plus my previous patch, namcap will stop warning when these dependencies are missing, and instead, warn when they are used. I've yet to hear a convincing reason why these dependencies would be wanted -- I suspect they exist mostly because of inertia, or because they were copied from another (historic?) PKGBUILD that was used as a role model. Namcap/rules/__init__.py | 1 + Namcap/rules/hookdepends.py | 48 +++++++++++++++++++++++++++++++++++++ namcap-tags | 8 ++++--- 3 files changed, 54 insertions(+), 3 deletions(-) create mode 100644 Namcap/rules/hookdepends.py diff --git a/Namcap/rules/__init__.py b/Namcap/rules/__init__.py index 1e05326..525dbc6 100644 --- a/Namcap/rules/__init__.py +++ b/Namcap/rules/__init__.py @@ -31,6 +31,7 @@ from . import ( fileownership, gnomemime, hardlinks, + hookdepends, infodirectory, javafiles, kdeprograms, diff --git a/Namcap/rules/hookdepends.py b/Namcap/rules/hookdepends.py new file mode 100644 index 0000000..dcf03a1 --- /dev/null +++ b/Namcap/rules/hookdepends.py @@ -0,0 +1,48 @@ +# +# namcap rules - hookdepends +# Copyright (C) 2019 Eli Schwartz +# Copyright (C) 2016 Kyle Keen +# +# 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, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# + +import re +from Namcap.ruleclass import * + +class HookDependsRule(TarballRule): + name = "hookdepends" + description = "Check for redundant hook dependencies" + subrules = [ + { + 'path': '^usr/share/applications/.*\.desktop$', + 'dep': 'desktop-file-utils', + }, + { + 'path': '^usr/share/mime$', + 'dep': 'shared-mime-info', + } + ] + def analyze(self, pkginfo, tar): + names = [entry.name for entry in tar] + for subrule in self.subrules: + pattern = re.compile(subrule['path']) + if any(pattern.search(n) for n in names): + dep = subrule['dep'] + if dep in pkginfo['depends']: + self.warnings = [('external-hooks-unneeded-warning', ())] + self.infos.append(('external-hooks-unneeded-name %s', dep)) + + +# vim: set ts=4 sw=4 noet: diff --git a/namcap-tags b/namcap-tags index 17b9506..84cc3f7 100644 --- a/namcap-tags +++ b/namcap-tags @@ -1,11 +1,11 @@ # namcap tags file -# The tags file consists of lines specifying the human readable form of the -# hyphenated tags used in the namcap code. A line beginning with a '#' is +# The tags file consists of lines specifying the human readable form of the +# hyphenated tags used in the namcap code. A line beginning with a '#' is # treated as a comment. Otherwise the format of the file is: # # machine-parseable-tag %s :: This is machine parseable tag %s # -# Note that a double colon (::) is used to separate the hyphenated tag from the +# Note that a double colon (::) is used to separate the hyphenated tag from the # human readable description. # rules tags @@ -26,6 +26,8 @@ empty-directory %s :: Directory (%s) is empty error-running-rule %s :: Error running rule '%s' external-hooks-name %s :: .INSTALL file runs a command (%s) provided by hooks. external-hooks-warning :: .INSTALL file runs a command provided by hooks. +external-hooks-unneeded-name %s :: unneeded dependency on a package (%s) run when needed by hooks. +external-hooks-unneeded-warning :: unneeded dependency on a package run when needed by hooks. extra-var-begins-without-underscore %s :: Non standard variable '%s' doesn't start with an underscore file-in-non-standard-dir %s :: File (%s) exists in a non-standard directory. file-in-temporary-dir %s :: File (%s) is in a temporary directory.