summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/bb/parse/parse_c/BBHandler.py
diff options
context:
space:
mode:
Diffstat (limited to 'bitbake/lib/bb/parse/parse_c/BBHandler.py')
-rw-r--r--bitbake/lib/bb/parse/parse_c/BBHandler.py151
1 files changed, 113 insertions, 38 deletions
diff --git a/bitbake/lib/bb/parse/parse_c/BBHandler.py b/bitbake/lib/bb/parse/parse_c/BBHandler.py
index d9f48db17b..b430e1f4e5 100644
--- a/bitbake/lib/bb/parse/parse_c/BBHandler.py
+++ b/bitbake/lib/bb/parse/parse_c/BBHandler.py
@@ -5,33 +5,33 @@
5 Reads a .bb file and obtains its metadata (using a C++ parser) 5 Reads a .bb file and obtains its metadata (using a C++ parser)
6 6
7 Copyright (C) 2006 Tim Robert Ansell 7 Copyright (C) 2006 Tim Robert Ansell
8 Copyright (C) 2006 Holger Hans Peter Freyther 8 Copyright (C) 2006 Holger Hans Peter Freyther
9 9
10 This program is free software; you can redistribute it and/or modify it under 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 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 12 Foundation; either version 2 of the License, or (at your option) any later
13 version. 13 version.
14 14
15 Permission is hereby granted, free of charge, to any person obtaining a copy 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 16 of this software and associated documentation files (the "Software"), to deal
17 in the Software without restriction, including without limitation the rights 17 in the Software without restriction, including without limitation the rights
18 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 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 19 copies of the Software, and to permit persons to whom the Software is
20 furnished to do so, subject to the following conditions: 20 furnished to do so, subject to the following conditions:
21 21
22 The above copyright notice and this permission notice shall be included in all 22 The above copyright notice and this permission notice shall be included in all
23 copies or substantial portions of the Software. 23 copies or substantial portions of the Software.
24 24
25 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 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, 26 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
27 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT 27 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
28 SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 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 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 30 OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
31 THE USE OR OTHER DEALINGS IN THE SOFTWARE. 31 THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32""" 32"""
33 33
34import os 34import os, sys
35 35
36# The Module we will use here 36# The Module we will use here
37import bb 37import bb
@@ -61,51 +61,126 @@ def supports(fn, data):
61 return fn[-3:] == ".bb" or fn[-8:] == ".bbclass" or fn[-4:] == ".inc" or fn[-5:] == ".conf" 61 return fn[-3:] == ".bb" or fn[-8:] == ".bbclass" or fn[-4:] == ".inc" or fn[-5:] == ".conf"
62 62
63def init(fn, data): 63def init(fn, data):
64 if not data.getVar('TOPDIR'): 64 if not bb.data.getVar('TOPDIR', data):
65 bb.error('TOPDIR is not set') 65 bb.data.setVar('TOPDIR', os.getcwd(), data)
66 if not data.getVar('BBPATH'): 66 if not bb.data.getVar('BBPATH', data):
67 bb.error('BBPATH is not set') 67 bb.data.setVar('BBPATH', os.path.join(sys.prefix, 'share', 'bitbake'), data)
68
69def handle_inherit(d):
70 """
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
74 """
75 from bb.parse import handle
76
77 files = (data.getVar('INHERIT', d, True) or "").split()
78 if not "base" in i:
79 files[0:0] = ["base"]
80
81 __inherit_cache = data.getVar('__inherit_cache', d) or []
82 for f in files:
83 file = data.expand(f, d)
84 if file[0] != "/" and file[-8:] != ".bbclass":
85 file = os.path.join('classes', '%s.bbclass' % file)
86
87 if not file in __inherit_cache:
88 debug(2, "BB %s:%d: inheriting %s" % (fn, lineno, file))
89 __inherit_cache.append( file )
90
91 try:
92 handle(file, d, True)
93 except IOError:
94 print "Failed to inherit %s" % file
95 data.setVar('__inherit_cache', __inherit_cache, d)
68 96
69 97
70def handle(fn, d, include): 98def handle(fn, d, include):
71 print "" 99 from bb import data, parse
72 print "fn: %s" % fn 100
73 print "data: %s" % d 101 (root, ext) = os.path.splitext(os.path.basename(fn))
74 print dir(d) 102 base_name = "%s%s" % (root,ext)
75 print d.getVar.__doc__ 103
76 print "include: %s" % include 104 # initialize with some data
105 init(fn,d)
77 106
78 # check if we include or are the beginning 107 # check if we include or are the beginning
108 oldfile = None
79 if include: 109 if include:
80 oldfile = d.getVar('FILE') 110 oldfile = d.getVar('FILE', False)
81 else: 111 is_conf = False
82 #d.inheritFromOS() 112 elif ext == ".conf":
83 oldfile = None 113 is_conf = True
114 data.inheritFromOS(d)
84 115
85 # find the file 116 # find the file
86 if not os.path.isabs(fn): 117 if not os.path.isabs(fn):
87 bb.error("No Absolute FILE name") 118 abs_fn = bb.which(d.getVar('BBPATH', True), fn)
88 abs_fn = bb.which(d.getVar('BBPATH'), fn)
89 else: 119 else:
90 abs_fn = fn 120 abs_fn = fn
91 121
92 # check if the file exists 122 # check if the file exists
93 if not os.path.exists(abs_fn): 123 if not os.path.exists(abs_fn):
94 raise IOError("file '%(fn)' not found" % locals() ) 124 raise IOError("file '%(fn)s' not found" % locals() )
95 125
96 # now we know the file is around mark it as dep 126 # now we know the file is around mark it as dep
97 if include: 127 if include:
98 parse.mark_dependency(d, abs_fn) 128 parse.mark_dependency(d, abs_fn)
99 129
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)
134
135 # handle INHERITS and base inherit
136 if ext != ".bbclass" and ext != ".conf":
137 data.setVar('FILE', fn, d)
138 handle_interit(d)
139
100 # now parse this file - by defering it to C++ 140 # now parse this file - by defering it to C++
101 parsefile(fn, d) 141 parsefile(abs_fn, d, is_conf)
142
143 # Finish it up
144 if include == 0:
145 data.expandKeys(d)
146 data.update_data(d)
147 #### !!! XXX Finish it up by executing the anonfunc
148
102 149
103 # restore the original FILE 150 # restore the original FILE
104 if oldfile: 151 if oldfile:
105 d.setVar('FILE', oldfile) 152 d.setVar('FILE', oldfile)
106 153
154 # restore bbpath
155 if ext != ".bbclass" and ext != ".conf":
156 data.setVar('BBPATH', old_bb_path, d )
157
158
107 return d 159 return d
108 160
161
162# Needed for BitBake files...
163__pkgsplit_cache__={}
164def vars_from_file(mypkg, d):
165 if not mypkg:
166 return (None, None, None)
167 if mypkg in __pkgsplit_cache__:
168 return __pkgsplit_cache__[mypkg]
169
170 myfile = os.path.splitext(os.path.basename(mypkg))
171 parts = myfile[0].split('_')
172 __pkgsplit_cache__[mypkg] = parts
173 exp = 3 - len(parts)
174 tmplist = []
175 while exp != 0:
176 exp -= 1
177 tmplist.append(None)
178 parts.extend(tmplist)
179 return parts
180
181
182
183
109# Inform bitbake that we are a parser 184# Inform bitbake that we are a parser
110# We need to define all three 185# We need to define all three
111from bb.parse import handlers 186from bb.parse import handlers