diff mbox series

fetch2/wget.py: correctly match versioned directories

Message ID 20221208122131.2455528-1-alex@linutronix.de
State Accepted, archived
Commit b6601be22c6d776327acdcd1fa931400f41ac786
Headers show
Series fetch2/wget.py: correctly match versioned directories | expand

Commit Message

Alexander Kanavin Dec. 8, 2022, 12:21 p.m. UTC
When obtaining latest upstream versions, the code needs
to check if the existing tarball is in a versioned directory
(e.g. component-name/x.y/component-name-x.y.z.tar.gz) and
if it is, it needs to first obtain the list of all
such versioned directories and then check all of them by going
one step up in the directory hierarchy.

Existing code was returning a correct match when the component
name did not have numbers, e.g. a check on 'source/epiphany/43/'
would return 43, but was stopping too soon when the component
name itself had numbers ('source/libxml2/2.10/' would return libxml2).

This change ensures the last match is taken instead of the first.

Signed-off-by: Alexander Kanavin <alex@linutronix.de>
---
 bitbake/lib/bb/fetch2/wget.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Richard Purdie Dec. 8, 2022, 2:59 p.m. UTC | #1
On Thu, 2022-12-08 at 13:21 +0100, Alexander Kanavin wrote:
> When obtaining latest upstream versions, the code needs
> to check if the existing tarball is in a versioned directory
> (e.g. component-name/x.y/component-name-x.y.z.tar.gz) and
> if it is, it needs to first obtain the list of all
> such versioned directories and then check all of them by going
> one step up in the directory hierarchy.
> 
> Existing code was returning a correct match when the component
> name did not have numbers, e.g. a check on 'source/epiphany/43/'
> would return 43, but was stopping too soon when the component
> name itself had numbers ('source/libxml2/2.10/' would return libxml2).
> 
> This change ensures the last match is taken instead of the first.
> 
> Signed-off-by: Alexander Kanavin <alex@linutronix.de>
> ---
>  bitbake/lib/bb/fetch2/wget.py | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/bitbake/lib/bb/fetch2/wget.py b/bitbake/lib/bb/fetch2/wget.py
> index 821afa5b58..7ccea3ad89 100644
> --- a/bitbake/lib/bb/fetch2/wget.py
> +++ b/bitbake/lib/bb/fetch2/wget.py
> @@ -644,10 +644,10 @@ class Wget(FetchMethod):
>              # search for version matches on folders inside the path, like:
>              # "5.7" in http://download.gnome.org/sources/${PN}/5.7/${PN}-${PV}.tar.gz
>              dirver_regex = re.compile(r"(?P<dirver>[^/]*(\d+\.)*\d+([-_]r\d+)*)/")
> -            m = dirver_regex.search(path)
> +            m = dirver_regex.findall(path)
>              if m:
>                  pn = d.getVar('PN')
> -                dirver = m.group('dirver')
> +                dirver = m[-1][0]
>  
>                  dirver_pn_regex = re.compile(r"%s\d?" % (re.escape(pn)))
>                  if not dirver_pn_regex.search(dirver):


There are tests and examples in lib/bb/tests/fetch.py, could we add
something for this case?

Cheers,

Richard
Alexander Kanavin Dec. 8, 2022, 4:04 p.m. UTC | #2
On Thu, 8 Dec 2022 at 15:59, Richard Purdie
<richard.purdie@linuxfoundation.org> wrote:

> There are tests and examples in lib/bb/tests/fetch.py, could we add
> something for this case?

Added. I completely forgot they exist :)

Alex
diff mbox series

Patch

diff --git a/bitbake/lib/bb/fetch2/wget.py b/bitbake/lib/bb/fetch2/wget.py
index 821afa5b58..7ccea3ad89 100644
--- a/bitbake/lib/bb/fetch2/wget.py
+++ b/bitbake/lib/bb/fetch2/wget.py
@@ -644,10 +644,10 @@  class Wget(FetchMethod):
             # search for version matches on folders inside the path, like:
             # "5.7" in http://download.gnome.org/sources/${PN}/5.7/${PN}-${PV}.tar.gz
             dirver_regex = re.compile(r"(?P<dirver>[^/]*(\d+\.)*\d+([-_]r\d+)*)/")
-            m = dirver_regex.search(path)
+            m = dirver_regex.findall(path)
             if m:
                 pn = d.getVar('PN')
-                dirver = m.group('dirver')
+                dirver = m[-1][0]
 
                 dirver_pn_regex = re.compile(r"%s\d?" % (re.escape(pn)))
                 if not dirver_pn_regex.search(dirver):