[namcap,v2,3/3] Warn about missing VCS make dependencies (FS#58303)

Message ID 20181125145241.10889-3-michael.straube@posteo.de
State New
Headers show
Series
  • [namcap,v2,1/3] Warn about makedepends already in depends
Related show

Commit Message

Eli Schwartz via arch-projects Nov. 25, 2018, 2:52 p.m. UTC
Signed-off-by: Michael Straube <michael.straube@posteo.de>
---
 Namcap/rules/makedepends.py               | 32 ++++++++++++++++-
 Namcap/tests/pkgbuild/test_makedepends.py | 44 ++++++++++++++++++++++-
 namcap-tags                               |  1 +
 3 files changed, 75 insertions(+), 2 deletions(-)

Patch

diff --git a/Namcap/rules/makedepends.py b/Namcap/rules/makedepends.py
index 48b1049..1a32690 100644
--- a/Namcap/rules/makedepends.py
+++ b/Namcap/rules/makedepends.py
@@ -17,6 +17,7 @@ 
 #   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 #
 
+import re
 from Namcap.ruleclass import *
 
 class RedundantMakedepends(PkgbuildRule):
@@ -24,7 +25,7 @@  class RedundantMakedepends(PkgbuildRule):
 	This rule checks for make dependencies that are already
 	included as dependencies.
 	"""
-	name = "makedepends"
+	name = "redundant_makedepends"
 	description = "Check for redundant make dependencies"
 
 	def analyze(self, pkginfo, pkgbuild):
@@ -38,4 +39,33 @@  class RedundantMakedepends(PkgbuildRule):
 		for i in redundant_makedeps:
 			self.warnings.append(("redundant-makedep %s", i))
 
+class VCSMakedepends(PkgbuildRule):
+	"""
+	This rule checks for missing VCS make dependencies.
+	"""
+	name = "vcs_makedepends"
+	description = "Verify make dependencies for VCS sources"
+
+	def analyze(self, pkginfo, pkgbuild):
+		vcs = {
+			'bzr' : 'bzr',
+			'git' : 'git',
+			'hg' : 'mercurial',
+			'svn' : 'subversion'
+		}
+		missing = []
+
+		for i in pkginfo["source"]:
+			for j in vcs:
+				if re.match('^' + j + '+.*$', i):
+					d = vcs.get(j)
+					if 'makedepends' in pkginfo:
+						if d not in pkginfo["makedepends"]:
+							missing.append(d)
+					else:
+						missing.append(d)
+
+		for i in missing:
+			self.warnings.append(("missing-vcs-makedeps %s", i))
+
 # vim: set ts=4 sw=4 noet:
diff --git a/Namcap/tests/pkgbuild/test_makedepends.py b/Namcap/tests/pkgbuild/test_makedepends.py
index c8d6e97..15f5360 100644
--- a/Namcap/tests/pkgbuild/test_makedepends.py
+++ b/Namcap/tests/pkgbuild/test_makedepends.py
@@ -48,7 +48,6 @@  package() {
   true
 }
 """
-
 	test_valid = PkgbuildTest.valid_tests
 
 	def preSetUp(self):
@@ -62,4 +61,47 @@  package() {
 			set(("redundant-makedep %s", i) for i in ["lib1" ,"lib2"]))
 		self.assertEqual(r.infos, [])
 
+class NamcapVCSMakedependsTest(PkgbuildTest):
+	pkgbuild1 = """
+# Maintainer: Arch Linux <archlinux@example.com>
+# Contributor: Arch Linux <archlinux@example.com>
+
+pkgname=mypackage
+pkgver=1.0
+pkgrel=1
+pkgdesc="A package"
+url="http://www.example.com/"
+arch=('i686' 'x86_64')
+depends=()
+makedepends=()
+license=('GPL')
+options=('!libtool')
+source=(bzr+https://ftp.example.com/pub/mypackage
+        git+https://ftp.example.com/pub/mypackage
+        hg+https://ftp.example.com/pub/mypackage
+        svn+https://ftp.example.com/pub/mypackage)
+md5sums=('abcdefabcdef12345678901234567890')
+
+build() {
+  true
+}
+
+package() {
+  true
+}
+"""
+	test_valid = PkgbuildTest.valid_tests
+
+	def preSetUp(self):
+		self.rule = module.VCSMakedepends
+
+	def test_example1(self):
+		# Example 1
+		makedeps = ['bzr', 'git', 'mercurial', 'subversion']
+		r = self.run_on_pkg(self.pkgbuild1)
+		self.assertEqual(r.errors, [])
+		self.assertEqual(set(r.warnings),
+			set(("missing-vcs-makedeps %s", i) for i in makedeps))
+		self.assertEqual(r.infos, [])
+
 # vim: set ts=4 sw=4 noet:
diff --git a/namcap-tags b/namcap-tags
index c253042..eade98e 100644
--- a/namcap-tags
+++ b/namcap-tags
@@ -58,6 +58,7 @@  missing-checksums :: Missing checksums
 missing-url :: Missing url
 missing-pkgfunction %s :: Child package %s does not have a valid package() function
 missing-makedeps %s :: Split PKGBUILD needs additional makedepends %s to work properly
+missing-vcs-makedeps %s :: VCS source PKGBUILD needs additional makedepends '%s' to work properly
 no-elffiles-not-any-package :: No ELF files and not an "any" package
 non-fhs-info-page %s :: Non-FHS info page (%s) found. Use /usr/share/info instead
 non-fhs-man-page %s :: Non-FHS man page (%s) found. Use /usr/share/man instead