summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/bb/cache.py
diff options
context:
space:
mode:
authorRichard Purdie <richard.purdie@linuxfoundation.org>2016-08-15 18:02:41 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2016-08-18 10:06:26 +0100
commitb176189df1163d92aaec8b565bf69dcf76bab458 (patch)
treef9157a429d0c089aede1990408ee48ded5615d10 /bitbake/lib/bb/cache.py
parente79550ea8708f82aa720a47c5ed9a8aab1182458 (diff)
downloadpoky-b176189df1163d92aaec8b565bf69dcf76bab458.tar.gz
bitbake: cache: Split Cache() into a NoCache() parent object
There are some cases we want to parse recipes without any cache setup or involvement. Split out the standalone functions into a NoCache variant which the Cache is based upon, setting the scene for further cleanup and restructuring. (Bitbake rev: 120b64ea6a0c0ecae7af0fd15d989934fa4f1c36) Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/bb/cache.py')
-rw-r--r--bitbake/lib/bb/cache.py109
1 files changed, 57 insertions, 52 deletions
diff --git a/bitbake/lib/bb/cache.py b/bitbake/lib/bb/cache.py
index 7118c83f73..8c1fe11317 100644
--- a/bitbake/lib/bb/cache.py
+++ b/bitbake/lib/bb/cache.py
@@ -265,12 +265,68 @@ def realfn2virtual(realfn, cls):
265 return realfn 265 return realfn
266 return "virtual:" + cls + ":" + realfn 266 return "virtual:" + cls + ":" + realfn
267 267
268class Cache(object): 268class NoCache(object):
269
270 def __init__(self, databuilder):
271 self.databuilder = databuilder
272 self.data = databuilder.data
273
274 @classmethod
275 def loadDataFull(cls, virtualfn, appends, cfgData):
276 """
277 Return a complete set of data for fn.
278 To do this, we need to parse the file.
279 """
280
281 (fn, virtual) = virtualfn2realfn(virtualfn)
282
283 logger.debug(1, "Parsing %s (full)", fn)
284
285 cfgData.setVar("__ONLYFINALISE", virtual or "default")
286 bb_data = cls.load_bbfile(fn, appends, cfgData)
287 return bb_data[virtual]
288
289 @staticmethod
290 def load_bbfile(bbfile, appends, config):
291 """
292 Load and parse one .bb build file
293 Return the data and whether parsing resulted in the file being skipped
294 """
295 chdir_back = False
296
297 # expand tmpdir to include this topdir
298 config.setVar('TMPDIR', config.getVar('TMPDIR', True) or "")
299 bbfile_loc = os.path.abspath(os.path.dirname(bbfile))
300 oldpath = os.path.abspath(os.getcwd())
301 bb.parse.cached_mtime_noerror(bbfile_loc)
302 bb_data = config.createCopy()
303 # The ConfHandler first looks if there is a TOPDIR and if not
304 # then it would call getcwd().
305 # Previously, we chdir()ed to bbfile_loc, called the handler
306 # and finally chdir()ed back, a couple of thousand times. We now
307 # just fill in TOPDIR to point to bbfile_loc if there is no TOPDIR yet.
308 if not bb_data.getVar('TOPDIR', False):
309 chdir_back = True
310 bb_data.setVar('TOPDIR', bbfile_loc)
311 try:
312 if appends:
313 bb_data.setVar('__BBAPPEND', " ".join(appends))
314 bb_data = bb.parse.handle(bbfile, bb_data)
315 if chdir_back:
316 os.chdir(oldpath)
317 return bb_data
318 except:
319 if chdir_back:
320 os.chdir(oldpath)
321 raise
322
323class Cache(NoCache):
269 """ 324 """
270 BitBake Cache implementation 325 BitBake Cache implementation
271 """ 326 """
272 327
273 def __init__(self, databuilder, data_hash, caches_array): 328 def __init__(self, databuilder, data_hash, caches_array):
329 super().__init__(databuilder)
274 data = databuilder.data 330 data = databuilder.data
275 331
276 # Pass caches_array information into Cache Constructor 332 # Pass caches_array information into Cache Constructor
@@ -376,21 +432,6 @@ class Cache(object):
376 self.data) 432 self.data)
377 433
378 @classmethod 434 @classmethod
379 def loadDataFull(cls, virtualfn, appends, cfgData):
380 """
381 Return a complete set of data for fn.
382 To do this, we need to parse the file.
383 """
384
385 (fn, virtual) = virtualfn2realfn(virtualfn)
386
387 logger.debug(1, "Parsing %s (full)", fn)
388
389 cfgData.setVar("__ONLYFINALISE", virtual or "default")
390 bb_data = cls.load_bbfile(fn, appends, cfgData)
391 return bb_data[virtual]
392
393 @classmethod
394 def parse(cls, filename, appends, configdata, caches_array): 435 def parse(cls, filename, appends, configdata, caches_array):
395 """Parse the specified filename, returning the recipe information""" 436 """Parse the specified filename, returning the recipe information"""
396 logger.debug(1, "Parsing %s", filename) 437 logger.debug(1, "Parsing %s", filename)
@@ -648,42 +689,6 @@ class Cache(object):
648 info_array.append(cache_class(realfn, data)) 689 info_array.append(cache_class(realfn, data))
649 self.add_info(file_name, info_array, cacheData, parsed) 690 self.add_info(file_name, info_array, cacheData, parsed)
650 691
651 @staticmethod
652 def load_bbfile(bbfile, appends, config):
653 """
654 Load and parse one .bb build file
655 Return the data and whether parsing resulted in the file being skipped
656 """
657 chdir_back = False
658
659 from bb import parse
660
661 # expand tmpdir to include this topdir
662 config.setVar('TMPDIR', config.getVar('TMPDIR', True) or "")
663 bbfile_loc = os.path.abspath(os.path.dirname(bbfile))
664 oldpath = os.path.abspath(os.getcwd())
665 parse.cached_mtime_noerror(bbfile_loc)
666 bb_data = config.createCopy()
667 # The ConfHandler first looks if there is a TOPDIR and if not
668 # then it would call getcwd().
669 # Previously, we chdir()ed to bbfile_loc, called the handler
670 # and finally chdir()ed back, a couple of thousand times. We now
671 # just fill in TOPDIR to point to bbfile_loc if there is no TOPDIR yet.
672 if not bb_data.getVar('TOPDIR', False):
673 chdir_back = True
674 bb_data.setVar('TOPDIR', bbfile_loc)
675 try:
676 if appends:
677 bb_data.setVar('__BBAPPEND', " ".join(appends))
678 bb_data = parse.handle(bbfile, bb_data)
679 if chdir_back:
680 os.chdir(oldpath)
681 return bb_data
682 except:
683 if chdir_back:
684 os.chdir(oldpath)
685 raise
686
687 692
688def init(cooker): 693def init(cooker):
689 """ 694 """