[bitbake-devel,2/5] fetch2: Add get_mirrorname()

Submitted by Robert Yang on March 14, 2019, 9:28 a.m. | Patch ID: 159567

Details

Message ID b3ade2ccda56d3abbe44c5ede950093995f8b536.1552555629.git.liezhi.yang@windriver.com
State New
Headers show

Commit Message

Robert Yang March 14, 2019, 9:28 a.m.
It can be used by both __init__.py and git.py.

Signed-off-by: Robert Yang <liezhi.yang@windriver.com>
---
 bitbake/lib/bb/fetch2/__init__.py | 5 ++++-
 bitbake/lib/bb/fetch2/git.py      | 2 +-
 2 files changed, 5 insertions(+), 2 deletions(-)

Patch hide | download patch | download mbox

diff --git a/bitbake/lib/bb/fetch2/__init__.py b/bitbake/lib/bb/fetch2/__init__.py
index f112067..5062bb2 100644
--- a/bitbake/lib/bb/fetch2/__init__.py
+++ b/bitbake/lib/bb/fetch2/__init__.py
@@ -889,6 +889,9 @@  def runfetchcmd(cmd, d, quiet=False, cleanup=None, log=None, workdir=None):
 
     return output
 
+def get_mirrorname(ud):
+    return ud.host.replace(':','.') + ud.path.replace('/', '.').replace('*', '.')
+
 def check_network_access(d, info, url):
     """
     log remote network access, and error if BB_NO_NETWORK is set or the given
@@ -910,7 +913,7 @@  def build_mirroruris(origud, mirrors, ld):
     replacements["HOST"] = origud.host
     replacements["PATH"] = origud.path
     replacements["BASENAME"] = origud.path.split("/")[-1]
-    replacements["MIRRORNAME"] = origud.host.replace(':','.') + origud.path.replace('/', '.').replace('*', '.')
+    replacements["MIRRORNAME"] = get_mirrorname(origud)
 
     def adduri(ud, uris, uds, mirrors, tarballs):
         for line in mirrors:
diff --git a/bitbake/lib/bb/fetch2/git.py b/bitbake/lib/bb/fetch2/git.py
index cf8bee7..45d7303 100644
--- a/bitbake/lib/bb/fetch2/git.py
+++ b/bitbake/lib/bb/fetch2/git.py
@@ -248,7 +248,7 @@  class Git(FetchMethod):
                     ud.unresolvedrev[name] = ud.revisions[name]
                 ud.revisions[name] = self.latest_revision(ud, d, name)
 
-        gitsrcname = '%s%s' % (ud.host.replace(':', '.'), ud.path.replace('/', '.').replace('*', '.'))
+        gitsrcname = bb.fetch2.get_mirrorname(ud)
         if gitsrcname.startswith('.'):
             gitsrcname = gitsrcname[1:]
 

Comments

Richard Purdie March 21, 2019, 11:42 p.m.
On Thu, 2019-03-14 at 17:28 +0800, Robert Yang wrote:
> It can be used by both __init__.py and git.py.
> 
> Signed-off-by: Robert Yang <liezhi.yang@windriver.com>
> ---
>  bitbake/lib/bb/fetch2/__init__.py | 5 ++++-
>  bitbake/lib/bb/fetch2/git.py      | 2 +-
>  2 files changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/bitbake/lib/bb/fetch2/__init__.py b/bitbake/lib/bb/fetch2/__init__.py
> index f112067..5062bb2 100644
> --- a/bitbake/lib/bb/fetch2/__init__.py
> +++ b/bitbake/lib/bb/fetch2/__init__.py
> @@ -889,6 +889,9 @@ def runfetchcmd(cmd, d, quiet=False, cleanup=None, log=None, workdir=None):
>  
>      return output
>  
> +def get_mirrorname(ud):
> +    return ud.host.replace(':','.') + ud.path.replace('/', '.').replace('*', '.')
> +
>  def check_network_access(d, info, url):
>      """
>      log remote network access, and error if BB_NO_NETWORK is set or the given
> @@ -910,7 +913,7 @@ def build_mirroruris(origud, mirrors, ld):
>      replacements["HOST"] = origud.host
>      replacements["PATH"] = origud.path
>      replacements["BASENAME"] = origud.path.split("/")[-1]
> -    replacements["MIRRORNAME"] = origud.host.replace(':','.') + origud.path.replace('/', '.').replace('*', '.')
> +    replacements["MIRRORNAME"] = get_mirrorname(origud)
>  
>      def adduri(ud, uris, uds, mirrors, tarballs):
>          for line in mirrors:
> diff --git a/bitbake/lib/bb/fetch2/git.py b/bitbake/lib/bb/fetch2/git.py
> index cf8bee7..45d7303 100644
> --- a/bitbake/lib/bb/fetch2/git.py
> +++ b/bitbake/lib/bb/fetch2/git.py
> @@ -248,7 +248,7 @@ class Git(FetchMethod):
>                      ud.unresolvedrev[name] = ud.revisions[name]
>                  ud.revisions[name] = self.latest_revision(ud, d, name)
>  
> -        gitsrcname = '%s%s' % (ud.host.replace(':', '.'), ud.path.replace('/', '.').replace('*', '.'))
> +        gitsrcname = bb.fetch2.get_mirrorname(ud)
>          if gitsrcname.startswith('.'):
>              gitsrcname = gitsrcname[1:]
>  

