[namcap,v3] makedepends: Make VCS matching more robust

Message ID 20181202141453.14684-1-michael.straube@posteo.de
State New
Headers show
Series
  • [namcap,v3] makedepends: Make VCS matching more robust
Related show

Commit Message

Eli Schwartz via arch-projects Dec. 2, 2018, 2:14 p.m. UTC
If a VCS source is renamed using the "::" syntax the makedepends are not
detected. If there are files starting with <name of VCS binary> in the source
array false positives are produced. See the gitlab package for example. Make
the matching more robust to avoid such issues.

Signed-off-by: Michael Straube <michael.straube@posteo.de>
---
v1 -> v2
Make it also work for e.g. git://

v2 -> v3
Return early if no vcs sources.

 Namcap/rules/makedepends.py               | 15 ++++++++++++---
 Namcap/tests/pkgbuild/test_makedepends.py | 15 +++++++++++----
 2 files changed, 23 insertions(+), 7 deletions(-)

Patch

diff --git a/Namcap/rules/makedepends.py b/Namcap/rules/makedepends.py
index 2a0ceaa..53676c2 100644
--- a/Namcap/rules/makedepends.py
+++ b/Namcap/rules/makedepends.py
@@ -54,10 +54,19 @@  class VCSMakedepends(PkgbuildRule):
 			'svn' : 'subversion',
 		}
 		missing = []
+		protocols = set()
 
-		for v in vcs:
-			if not any(s.startswith(v) for s in pkginfo["source"]):
-				continue
+		for s in pkginfo["source"]:
+			p = s.split("::", 1)[-1]
+			p = p.split("://", 1)[0]
+			p = p.split("+", 1)[0]
+			if p in vcs:
+				protocols.add(p)
+
+		if not protocols:
+			return
+
+		for v in protocols:
 			d = vcs[v]
 			if 'makedepends' not in pkginfo:
 				missing.append(d)
diff --git a/Namcap/tests/pkgbuild/test_makedepends.py b/Namcap/tests/pkgbuild/test_makedepends.py
index 78c476a..d443b2b 100644
--- a/Namcap/tests/pkgbuild/test_makedepends.py
+++ b/Namcap/tests/pkgbuild/test_makedepends.py
@@ -76,10 +76,10 @@  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)
+source=(name::bzr+https://example.com/pub/mypackage
+        name::git://example.com/pub/mypackage
+        hg+https://example.com/pub/mypackage
+        svn://example.com/pub/mypackage)
 md5sums=('abcdefabcdef12345678901234567890')
 
 build() {
@@ -104,4 +104,11 @@  package() {
 			set(("missing-vcs-makedeps %s", i) for i in makedeps))
 		self.assertEqual(r.infos, [])
 
+	def test_example2(self):
+		# Example 2
+		r = self.run_on_pkg(self.pkgbuild1 + 'source=(gitsomething)')
+		self.assertEqual(r.errors, [])
+		self.assertEqual(r.warnings, [])
+		self.assertEqual(r.infos, [])
+
 # vim: set ts=4 sw=4 noet: