[bitbake-devel,v2,3/4] cache: allow parsing a recipe with a custom config datastore

Submitted by Paul Eggleton on Aug. 30, 2016, 8:48 p.m. | Patch ID: 130673

Details

Message ID 634deb5b43cf3470c41e1ee86cef05c7fd31df9d.1472589757.git.paul.eggleton@linux.intel.com
State New
Headers show

Commit Message

Paul Eggleton Aug. 30, 2016, 8:48 p.m.
To accommodate the OpenEmbedded layer index recipe parsing, we have to
have the ability to pass in a custom config datastore since it
constructs a synthetic one. To make this possible after the multi-config
changes, rename the internal _load_bbfile() function to parse_recipe(),
make it a function at the module level (since it doesn't actually need
to access any members of the class or instance) and move setting
__BBMULTICONFIG inside it since other code will expect that to be set.

Part of the fix for [YOCTO #10192].

Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
---
 lib/bb/cache.py | 73 ++++++++++++++++++++++++++++++---------------------------
 1 file changed, 39 insertions(+), 34 deletions(-)

Patch hide | download patch | download mbox

diff --git a/lib/bb/cache.py b/lib/bb/cache.py
index 0d5a034..ccad5c8 100644
--- a/lib/bb/cache.py
+++ b/lib/bb/cache.py
@@ -286,6 +286,42 @@  def variant2virtual(realfn, variant):
         return "multiconfig:" + elems[1] + ":" + realfn
     return "virtual:" + variant + ":" + realfn
 
+def parse_recipe(bb_data, bbfile, appends, mc=''):
+    """
+    Parse a recipe
+    """
+
+    chdir_back = False
+
+    bb_data.setVar("__BBMULTICONFIG", mc)
+
+    # expand tmpdir to include this topdir
+    bb_data.setVar('TMPDIR', bb_data.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)
+
+    # 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 NoCache(object):
 
@@ -312,54 +348,23 @@  class NoCache(object):
         if virtonly:
             (bbfile, virtual, mc) = virtualfn2realfn(bbfile)
             bb_data = self.databuilder.mcdata[mc].createCopy()
-            bb_data.setVar("__BBMULTICONFIG", mc) 
             bb_data.setVar("__ONLYFINALISE", virtual or "default")
-            datastores = self._load_bbfile(bb_data, bbfile, appends)
+            datastores = parse_recipe(bb_data, bbfile, appends, mc)
             return datastores
 
         bb_data = self.data.createCopy()
-        datastores = self._load_bbfile(bb_data, bbfile, appends)
+        datastores = parse_recipe(bb_data, bbfile, appends, mc)
 
         for mc in self.databuilder.mcdata:
             if not mc:
                 continue
             bb_data = self.databuilder.mcdata[mc].createCopy()
-            bb_data.setVar("__BBMULTICONFIG", mc) 
-            newstores = self._load_bbfile(bb_data, bbfile, appends)
+            newstores = parse_recipe(bb_data, bbfile, appends, mc)
             for ns in newstores:
                 datastores["multiconfig:%s:%s" % (mc, ns)] = newstores[ns]
 
         return datastores
 
-    def _load_bbfile(self, bb_data, bbfile, appends):
-        chdir_back = False
-
-        # expand tmpdir to include this topdir
-        bb_data.setVar('TMPDIR', bb_data.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)
-
-        # 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

Comments

Paul Eggleton Aug. 30, 2016, 9:11 p.m.
On Wed, 31 Aug 2016 08:48:08 Paul Eggleton wrote:
> To accommodate the OpenEmbedded layer index recipe parsing, we have to
> have the ability to pass in a custom config datastore since it
> constructs a synthetic one. To make this possible after the multi-config
> changes, rename the internal _load_bbfile() function to parse_recipe(),
> make it a function at the module level (since it doesn't actually need
> to access any members of the class or instance) and move setting
> __BBMULTICONFIG inside it since other code will expect that to be set.
> 
> Part of the fix for [YOCTO #10192].
> 
> Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
> ---
>  lib/bb/cache.py | 73
> ++++++++++++++++++++++++++++++--------------------------- 1 file changed,
> 39 insertions(+), 34 deletions(-)
> 
> diff --git a/lib/bb/cache.py b/lib/bb/cache.py
> index 0d5a034..ccad5c8 100644
> --- a/lib/bb/cache.py
> +++ b/lib/bb/cache.py
> @@ -286,6 +286,42 @@ def variant2virtual(realfn, variant):
>          return "multiconfig:" + elems[1] + ":" + realfn
>      return "virtual:" + variant + ":" + realfn
> 
> +def parse_recipe(bb_data, bbfile, appends, mc=''):
> +    """
> +    Parse a recipe
> +    """
> +
> +    chdir_back = False
> +
> +    bb_data.setVar("__BBMULTICONFIG", mc)
> +
> +    # expand tmpdir to include this topdir
> +    bb_data.setVar('TMPDIR', bb_data.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)
> +
> +    # 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 NoCache(object):
> 
> @@ -312,54 +348,23 @@ class NoCache(object):
>          if virtonly:
>              (bbfile, virtual, mc) = virtualfn2realfn(bbfile)
>              bb_data = self.databuilder.mcdata[mc].createCopy()
> -            bb_data.setVar("__BBMULTICONFIG", mc)
>              bb_data.setVar("__ONLYFINALISE", virtual or "default")
> -            datastores = self._load_bbfile(bb_data, bbfile, appends)
> +            datastores = parse_recipe(bb_data, bbfile, appends, mc)
>              return datastores
> 
>          bb_data = self.data.createCopy()
> -        datastores = self._load_bbfile(bb_data, bbfile, appends)
> +        datastores = parse_recipe(bb_data, bbfile, appends, mc)

So the last line above was definitely wrong - I've dropped the "mc" parameter 
in this call and pushed a new paule/tinfoil-fixes-bb branch.

Cheers,
Paul