mirror of
https://git.yoctoproject.org/poky
synced 2026-05-31 00:39:46 +00:00
bitbake/fetch2: Simplify localpath variable handling FetchData init
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
@@ -198,7 +198,7 @@ def fetcher_compare_revisions(d):
|
|||||||
# 3. localpaths
|
# 3. localpaths
|
||||||
# localpath can be called at any time
|
# localpath can be called at any time
|
||||||
|
|
||||||
def init(urls, d, setup = True):
|
def init(urls, d):
|
||||||
urldata = {}
|
urldata = {}
|
||||||
|
|
||||||
fn = bb.data.getVar('FILE', d, 1)
|
fn = bb.data.getVar('FILE', d, 1)
|
||||||
@@ -209,11 +209,6 @@ def init(urls, d, setup = True):
|
|||||||
if url not in urldata:
|
if url not in urldata:
|
||||||
urldata[url] = FetchData(url, d)
|
urldata[url] = FetchData(url, d)
|
||||||
|
|
||||||
if setup:
|
|
||||||
for url in urldata:
|
|
||||||
if not urldata[url].setup:
|
|
||||||
urldata[url].setup_localpath(d)
|
|
||||||
|
|
||||||
urldata_cache[fn] = urldata
|
urldata_cache[fn] = urldata
|
||||||
return urldata
|
return urldata
|
||||||
|
|
||||||
@@ -279,7 +274,10 @@ def download(d, urls = None):
|
|||||||
"""
|
"""
|
||||||
if not urls:
|
if not urls:
|
||||||
urls = d.getVar("SRC_URI", 1).split()
|
urls = d.getVar("SRC_URI", 1).split()
|
||||||
urldata = init(urls, d, True)
|
urldata = init(urls, d)
|
||||||
|
|
||||||
|
for u in urls:
|
||||||
|
urldata[u].setup_localpath(d)
|
||||||
|
|
||||||
for u in urls:
|
for u in urls:
|
||||||
ud = urldata[u]
|
ud = urldata[u]
|
||||||
@@ -341,13 +339,14 @@ def checkstatus(d, urls = None):
|
|||||||
Check all urls exist upstream
|
Check all urls exist upstream
|
||||||
init must have previously been called
|
init must have previously been called
|
||||||
"""
|
"""
|
||||||
urldata = init([], d, True)
|
urldata = init([], d)
|
||||||
|
|
||||||
if not urls:
|
if not urls:
|
||||||
urls = urldata
|
urls = urldata
|
||||||
|
|
||||||
for u in urls:
|
for u in urls:
|
||||||
ud = urldata[u]
|
ud = urldata[u]
|
||||||
|
ud.setup_localpath(d)
|
||||||
m = ud.method
|
m = ud.method
|
||||||
logger.debug(1, "Testing URL %s", u)
|
logger.debug(1, "Testing URL %s", u)
|
||||||
# First try checking uri, u, from PREMIRRORS
|
# First try checking uri, u, from PREMIRRORS
|
||||||
@@ -370,10 +369,11 @@ def localpaths(d):
|
|||||||
Return a list of the local filenames, assuming successful fetch
|
Return a list of the local filenames, assuming successful fetch
|
||||||
"""
|
"""
|
||||||
local = []
|
local = []
|
||||||
urldata = init([], d, True)
|
urldata = init([], d)
|
||||||
|
|
||||||
for u in urldata:
|
for u in urldata:
|
||||||
ud = urldata[u]
|
ud = urldata[u]
|
||||||
|
ud.setup_localpath(d)
|
||||||
local.append(ud.localpath)
|
local.append(ud.localpath)
|
||||||
|
|
||||||
return local
|
return local
|
||||||
@@ -394,14 +394,9 @@ def get_srcrev(d):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
scms = []
|
scms = []
|
||||||
|
urldata = init(bb.data.getVar('SRC_URI', d, 1).split(), d)
|
||||||
# Only call setup_localpath on URIs which supports_srcrev()
|
|
||||||
urldata = init(bb.data.getVar('SRC_URI', d, 1).split(), d, False)
|
|
||||||
for u in urldata:
|
for u in urldata:
|
||||||
ud = urldata[u]
|
if urldata[u].method.supports_srcrev():
|
||||||
if ud.method.supports_srcrev():
|
|
||||||
if not ud.setup:
|
|
||||||
ud.setup_localpath(d)
|
|
||||||
scms.append(u)
|
scms.append(u)
|
||||||
|
|
||||||
if len(scms) == 0:
|
if len(scms) == 0:
|
||||||
@@ -434,6 +429,7 @@ def localpath(url, d, cache = True):
|
|||||||
"""
|
"""
|
||||||
ud = init([url], d)
|
ud = init([url], d)
|
||||||
if ud[url].method:
|
if ud[url].method:
|
||||||
|
ud[url].setup_localpath(d)
|
||||||
return ud[url].localpath
|
return ud[url].localpath
|
||||||
return url
|
return url
|
||||||
|
|
||||||
@@ -546,6 +542,8 @@ class FetchData(object):
|
|||||||
"""
|
"""
|
||||||
def __init__(self, url, d):
|
def __init__(self, url, d):
|
||||||
self.localfile = ""
|
self.localfile = ""
|
||||||
|
self.localpath = None
|
||||||
|
self.lockfile = None
|
||||||
(self.type, self.host, self.path, self.user, self.pswd, self.parm) = decodeurl(data.expand(url, d))
|
(self.type, self.host, self.path, self.user, self.pswd, self.parm) = decodeurl(data.expand(url, d))
|
||||||
self.date = Fetch.getSRCDate(self, d)
|
self.date = Fetch.getSRCDate(self, d)
|
||||||
self.url = url
|
self.url = url
|
||||||
@@ -565,15 +563,34 @@ class FetchData(object):
|
|||||||
self.sha256_expected = bb.data.getVarFlag("SRC_URI", self.sha256_name, d)
|
self.sha256_expected = bb.data.getVarFlag("SRC_URI", self.sha256_name, d)
|
||||||
|
|
||||||
self.names = self.parm.get("name",'default').split(',')
|
self.names = self.parm.get("name",'default').split(',')
|
||||||
|
|
||||||
|
self.method = None
|
||||||
for m in methods:
|
for m in methods:
|
||||||
if m.supports(url, self, d):
|
if m.supports(url, self, d):
|
||||||
self.method = m
|
self.method = m
|
||||||
if hasattr(m,"urldata_init"):
|
break
|
||||||
m.urldata_init(self, d)
|
|
||||||
if m.supports_srcrev():
|
if not self.method:
|
||||||
self.setup_srcrevs(d)
|
raise NoMethodError("Missing implementation for url %s" % url)
|
||||||
return
|
|
||||||
raise NoMethodError("Missing implementation for url %s" % url)
|
if self.method.supports_srcrev():
|
||||||
|
self.setup_srcrevs(d)
|
||||||
|
|
||||||
|
if hasattr(self.method, "urldata_init"):
|
||||||
|
self.method.urldata_init(self, d)
|
||||||
|
|
||||||
|
if "localpath" in self.parm:
|
||||||
|
# if user sets localpath for file, use it instead.
|
||||||
|
self.localpath = self.parm["localpath"]
|
||||||
|
self.basename = os.path.basename(self.localpath)
|
||||||
|
elif self.localfile:
|
||||||
|
self.localpath = self.method.localpath(self.url, self, d)
|
||||||
|
|
||||||
|
if self.localfile and self.localpath:
|
||||||
|
# Note: These files should always be in DL_DIR whereas localpath may not be.
|
||||||
|
basepath = bb.data.expand("${DL_DIR}/%s" % os.path.basename(self.localpath), d)
|
||||||
|
self.md5 = basepath + '.md5'
|
||||||
|
self.lockfile = basepath + '.lock'
|
||||||
|
|
||||||
def setup_srcrevs(self, d):
|
def setup_srcrevs(self, d):
|
||||||
if not self.method.supports_srcrev():
|
if not self.method.supports_srcrev():
|
||||||
@@ -588,20 +605,9 @@ class FetchData(object):
|
|||||||
self.revision = self.revisions[self.names[0]]
|
self.revision = self.revisions[self.names[0]]
|
||||||
|
|
||||||
def setup_localpath(self, d):
|
def setup_localpath(self, d):
|
||||||
self.setup = True
|
if not self.localpath:
|
||||||
if "localpath" in self.parm:
|
|
||||||
# if user sets localpath for file, use it instead.
|
|
||||||
self.localpath = self.parm["localpath"]
|
|
||||||
self.basename = os.path.basename(self.localpath)
|
|
||||||
else:
|
|
||||||
self.localpath = self.method.localpath(self.url, self, d)
|
self.localpath = self.method.localpath(self.url, self, d)
|
||||||
|
|
||||||
if self.localpath is not None:
|
|
||||||
# Note: These files should always be in DL_DIR whereas localpath may not be.
|
|
||||||
basepath = bb.data.expand("${DL_DIR}/%s" % os.path.basename(self.localpath), d)
|
|
||||||
self.md5 = basepath + '.md5'
|
|
||||||
self.lockfile = basepath + '.lock'
|
|
||||||
|
|
||||||
|
|
||||||
class Fetch(object):
|
class Fetch(object):
|
||||||
"""Base class for 'fetch'ing data"""
|
"""Base class for 'fetch'ing data"""
|
||||||
|
|||||||
Reference in New Issue
Block a user