From patchwork Fri Jan 17 13:19:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Panteleev X-Patchwork-Id: 1453 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 8DEB4165B96C1 for ; Fri, 17 Jan 2020 13:20:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.3 (2019-12-06) on apollo.archlinux.org X-Spam-Level: X-Spam-Status: No, score=-3.3 required=5.0 tests=MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3,SPF_HELO_NONE=0.001,T_DMARC_TESTS_FAIL=0.01 autolearn=ham autolearn_force=no version=3.4.3 X-Spam-BL-Results: [127.0.9.2] [127.0.0.6] Received: from orion.archlinux.org (orion.archlinux.org [88.198.91.70]) by apollo.archlinux.org (Postfix) with ESMTPS for ; Fri, 17 Jan 2020 13:20:29 +0000 (UTC) Received: from orion.archlinux.org (localhost [127.0.0.1]) by orion.archlinux.org (Postfix) with ESMTP id 4E3E2182649B64; Fri, 17 Jan 2020 13:20:08 +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) (Authenticated sender: luna) by orion.archlinux.org (Postfix) with ESMTPSA id 636B5182649B2E; Fri, 17 Jan 2020 13:19:59 +0000 (UTC) Authentication-Results: orion.archlinux.org; dkim=none Received: from luna.archlinux.org (luna.archlinux.org [127.0.0.1]) by luna.archlinux.org (Postfix) with ESMTP id 49BCA2BFEA; Fri, 17 Jan 2020 13:19:59 +0000 (UTC) Authentication-Results: luna.archlinux.org; dkim=none Received: from luna.archlinux.org (luna.archlinux.org [127.0.0.1]) by luna.archlinux.org (Postfix) with ESMTP id E90792BFEA for ; Fri, 17 Jan 2020 13:19:53 +0000 (UTC) Received: from orion.archlinux.org (orion.archlinux.org [IPv6:2a01:4f8:160:6087::1]) by luna.archlinux.org (Postfix) with ESMTPS for ; Fri, 17 Jan 2020 13:19:53 +0000 (UTC) Received: from orion.archlinux.org (localhost [127.0.0.1]) by orion.archlinux.org (Postfix) with ESMTP id 94121182649B09 for ; Fri, 17 Jan 2020 13:19:49 +0000 (UTC) Received: from mail-wr1-f67.google.com (mail-wr1-f67.google.com [209.85.221.67]) (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) by orion.archlinux.org (Postfix) with ESMTPS for ; Fri, 17 Jan 2020 13:19:49 +0000 (UTC) Received: by mail-wr1-f67.google.com with SMTP id g17so22667640wro.2 for ; Fri, 17 Jan 2020 05:19:49 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=5DUEMYcd7hh3H59sFTRDI6HnlWbpQxS6I4ge7j0l20Y=; b=G4NSzgd7LakUbHnQTeyKAMrMqMs1e+zPMvJawsqedTJMRciMKE1QNGaYTo7G5sZDS5 KAUkyxfypcPkMLKo+2dSYh7Um+8xWznNUM4FQnO1hSDYgT3SHkRkSLUJ5XqYlrYXgxJI P4mQ5tAWq/uJXJ1OomGMck0/jwTXuB6GTHG3+FH8MSff2BYqQbLMyJ+schsCR008//Sg IkHExJ1ZFUCND8so/OB1yGB/etclZCEs+IfpJUgoDZ+tiPm+KHrBr2w/ARPa+7pKvX9M ic3XeMEpdNBMvrjUQR7bJ0hpglD2HgxOc1Kmn0Ad/SWp8b2bP4V+uxIQhOcjfcXBWWq/ Dkcw== X-Gm-Message-State: APjAAAXMzfrqg8sW7w47AUhYyjllQxTpNcr6rEqyLGjjgRCinmgTb0d6 XSSiLDGmS87hMJMKdB92sL6I+isvYRg= X-Google-Smtp-Source: APXvYqzC5SenvYFGv1wEun0lFafNaujFWfiqJ3BRTMowk8oP/QJCFa9op3MepnaeCgGjTHN4lTRmSw== X-Received: by 2002:a5d:6390:: with SMTP id p16mr3179004wru.170.1579267188787; Fri, 17 Jan 2020 05:19:48 -0800 (PST) Received: from home.thecybershadow.net ([89.28.117.31]) by smtp.gmail.com with ESMTPSA id z124sm10577779wmc.20.2020.01.17.05.19.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Jan 2020 05:19:48 -0800 (PST) From: Vladimir Panteleev To: arch-projects@archlinux.org Date: Fri, 17 Jan 2020 13:19:31 +0000 Message-Id: <20200117131931.1746498-5-archlinux@thecybershadow.net> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200117131931.1746498-1-archlinux@thecybershadow.net> References: <20200117131931.1746498-1-archlinux@thecybershadow.net> MIME-Version: 1.0 Subject: [arch-projects] [namcap] [PATCH 5/5] Fix shebangdepends rule for programs found in noncanonical locations 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: , Reply-To: Arch Linux projects development discussion Cc: Vladimir Panteleev Errors-To: arch-projects-bounces@archlinux.org Sender: "arch-projects" If the user has a non-canonical (i.e. symlinked on Arch) location in front of their $PATH, such as /usr/sbin, shutil.which will return locations with that path. This later causes the rule to fail to find the binary in any packages, causing spurious library-no-package-associated and dependency-not-needed warnings. Fix this by resolving all symlinks for executables (using os.path.realpath) before trying to find them among installed packages. --- Namcap/rules/shebangdepends.py | 3 +- Namcap/tests/package/test_shebangdepends.py | 38 +++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/Namcap/rules/shebangdepends.py b/Namcap/rules/shebangdepends.py index 07896df..fc359c3 100644 --- a/Namcap/rules/shebangdepends.py +++ b/Namcap/rules/shebangdepends.py @@ -21,7 +21,7 @@ """Checks dependencies on programs specified in shebangs.""" -import shutil +import shutil, os.path import Namcap.package from Namcap.util import is_script, script_type from Namcap.ruleclass import * @@ -59,6 +59,7 @@ def findowners(scriptlist): out = shutil.which(s) if not out: continue + out = os.path.realpath(out) # strip leading slash scriptpath = out.lstrip('/') diff --git a/Namcap/tests/package/test_shebangdepends.py b/Namcap/tests/package/test_shebangdepends.py index dbacd86..b92e9fe 100644 --- a/Namcap/tests/package/test_shebangdepends.py +++ b/Namcap/tests/package/test_shebangdepends.py @@ -60,5 +60,43 @@ package() { ]) self.assertEqual(w, []) + valid_pkgbuild = """ +pkgname=__namcap_test_shebangdepends +pkgver=1.0 +pkgrel=1 +pkgdesc="A package" +arch=('any') +url="http://www.example.com/" +license=('GPL') +depends=('python') +source=() +options=(!purge !zipman) +build() { + cd "${srcdir}" + echo -e "#! /usr/bin/env python\nprint('a script')" > python_sample +} +package() { + install -Dm755 "$srcdir/python_sample" "$pkgdir/usr/bin/python_sample" +} +""" + def test_shebangdepends_noncanonical(self): + "shutil.which returns noncanonical path (e.g. in /usr/sbin)" + pkgfile = "__namcap_test_shebangdepends-1.0-1-any.pkg.tar" + with open(os.path.join(self.tmpdir, "PKGBUILD"), "w") as f: + f.write(self.valid_pkgbuild) + self.run_makepkg() + old_path = os.environ['PATH'] + try: + os.environ['PATH'] = '/usr/sbin:' + old_path + pkg, r = self.run_rule_on_tarball( + os.path.join(self.tmpdir, pkgfile), + Namcap.rules.shebangdepends.ShebangDependsRule + ) + finally: + os.environ['PATH'] = old_path + e, w, i = Namcap.depends.analyze_depends(pkg) + self.assertEqual(e, []) + self.assertEqual(w, []) + # vim: set ts=4 sw=4 noet: