All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] cache: Split Cache() into a NoCache() parent object
@ 2016-08-15 17:02 Richard Purdie
  2016-08-15 17:20 ` Christopher Larson
  0 siblings, 1 reply; 3+ messages in thread
From: Richard Purdie @ 2016-08-15 17:02 UTC (permalink / raw)
  To: bitbake-devel

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.

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>

diff --git a/bitbake/lib/bb/cache.py b/bitbake/lib/bb/cache.py
index 7118c83..8c1fe11 100644
--- a/bitbake/lib/bb/cache.py
+++ b/bitbake/lib/bb/cache.py
@@ -265,12 +265,68 @@ def realfn2virtual(realfn, cls):
         return realfn
     return "virtual:" + cls + ":" + realfn
 
-class Cache(object):
+class NoCache(object):
+
+    def __init__(self, databuilder):
+        self.databuilder = databuilder
+        self.data = databuilder.data
+
+    @classmethod
+    def loadDataFull(cls, virtualfn, appends, cfgData):
+        """
+        Return a complete set of data for fn.
+        To do this, we need to parse the file.
+        """
+
+        (fn, virtual) = virtualfn2realfn(virtualfn)
+
+        logger.debug(1, "Parsing %s (full)", fn)
+
+        cfgData.setVar("__ONLYFINALISE", virtual or "default")
+        bb_data = cls.load_bbfile(fn, appends, cfgData)
+        return bb_data[virtual]
+
+    @staticmethod
+    def load_bbfile(bbfile, appends, config):
+        """
+        Load and parse one .bb build file
+        Return the data and whether parsing resulted in the file being skipped
+        """
+        chdir_back = False
+
+        # expand tmpdir to include this topdir
+        config.setVar('TMPDIR', config.getVar('TMPDIR', True) or "")
+        bbfile_loc = os.path.abspath(os.path.dirname(bbfile))
+        oldpath = os.path.abspath(os.getcwd())
+        bb.parse.cached_mtime_noerror(bbfile_loc)
+        bb_data = config.createCopy()
+        # The ConfHandler first looks if there is a TOPDIR and if not
+        # then it would call getcwd().
+        # Previously, we chdir()ed to bbfile_loc, called the handler
+        # and finally chdir()ed back, a couple of thousand times. We now
+        # just fill in TOPDIR to point to bbfile_loc if there is no TOPDIR yet.
+        if not bb_data.getVar('TOPDIR', False):
+            chdir_back = True
+            bb_data.setVar('TOPDIR', bbfile_loc)
+        try:
+            if appends:
+                bb_data.setVar('__BBAPPEND', " ".join(appends))
+            bb_data = bb.parse.handle(bbfile, bb_data)
+            if chdir_back:
+                os.chdir(oldpath)
+            return bb_data
+        except:
+            if chdir_back:
+                os.chdir(oldpath)
+            raise
+
+class Cache(NoCache):
     """
     BitBake Cache implementation
     """
 
     def __init__(self, databuilder, data_hash, caches_array):
+        super().__init__(databuilder)
         data = databuilder.data
 
         # Pass caches_array information into Cache Constructor
@@ -376,21 +432,6 @@ class Cache(object):
                       self.data)
 
     @classmethod
-    def loadDataFull(cls, virtualfn, appends, cfgData):
-        """
-        Return a complete set of data for fn.
-        To do this, we need to parse the file.
-        """
-
-        (fn, virtual) = virtualfn2realfn(virtualfn)
-
-        logger.debug(1, "Parsing %s (full)", fn)
-
-        cfgData.setVar("__ONLYFINALISE", virtual or "default")
-        bb_data = cls.load_bbfile(fn, appends, cfgData)
-        return bb_data[virtual]
-
-    @classmethod
     def parse(cls, filename, appends, configdata, caches_array):
         """Parse the specified filename, returning the recipe information"""
         logger.debug(1, "Parsing %s", filename)
@@ -648,42 +689,6 @@ class Cache(object):
             info_array.append(cache_class(realfn, data))
         self.add_info(file_name, info_array, cacheData, parsed)
 
-    @staticmethod
-    def load_bbfile(bbfile, appends, config):
-        """
-        Load and parse one .bb build file
-        Return the data and whether parsing resulted in the file being skipped
-        """
-        chdir_back = False
-
-        from bb import parse
-
-        # expand tmpdir to include this topdir
-        config.setVar('TMPDIR', config.getVar('TMPDIR', True) or "")
-        bbfile_loc = os.path.abspath(os.path.dirname(bbfile))
-        oldpath = os.path.abspath(os.getcwd())
-        parse.cached_mtime_noerror(bbfile_loc)
-        bb_data = config.createCopy()
-        # The ConfHandler first looks if there is a TOPDIR and if not
-        # then it would call getcwd().
-        # Previously, we chdir()ed to bbfile_loc, called the handler
-        # and finally chdir()ed back, a couple of thousand times. We now
-        # just fill in TOPDIR to point to bbfile_loc if there is no TOPDIR yet.
-        if not bb_data.getVar('TOPDIR', False):
-            chdir_back = True
-            bb_data.setVar('TOPDIR', bbfile_loc)
-        try:
-            if appends:
-                bb_data.setVar('__BBAPPEND', " ".join(appends))
-            bb_data = parse.handle(bbfile, bb_data)
-            if chdir_back:
-                os.chdir(oldpath)
-            return bb_data
-        except:
-            if chdir_back:
-                os.chdir(oldpath)
-            raise
-
 
 def init(cooker):
     """




^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] cache: Split Cache() into a NoCache() parent object
  2016-08-15 17:02 [PATCH] cache: Split Cache() into a NoCache() parent object Richard Purdie
@ 2016-08-15 17:20 ` Christopher Larson
  2016-08-15 20:28   ` Richard Purdie
  0 siblings, 1 reply; 3+ messages in thread
From: Christopher Larson @ 2016-08-15 17:20 UTC (permalink / raw)
  To: Richard Purdie; +Cc: bitbake-devel

[-- Attachment #1: Type: text/plain, Size: 1211 bytes --]

On Mon, Aug 15, 2016 at 10:02 AM, Richard Purdie <
richard.purdie@linuxfoundation.org> wrote:

> 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.
>
> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
>
> diff --git a/bitbake/lib/bb/cache.py b/bitbake/lib/bb/cache.py
> index 7118c83..8c1fe11 100644
> --- a/bitbake/lib/bb/cache.py
> +++ b/bitbake/lib/bb/cache.py
> @@ -265,12 +265,68 @@ def realfn2virtual(realfn, cls):
>          return realfn
>      return "virtual:" + cls + ":" + realfn
>
> -class Cache(object):
> +class NoCache(object):
> +
> +    def __init__(self, databuilder):
> +        self.databuilder = databuilder
> +        self.data = databuilder.data
>

I like the idea, but do we really need to pass in databuilder and set data
if this class makes no use of it? It's all class methods, after all.
-- 
Christopher Larson
clarson at kergoth dot com
Founder - BitBake, OpenEmbedded, OpenZaurus
Maintainer - Tslib
Senior Software Engineer, Mentor Graphics

[-- Attachment #2: Type: text/html, Size: 1797 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] cache: Split Cache() into a NoCache() parent object
  2016-08-15 17:20 ` Christopher Larson
