1 # ex:ts=4:sw=4:sts=4:et
2 # -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
3 """class for handling .bb files (using a C++ parser)
5 Reads a .bb file and obtains its metadata (using a C++ parser)
7 Copyright (C) 2006 Tim Robert Ansell
8 Copyright (C) 2006 Holger Hans Peter Freyther
10 This program is free software; you can redistribute it and/or modify it under
11 the terms of the GNU General Public License as published by the Free Software
12 Foundation; either version 2 of the License, or (at your option) any later
15 Permission is hereby granted, free of charge, to any person obtaining a copy
16 of this software and associated documentation files (the "Software"), to deal
17 in the Software without restriction, including without limitation the rights
18 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
19 copies of the Software, and to permit persons to whom the Software is
20 furnished to do so, subject to the following conditions:
22 The above copyright notice and this permission notice shall be included in all
23 copies or substantial portions of the Software.
25 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
26 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
27 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
28 SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
29 DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
30 OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
31 THE USE OR OTHER DEALINGS IN THE SOFTWARE.
36 # The Module we will use here
39 from bitbakec import parsefile
42 # This is the Python Part of the Native Parser Implementation.
43 # We will only parse .bbclass, .inc and .bb files but no
44 # configuration files.
45 # supports, init and handle are the public methods used by
48 # The rest of the methods are internal implementation details.
52 Initialize the data implementation with values of
53 the environment and data from the file.
60 def supports(fn, data):
61 return fn[-3:] == ".bb" or fn[-8:] == ".bbclass" or fn[-4:] == ".inc" or fn[-5:] == ".conf"
64 if not bb.data.getVar('TOPDIR', data):
65 bb.data.setVar('TOPDIR', os.getcwd(), data)
66 if not bb.data.getVar('BBPATH', data):
67 bb.data.setVar('BBPATH', os.path.join(sys.prefix, 'share', 'bitbake'), data)
69 def handle_inherit(d):
71 Handle inheriting of classes. This will load all default classes.
72 It could be faster, it could detect infinite loops but this is todo
73 Also this delayed loading of bb.parse could impose a penalty
75 from bb.parse import handle
77 files = (data.getVar('INHERIT', d, True) or "").split()
81 __inherit_cache = data.getVar('__inherit_cache', d) or []
83 file = data.expand(f, d)
84 if file[0] != "/" and file[-8:] != ".bbclass":
85 file = os.path.join('classes', '%s.bbclass' % file)
87 if not file in __inherit_cache:
88 debug(2, "BB %s:%d: inheriting %s" % (fn, lineno, file))
89 __inherit_cache.append( file )
94 print "Failed to inherit %s" % file
95 data.setVar('__inherit_cache', __inherit_cache, d)
98 def handle(fn, d, include):
99 from bb import data, parse
101 (root, ext) = os.path.splitext(os.path.basename(fn))
102 base_name = "%s%s" % (root,ext)
104 # initialize with some data
107 # check if we include or are the beginning
110 oldfile = d.getVar('FILE', False)
114 data.inheritFromOS(d)
117 if not os.path.isabs(fn):
118 abs_fn = bb.which(d.getVar('BBPATH', True), fn)
122 # check if the file exists
123 if not os.path.exists(abs_fn):
124 raise IOError("file '%(fn)s' not found" % locals() )
126 # now we know the file is around mark it as dep
128 parse.mark_dependency(d, abs_fn)
130 # manipulate the bbpath
131 if ext != ".bbclass" and ext != ".conf":
132 old_bb_path = data.getVar('BBPATH', d)
133 data.setVar('BBPATH', os.path.dirname(abs_fn) + (":%s" %old_bb_path) , d)
135 # handle INHERITS and base inherit
136 if ext != ".bbclass" and ext != ".conf":
137 data.setVar('FILE', fn, d)
140 # now parse this file - by defering it to C++
141 parsefile(abs_fn, d, is_conf)
147 #### !!! XXX Finish it up by executing the anonfunc
150 # restore the original FILE
152 d.setVar('FILE', oldfile)
155 if ext != ".bbclass" and ext != ".conf":
156 data.setVar('BBPATH', old_bb_path, d )
162 # Needed for BitBake files...
163 __pkgsplit_cache__={}
164 def vars_from_file(mypkg, d):
166 return (None, None, None)
167 if mypkg in __pkgsplit_cache__:
168 return __pkgsplit_cache__[mypkg]
170 myfile = os.path.splitext(os.path.basename(mypkg))
171 parts = myfile[0].split('_')
172 __pkgsplit_cache__[mypkg] = parts
178 parts.extend(tmplist)
184 # Inform bitbake that we are a parser
185 # We need to define all three
186 from bb.parse import handlers
187 handlers.append( {'supports' : supports, 'handle': handle, 'init' : init})