I think your patch is highlighting a deeper problem here. The mirror
name is something which the given fetcher module should be decoding and
this shouldn't handled in __init__.py unless its some kind of default.

We probably need to look more deeply about why git fetcher knowledge is
being used in the general case and fix that instead...

Cheers,

Richard
Robert Yang March 22, 2019, 3:51 a.m.
On 3/22/19 7:42 AM, Richard Purdie wrote:
> On Thu, 2019-03-14 at 17:28 +0800, Robert Yang wrote:
>> It can be used by both __init__.py and git.py.
>>
>> Signed-off-by: Robert Yang <liezhi.yang@windriver.com>
>> ---
>>   bitbake/lib/bb/fetch2/__init__.py | 5 ++++-
>>   bitbake/lib/bb/fetch2/git.py      | 2 +-
>>   2 files changed, 5 insertions(+), 2 deletions(-)
>>
>> diff --git a/bitbake/lib/bb/fetch2/__init__.py b/bitbake/lib/bb/fetch2/__init__.py
>> index f112067..5062bb2 100644
>> --- a/bitbake/lib/bb/fetch2/__init__.py
>> +++ b/bitbake/lib/bb/fetch2/__init__.py
>> @@ -889,6 +889,9 @@ def runfetchcmd(cmd, d, quiet=False, cleanup=None, log=None, workdir=None):
>>   
>>       return output
>>   
>> +def get_mirrorname(ud):
>> +    return ud.host.replace(':','.') + ud.path.replace('/', '.').replace('*', '.')
>> +
>>   def check_network_access(d, info, url):
>>       """
>>       log remote network access, and error if BB_NO_NETWORK is set or the given
>> @@ -910,7 +913,7 @@ def build_mirroruris(origud, mirrors, ld):
>>       replacements["HOST"] = origud.host
>>       replacements["PATH"] = origud.path
>>       replacements["BASENAME"] = origud.path.split("/")[-1]
>> -    replacements["MIRRORNAME"] = origud.host.replace(':','.') + origud.path.replace('/', '.').replace('*', '.')
>> +    replacements["MIRRORNAME"] = get_mirrorname(origud)
>>   
>>       def adduri(ud, uris, uds, mirrors, tarballs):
>>           for line in mirrors:
>> diff --git a/bitbake/lib/bb/fetch2/git.py b/bitbake/lib/bb/fetch2/git.py
>> index cf8bee7..45d7303 100644
>> --- a/bitbake/lib/bb/fetch2/git.py
>> +++ b/bitbake/lib/bb/fetch2/git.py
>> @@ -248,7 +248,7 @@ class Git(FetchMethod):
>>                       ud.unresolvedrev[name] = ud.revisions[name]
>>                   ud.revisions[name] = self.latest_revision(ud, d, name)
>>   
>> -        gitsrcname = '%s%s' % (ud.host.replace(':', '.'), ud.path.replace('/', '.').replace('*', '.'))
>> +        gitsrcname = bb.fetch2.get_mirrorname(ud)
>>           if gitsrcname.startswith('.'):
>>               gitsrcname = gitsrcname[1:]
>>   
> 
> I think your patch is highlighting a deeper problem here. The mirror
> name is something which the given fetcher module should be decoding and
> this shouldn't handled in __init__.py unless its some kind of default.
> 
> We probably need to look more deeply about why git fetcher knowledge is
> being used in the general case and fix that instead...

Make sense, I will work on it.

// Robert

> 
> Cheers,
> 
> Richard
> 
>