]> code.ossystems Code Review - openembedded-core.git/commitdiff
bitbake: [parse] Unify opening a file...
authorHolger Freyther <ich@tamarin.(none)>
Sun, 17 May 2009 04:19:39 +0000 (06:19 +0200)
committerRichard Purdie <rpurdie@linux.intel.com>
Wed, 10 Feb 2010 16:31:33 +0000 (16:31 +0000)
Signed-off-by: Richard Purdie <rpurdie@linux.intel.com>
bitbake/lib/bb/parse/__init__.py
bitbake/lib/bb/parse/parse_py/BBHandler.py
bitbake/lib/bb/parse/parse_py/ConfHandler.py

index 5dd96c41367f1f1ffc1b172988be3d605a098f59..c6a925c7a804ecfd43f2785433d7bbf2598c8e03 100644 (file)
@@ -80,5 +80,24 @@ def init(fn, data):
         if h['supports'](fn):
             return h['init'](data)
 
+def resolve_file(fn, d):
+    if not os.path.isabs(fn):
+        f = None
+        bbpath = (bb.data.getVar('BBPATH', d, 1) or '').split(':')
+        for p in bbpath:
+            j = os.path.join(p, fn)
+            if os.access(j, os.R_OK):
+                abs_fn = j
+                f = open(j, 'r')
+                break
+        if f is None:
+            raise IOError("file %s not found" % fn)
+    else:
+        f = open(fn,'r')
+        abs_fn = fn
+
+    bb.msg.debug(2, bb.msg.domain.Parsing, "LOAD %s" % abs_fn)
+    return (f, abs_fn)
+
 
 from parse_py import __version__, ConfHandler, BBHandler
index 7707705aaf306e5079149ff230eb72083d9e40e2..c6931650dadb4be3e3251aefb36c6be471683639 100644 (file)
@@ -30,7 +30,7 @@ import bb.fetch, bb.build, bb.utils
 from bb import data, fetch, methodpool
 
 from ConfHandler import include, init
-from bb.parse import ParseError
+from bb.parse import ParseError, resolve_file
 
 __func_start_regexp__    = re.compile( r"(((?P<py>python)|(?P<fr>fakeroot))\s*)*(?P<func>[\w\.\-\+\{\}\$]+)?\s*\(\s*\)\s*{$" )
 __inherit_regexp__       = re.compile( r"inherit\s+(.+)" )
@@ -145,20 +145,7 @@ def handle(fn, d, include = 0):
     else:
         oldfile = None
 
-    bbpath = (data.getVar('BBPATH', d, 1) or '').split(':')
-    if not os.path.isabs(fn):
-        f = None
-        for p in bbpath:
-            j = os.path.join(p, fn)
-            if os.access(j, os.R_OK):
-                abs_fn = j
-                f = open(j, 'r')
-                break
-        if f is None:
-            raise IOError("file %s not found" % fn)
-    else:
-        f = open(fn,'r')
-        abs_fn = fn
+    (f, abs_fn) = resolve_file(fn, d)
 
     if include:
         bb.parse.mark_dependency(d, abs_fn)
@@ -203,7 +190,6 @@ def handle(fn, d, include = 0):
                 darray[cls] = based
             return darray
    
-        bbpath.pop(0)
     if oldfile:
         bb.data.setVar("FILE", oldfile, d)
 
index fcbf6aea155ed917d5c222f66dfead198ea6efc5..ce746106a484d0e0a1d49a89f73a9fcbe5d78d42 100644 (file)
@@ -25,7 +25,7 @@
 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 
 import re, bb.data, os, sys
-from bb.parse import ParseError
+from bb.parse import ParseError, resolve_file
 
 #__config_regexp__  = re.compile( r"(?P<exp>export\s*)?(?P<var>[a-zA-Z0-9\-_+.${}]+)\s*(?P<colon>:)?(?P<ques>\?)?=\s*(?P<apo>['\"]?)(?P<value>.*)(?P=apo)$")
 __config_regexp__  = re.compile( r"(?P<exp>export\s*)?(?P<var>[a-zA-Z0-9\-_+.${}/]+)(\[(?P<flag>[a-zA-Z0-9\-_+.]+)\])?\s*((?P<colon>:=)|(?P<ques>\?=)|(?P<append>\+=)|(?P<prepend>=\+)|(?P<predot>=\.)|(?P<postdot>\.=)|=)\s*(?P<apo>['\"]?)(?P<value>.*)(?P=apo)$")
@@ -77,10 +77,6 @@ def include(oldfn, fn, data, error_out):
         bb.msg.debug(2, bb.msg.domain.Parsing, "CONF file '%s' not found" % fn)
 
 def handle(fn, data, include = 0):
-    if include:
-        inc_string = "including"
-    else:
-        inc_string = "reading"
     init(data)
 
     if include == 0:
@@ -88,22 +84,7 @@ def handle(fn, data, include = 0):
     else:
         oldfile = bb.data.getVar('FILE', data)
 
-    if not os.path.isabs(fn):
-        f = None
-        bbpath = bb.data.getVar("BBPATH", data, 1) or []
-        for p in bbpath.split(":"):
-            currname = os.path.join(p, fn)
-            if os.access(currname, os.R_OK):
-                f = open(currname, 'r')
-                abs_fn = currname
-                bb.msg.debug(2, bb.msg.domain.Parsing, "CONF %s %s" % (inc_string, currname))
-                break
-        if f is None:
-            raise IOError("file '%s' not found" % fn)
-    else:
-        f = open(fn,'r')
-        bb.msg.debug(1, bb.msg.domain.Parsing, "CONF %s %s" % (inc_string,fn))
-        abs_fn = fn
+    (f, abs_fn) = resolve_file(fn, data)
 
     if include:
         bb.parse.mark_dependency(data, abs_fn)