@ 2016-08-15 20:28   ` Richard Purdie
  0 siblings, 0 replies; 3+ messages in thread
From: Richard Purdie @ 2016-08-15 20:28 UTC (permalink / raw)
  To: Christopher Larson; +Cc: bitbake-devel

On Mon, 2016-08-15 at 10:20 -0700, Christopher Larson wrote:
> 
> On Mon, Aug 15, 2016 at 10:02 AM, Richard Purdie <
> richard.purdie@linuxfoundation.org> wrote:
> > 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.
> > 
> > Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
> > 
> > diff --git a/bitbake/lib/bb/cache.py b/bitbake/lib/bb/cache.py
> > index 7118c83..8c1fe11 100644
> > --- a/bitbake/lib/bb/cache.py
> > +++ b/bitbake/lib/bb/cache.py
> > @@ -265,12 +265,68 @@ def realfn2virtual(realfn, cls):
> >          return realfn
> >      return "virtual:" + cls + ":" + realfn
> > 
> > -class Cache(object):
> > +class NoCache(object):
> > +
> > +    def __init__(self, databuilder):
> > +        self.databuilder = databuilder
> > +        self.data = databuilder.data
> > 
> I like the idea, but do we really need to pass in databuilder and set
> data if this class makes no use of it? It's all class methods, after
> all.

If I remember correctly it is used by users of the class, e.g. in
bitbake-worker so this is setting things up for later changes.

data is set since we have a ton of code which knows about this
namespace and I didn't really want to go and patch it all right now.

Cheers,

Richard





^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-08-15 20:28 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-08-15 17:02 [PATCH] cache: Split Cache() into a NoCache() parent object Richard Purdie
2016-08-15 17:20 ` Christopher Larson
2016-08-15 20:28   ` Richard Purdie

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.