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

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

Commit Message

Eli Schwartz via arch-projects Dec. 2, 2018, 1:01 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://

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

Comments

Eli Schwartz via arch-projects Dec. 2, 2018, 1:14 p.m. UTC | #1
On 12/2/18 8:01 AM, Michael Straube via arch-projects wrote:
> 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://
> 
>  Namcap/rules/makedepends.py               | 10 +++++++++-
>  Namcap/tests/pkgbuild/test_makedepends.py | 15 +++++++++++----
>  2 files changed, 20 insertions(+), 5 deletions(-)
> 
> diff --git a/Namcap/rules/makedepends.py b/Namcap/rules/makedepends.py
> index 2a0ceaa..65747c4 100644
> --- a/Namcap/rules/makedepends.py
> +++ b/Namcap/rules/makedepends.py
> @@ -54,9 +54,17 @@ class VCSMakedepends(PkgbuildRule):
>  			'svn' : 'subversion',
>  		}
>  		missing = []
> +		protocols = set()
> +
> +		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)
>  
>  		for v in vcs:
> -			if not any(s.startswith(v) for s in pkginfo["source"]):
> +			if not v in protocols:

Why not just check if protocols is empty?
Eli Schwartz via arch-projects Dec. 2, 2018, 2:12 p.m. UTC | #2
Am 02.12.18 um 14:14 schrieb Eli Schwartz via arch-projects:
> On 12/2/18 8:01 AM, Michael Straube via arch-projects wrote:
>> 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://
>>
>>   Namcap/rules/makedepends.py               | 10 +++++++++-
>>   Namcap/tests/pkgbuild/test_makedepends.py | 15 +++++++++++----
>>   2 files changed, 20 insertions(+), 5 deletions(-)
>>
>> diff --git a/Namcap/rules/makedepends.py b/Namcap/rules/makedepends.py
>> index 2a0ceaa..65747c4 100644
>> --- a/Namcap/rules/makedepends.py
>> +++ b/Namcap/rules/makedepends.py
>> @@ -54,9 +54,17 @@ class VCSMakedepends(PkgbuildRule):
>>   			'svn' : 'subversion',
>>   		}
>>   		missing = []
>> +		protocols = set()
>> +
>> +		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)
>>   
>>   		for v in vcs:
>> -			if not any(s.startswith(v) for s in pkginfo["source"]):
>> +			if not v in protocols:
> 
> Why not just check if protocols is empty?
> 
> 

Good point, thanks again.

Patch

diff --git a/Namcap/rules/makedepends.py b/Namcap/rules/makedepends.py
index 2a0ceaa..65747c4 100644
--- a/Namcap/rules/makedepends.py
+++ b/Namcap/rules/makedepends.py
@@ -54,9 +54,17 @@  class VCSMakedepends(PkgbuildRule):
 			'svn' : 'subversion',
 		}
 		missing = []
+		protocols = set()
+
+		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)
 
 		for v in vcs:
-			if not any(s.startswith(v) for s in pkginfo["source"]):
+			if not v in protocols:
 				continue
 			d = vcs[v]
 			if 'makedepends' not in pkginfo:
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: