diff options
author | Richard Purdie <richard@openedhand.com> | 2005-08-31 10:47:56 +0000 |
---|---|---|
committer | Richard Purdie <richard@openedhand.com> | 2005-08-31 10:47:56 +0000 |
commit | f54da734eb7b69e8e34de505bd89a13479e230e0 (patch) | |
tree | f796bea6f5683dfe3d591ca5390d12fd78e59c96 /bitbake/lib/bb/parse | |
parent | 4b46c1f6e891b1ddd5968536440b888661fade3e (diff) | |
download | poky-f54da734eb7b69e8e34de505bd89a13479e230e0.tar.gz |
Initial population
git-svn-id: https://svn.o-hand.com/repos/poky@2 311d38ba-8fff-0310-9ca6-ca027cbcb966
Diffstat (limited to 'bitbake/lib/bb/parse')
-rw-r--r-- | bitbake/lib/bb/parse/BBHandler.pyc | bin | 0 -> 10831 bytes | |||
-rw-r--r-- | bitbake/lib/bb/parse/ConfHandler.pyc | bin | 0 -> 6391 bytes | |||
-rw-r--r-- | bitbake/lib/bb/parse/__init__.py | 70 | ||||
-rw-r--r-- | bitbake/lib/bb/parse/__init__.pyc | bin | 0 -> 3254 bytes | |||
-rw-r--r-- | bitbake/lib/bb/parse/parse_c/bitbakeparser.l | 288 | ||||
-rw-r--r-- | bitbake/lib/bb/parse/parse_c/bitbakeparser.py | 133 | ||||
-rw-r--r-- | bitbake/lib/bb/parse/parse_c/bitbakeparser.y | 161 | ||||
-rw-r--r-- | bitbake/lib/bb/parse/parse_c/lexer.h | 41 | ||||
-rw-r--r-- | bitbake/lib/bb/parse/parse_c/token.h | 83 | ||||
-rw-r--r-- | bitbake/lib/bb/parse/parse_py/BBHandler.py | 378 | ||||
-rw-r--r-- | bitbake/lib/bb/parse/parse_py/BBHandler.pyc | bin | 0 -> 10825 bytes | |||
-rw-r--r-- | bitbake/lib/bb/parse/parse_py/ConfHandler.py | 199 | ||||
-rw-r--r-- | bitbake/lib/bb/parse/parse_py/ConfHandler.pyc | bin | 0 -> 6673 bytes | |||
-rw-r--r-- | bitbake/lib/bb/parse/parse_py/__init__.py | 32 | ||||
-rw-r--r-- | bitbake/lib/bb/parse/parse_py/__init__.pyc | bin | 0 -> 1185 bytes |
15 files changed, 1385 insertions, 0 deletions
diff --git a/bitbake/lib/bb/parse/BBHandler.pyc b/bitbake/lib/bb/parse/BBHandler.pyc new file mode 100644 index 0000000000..047a6853a3 --- /dev/null +++ b/bitbake/lib/bb/parse/BBHandler.pyc | |||
Binary files differ | |||
diff --git a/bitbake/lib/bb/parse/ConfHandler.pyc b/bitbake/lib/bb/parse/ConfHandler.pyc new file mode 100644 index 0000000000..620af52942 --- /dev/null +++ b/bitbake/lib/bb/parse/ConfHandler.pyc | |||
Binary files differ | |||
diff --git a/bitbake/lib/bb/parse/__init__.py b/bitbake/lib/bb/parse/__init__.py new file mode 100644 index 0000000000..b8839c09fd --- /dev/null +++ b/bitbake/lib/bb/parse/__init__.py | |||
@@ -0,0 +1,70 @@ | |||
1 | """ | ||
2 | BitBake Parsers | ||
3 | |||
4 | File parsers for the BitBake build tools. | ||
5 | |||
6 | Copyright (C) 2003, 2004 Chris Larson | ||
7 | Copyright (C) 2003, 2004 Phil Blundell | ||
8 | |||
9 | This program is free software; you can redistribute it and/or modify it under | ||
10 | the terms of the GNU General Public License as published by the Free Software | ||
11 | Foundation; either version 2 of the License, or (at your option) any later | ||
12 | version. | ||
13 | |||
14 | This program is distributed in the hope that it will be useful, but WITHOUT | ||
15 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
16 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. | ||
17 | |||
18 | You should have received a copy of the GNU General Public License along with | ||
19 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple | ||
20 | Place, Suite 330, Boston, MA 02111-1307 USA. | ||
21 | |||
22 | Based on functions from the base bb module, Copyright 2003 Holger Schurig | ||
23 | """ | ||
24 | |||
25 | __all__ = [ 'ParseError', 'SkipPackage', 'cached_mtime', 'mark_dependency', | ||
26 | 'supports', 'handle', 'init' ] | ||
27 | handlers = [] | ||
28 | |||
29 | class ParseError(Exception): | ||
30 | """Exception raised when parsing fails""" | ||
31 | |||
32 | class SkipPackage(Exception): | ||
33 | """Exception raised to skip this package""" | ||
34 | |||
35 | __mtime_cache = {} | ||
36 | def cached_mtime(f): | ||
37 | import os | ||
38 | if not __mtime_cache.has_key(f): | ||
39 | __mtime_cache[f] = os.stat(f)[8] | ||
40 | return __mtime_cache[f] | ||
41 | |||
42 | def mark_dependency(d, f): | ||
43 | import bb, os | ||
44 | if f.startswith('./'): | ||
45 | f = "%s/%s" % (os.getcwd(), f[2:]) | ||
46 | deps = (bb.data.getVar('__depends', d) or "").split() | ||
47 | deps.append("%s@%s" % (f, cached_mtime(f))) | ||
48 | bb.data.setVar('__depends', " ".join(deps), d) | ||
49 | |||
50 | def supports(fn, data): | ||
51 | """Returns true if we have a handler for this file, false otherwise""" | ||
52 | for h in handlers: | ||
53 | if h['supports'](fn, data): | ||
54 | return 1 | ||
55 | return 0 | ||
56 | |||
57 | def handle(fn, data, include = 0): | ||
58 | """Call the handler that is appropriate for this file""" | ||
59 | for h in handlers: | ||
60 | if h['supports'](fn, data): | ||
61 | return h['handle'](fn, data, include) | ||
62 | raise ParseError("%s is not a BitBake file" % fn) | ||
63 | |||
64 | def init(fn, data): | ||
65 | for h in handlers: | ||
66 | if h['supports'](fn): | ||
67 | return h['init'](data) | ||
68 | |||
69 | |||
70 | from parse_py import __version__, ConfHandler, BBHandler | ||
diff --git a/bitbake/lib/bb/parse/__init__.pyc b/bitbake/lib/bb/parse/__init__.pyc new file mode 100644 index 0000000000..a2c2d6ae54 --- /dev/null +++ b/bitbake/lib/bb/parse/__init__.pyc | |||
Binary files differ | |||
diff --git a/bitbake/lib/bb/parse/parse_c/bitbakeparser.l b/bitbake/lib/bb/parse/parse_c/bitbakeparser.l new file mode 100644 index 0000000000..ee4ce14839 --- /dev/null +++ b/bitbake/lib/bb/parse/parse_c/bitbakeparser.l | |||
@@ -0,0 +1,288 @@ | |||
1 | /* bbf.flex | ||
2 | |||
3 | written by Marc Singer | ||
4 | 6 January 2005 | ||
5 | |||
6 | This program is free software; you can redistribute it and/or | ||
7 | modify it under the terms of the GNU General Public License as | ||
8 | published by the Free Software Foundation; either version 2 of the | ||
9 | License, or (at your option) any later version. | ||
10 | |||
11 | This program is distributed in the hope that it will be useful, but | ||
12 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
14 | General Public License for more details. | ||
15 | |||
16 | You should have received a copy of the GNU General Public License | ||
17 | along with this program; if not, write to the Free Software | ||
18 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 | ||
19 | USA. | ||
20 | |||
21 | DESCRIPTION | ||
22 | ----------- | ||
23 | |||
24 | flex lexer specification for a BitBake input file parser. | ||
25 | |||
26 | Unfortunately, flex doesn't welcome comments within the rule sets. | ||
27 | I say unfortunately because this lexer is unreasonably complex and | ||
28 | comments would make the code much easier to comprehend. | ||
29 | |||
30 | The BitBake grammar is not regular. In order to interpret all | ||
31 | of the available input files, the lexer maintains much state as it | ||
32 | parses. There are places where this lexer will emit tokens that | ||
33 | are invalid. The parser will tend to catch these. | ||
34 | |||
35 | The lexer requires C++ at the moment. The only reason for this has | ||
36 | to do with a very small amount of managed state. Producing a C | ||
37 | lexer should be a reasonably easy task as long as the %reentrant | ||
38 | option is used. | ||
39 | |||
40 | |||
41 | NOTES | ||
42 | ----- | ||
43 | |||
44 | o RVALUES. There are three kinds of RVALUES. There are unquoted | ||
45 | values, double quote enclosed strings, and single quote | ||
46 | strings. Quoted strings may contain unescaped quotes (of either | ||
47 | type), *and* any type may span more than one line by using a | ||
48 | continuation '\' at the end of the line. This requires us to | ||
49 | recognize all types of values with a single expression. | ||
50 | Moreover, the only reason to quote a value is to include | ||
51 | trailing or leading whitespace. Whitespace within a value is | ||
52 | preserved, ugh. | ||
53 | |||
54 | o CLASSES. C_ patterns define classes. Classes ought not include | ||
55 | a repitition operator, instead letting the reference to the class | ||
56 | define the repitition count. | ||
57 | |||
58 | C_SS - symbol start | ||
59 | C_SB - symbol body | ||
60 | C_SP - whitespace | ||
61 | |||
62 | */ | ||
63 | |||
64 | %option never-interactive | ||
65 | %option yylineno | ||
66 | %option noyywrap | ||
67 | %option reentrant stack | ||
68 | |||
69 | |||
70 | %{ | ||
71 | |||
72 | #include "token.h" | ||
73 | #include "lexer.h" | ||
74 | #include <ctype.h> | ||
75 | |||
76 | extern void *bbparseAlloc(void *(*mallocProc)(size_t)); | ||
77 | extern void bbparseFree(void *p, void (*freeProc)(void*)); | ||
78 | extern void *bbparseAlloc(void *(*mallocProc)(size_t)); | ||
79 | extern void *bbparse(void*, int, token_t, lex_t*); | ||
80 | extern void bbparseTrace(FILE *TraceFILE, char *zTracePrompt); | ||
81 | |||
82 | //static const char* rgbInput; | ||
83 | //static size_t cbInput; | ||
84 | |||
85 | |||
86 | int lineError; | ||
87 | int errorParse; | ||
88 | |||
89 | enum { | ||
90 | errorNone = 0, | ||
91 | errorUnexpectedInput, | ||
92 | errorUnsupportedFeature, | ||
93 | }; | ||
94 | |||
95 | #define YY_EXTRA_TYPE lex_t* | ||
96 | |||
97 | /* Read from buffer */ | ||
98 | #define YY_INPUT(buf,result,max_size) \ | ||
99 | { yyextra->input(buf, &result, max_size); } | ||
100 | |||
101 | //#define YY_DECL static size_t yylex () | ||
102 | |||
103 | #define ERROR(e) \ | ||
104 | do { lineError = yylineno; errorParse = e; yyterminate (); } while (0) | ||
105 | |||
106 | static const char* fixup_escapes (const char* sz); | ||
107 | |||
108 | %} | ||
109 | |||
110 | |||
111 | C_SP [ \t] | ||
112 | COMMENT #.*\n | ||
113 | OP_ASSIGN "=" | ||
114 | OP_IMMEDIATE ":=" | ||
115 | OP_PREPEND "=+" | ||
116 | OP_APPEND "+=" | ||
117 | OP_COND "?=" | ||
118 | B_OPEN "{" | ||
119 | B_CLOSE "}" | ||
120 | |||
121 | K_ADDTASK "addtask" | ||
122 | K_ADDHANDLER "addhandler" | ||
123 | K_AFTER "after" | ||
124 | K_BEFORE "before" | ||
125 | K_DEF "def" | ||
126 | K_INCLUDE "include" | ||
127 | K_INHERIT "inherit" | ||
128 | K_PYTHON "python" | ||
129 | K_FAKEROOT "fakeroot" | ||
130 | K_EXPORT "export" | ||
131 | K_EXPORT_FUNC "EXPORT_FUNCTIONS" | ||
132 | |||
133 | STRING \"([^\n\r]|"\\\n")*\" | ||
134 | SSTRING \'([^\n\r]|"\\\n")*\' | ||
135 | VALUE ([^'" \t\n])|([^'" \t\n]([^\n]|(\\\n))*[^'" \t\n]) | ||
136 | |||
137 | C_SS [a-zA-Z_] | ||
138 | C_SB [a-zA-Z0-9_+-.] | ||
139 | REF $\{{C_SS}{C_SB}*\} | ||
140 | SYMBOL {C_SS}{C_SB}* | ||
141 | VARIABLE $?{C_SS}({C_SB}*|{REF})*(\[[a-zA-Z0-9_]*\])? | ||
142 | FILENAME ([a-zA-Z_./]|{REF})(([-+a-zA-Z0-9_./]*)|{REF})* | ||
143 | |||
144 | PROC \({C_SP}*\) | ||
145 | |||
146 | %s S_DEF | ||
147 | %s S_DEF_ARGS | ||
148 | %s S_DEF_BODY | ||
149 | %s S_FUNC | ||
150 | %s S_INCLUDE | ||
151 | %s S_INHERIT | ||
152 | %s S_PROC | ||
153 | %s S_RVALUE | ||
154 | %s S_TASK | ||
155 | |||
156 | %% | ||
157 | |||
158 | {OP_APPEND} { BEGIN S_RVALUE; | ||
159 | yyextra->accept (T_OP_APPEND); } | ||
160 | {OP_PREPEND} { BEGIN S_RVALUE; | ||
161 | yyextra->accept (T_OP_PREPEND); } | ||
162 | {OP_IMMEDIATE} { BEGIN S_RVALUE; | ||
163 | yyextra->accept (T_OP_IMMEDIATE); } | ||
164 | {OP_ASSIGN} { BEGIN S_RVALUE; | ||
165 | yyextra->accept (T_OP_ASSIGN); } | ||
166 | {OP_COND} { BEGIN S_RVALUE; | ||
167 | yyextra->accept (T_OP_COND); } | ||
168 | |||
169 | <S_RVALUE>\\\n{C_SP}* { } | ||
170 | <S_RVALUE>{STRING} { BEGIN INITIAL; | ||
171 | size_t cb = yyleng; | ||
172 | while (cb && isspace (yytext[cb - 1])) | ||
173 | --cb; | ||
174 | yytext[cb - 1] = 0; | ||
175 | yyextra->accept (T_STRING, yytext + 1); } | ||
176 | <S_RVALUE>{SSTRING} { BEGIN INITIAL; | ||
177 | size_t cb = yyleng; | ||
178 | while (cb && isspace (yytext[cb - 1])) | ||
179 | --cb; | ||
180 | yytext[cb - 1] = 0; | ||
181 | yyextra->accept (T_STRING, yytext + 1); } | ||
182 | |||
183 | <S_RVALUE>{VALUE} { ERROR (errorUnexpectedInput); } | ||
184 | <S_RVALUE>{C_SP}*\n+ { BEGIN INITIAL; | ||
185 | yyextra->accept (T_STRING, NULL); } | ||
186 | |||
187 | {K_INCLUDE} { BEGIN S_INCLUDE; | ||
188 | yyextra->accept (T_INCLUDE); } | ||
189 | {K_INHERIT} { BEGIN S_INHERIT; | ||
190 | yyextra->accept (T_INHERIT); } | ||
191 | {K_ADDTASK} { BEGIN S_TASK; | ||
192 | yyextra->accept (T_ADDTASK); } | ||
193 | {K_ADDHANDLER} { yyextra->accept (T_ADDHANDLER); } | ||
194 | {K_EXPORT_FUNC} { BEGIN S_FUNC; | ||
195 | yyextra->accept (T_EXPORT_FUNC); } | ||
196 | <S_TASK>{K_BEFORE} { yyextra->accept (T_BEFORE); } | ||
197 | <S_TASK>{K_AFTER} { yyextra->accept (T_AFTER); } | ||
198 | <INITIAL>{K_EXPORT} { yyextra->accept (T_EXPORT); } | ||
199 | |||
200 | <INITIAL>{K_FAKEROOT} { yyextra->accept (T_FAKEROOT); } | ||
201 | <INITIAL>{K_PYTHON} { yyextra->accept (T_PYTHON); } | ||
202 | {PROC}{C_SP}*{B_OPEN}{C_SP}*\n* { BEGIN S_PROC; | ||
203 | yyextra->accept (T_PROC_OPEN); } | ||
204 | <S_PROC>{B_CLOSE}{C_SP}*\n* { BEGIN INITIAL; | ||
205 | yyextra->accept (T_PROC_CLOSE); } | ||
206 | <S_PROC>([^}][^\n]*)?\n* { yyextra->accept (T_PROC_BODY, yytext); } | ||
207 | |||
208 | {K_DEF} { BEGIN S_DEF; } | ||
209 | <S_DEF>{SYMBOL} { BEGIN S_DEF_ARGS; | ||
210 | yyextra->accept (T_SYMBOL, yytext); } | ||
211 | <S_DEF_ARGS>[^\n:]*: { yyextra->accept (T_DEF_ARGS, yytext); } | ||
212 | <S_DEF_ARGS>{C_SP}*\n { BEGIN S_DEF_BODY; } | ||
213 | <S_DEF_BODY>{C_SP}+[^\n]*\n { yyextra->accept (T_DEF_BODY, yytext); } | ||
214 | <S_DEF_BODY>\n { yyextra->accept (T_DEF_BODY, yytext); } | ||
215 | <S_DEF_BODY>. { BEGIN INITIAL; unput (yytext[0]); } | ||
216 | |||
217 | {COMMENT} { } | ||
218 | |||
219 | <INITIAL>{SYMBOL} { yyextra->accept (T_SYMBOL, yytext); } | ||
220 | <INITIAL>{VARIABLE} { yyextra->accept (T_VARIABLE, yytext); } | ||
221 | |||
222 | <S_TASK>{SYMBOL} { yyextra->accept (T_TSYMBOL, yytext); } | ||
223 | <S_FUNC>{SYMBOL} { yyextra->accept (T_FSYMBOL, yytext); } | ||
224 | <S_INHERIT>{SYMBOL} { yyextra->accept (T_ISYMBOL, yytext); } | ||
225 | <S_INCLUDE>{FILENAME} { BEGIN INITIAL; | ||
226 | yyextra->accept (T_ISYMBOL, yytext); } | ||
227 | |||
228 | <S_TASK>\n { BEGIN INITIAL; } | ||
229 | <S_FUNC>\n { BEGIN INITIAL; } | ||
230 | <S_INHERIT>\n { BEGIN INITIAL; } | ||
231 | |||
232 | [ \t\r\n] /* Insignificant whitespace */ | ||
233 | |||
234 | . { ERROR (errorUnexpectedInput); } | ||
235 | |||
236 | /* Check for premature termination */ | ||
237 | <<EOF>> { return T_EOF; } | ||
238 | |||
239 | %% | ||
240 | |||
241 | void lex_t::accept (int token, const char* sz) | ||
242 | { | ||
243 | token_t t; | ||
244 | memset (&t, 0, sizeof (t)); | ||
245 | t.copyString(sz); | ||
246 | |||
247 | /* tell lemon to parse the token */ | ||
248 | parse (parser, token, t, this); | ||
249 | } | ||
250 | |||
251 | int lex_t::line ()const | ||
252 | { | ||
253 | return yyget_lineno (scanner); | ||
254 | } | ||
255 | |||
256 | const char* lex_t::filename ()const | ||
257 | { | ||
258 | return m_fileName; | ||
259 | } | ||
260 | |||
261 | void parse (MappedFile* mf) | ||
262 | { | ||
263 | void* parser = bbparseAlloc (malloc); | ||
264 | yyscan_t scanner; | ||
265 | lex_t lex; | ||
266 | |||
267 | yylex_init (&scanner); | ||
268 | |||
269 | lex.parser = parser; | ||
270 | lex.scanner = scanner; | ||
271 | lex.mf = mf; | ||
272 | lex.rgbInput = mf->m_rgb; | ||
273 | lex.cbInput = mf->m_cb; | ||
274 | lex.parse = bbparse; | ||
275 | yyset_extra (&lex, scanner); | ||
276 | |||
277 | |||
278 | int result = yylex (scanner); | ||
279 | |||
280 | lex.accept (0); | ||
281 | bbparseTrace (NULL, NULL); | ||
282 | |||
283 | if (result != T_EOF) | ||
284 | WARNING ("premature end of file\n"); | ||
285 | |||
286 | yylex_destroy (scanner); | ||
287 | bbparseFree (parser, free); | ||
288 | } | ||
diff --git a/bitbake/lib/bb/parse/parse_c/bitbakeparser.py b/bitbake/lib/bb/parse/parse_c/bitbakeparser.py new file mode 100644 index 0000000000..ed7b13eef9 --- /dev/null +++ b/bitbake/lib/bb/parse/parse_c/bitbakeparser.py | |||
@@ -0,0 +1,133 @@ | |||
1 | """ | ||
2 | |||
3 | BitBake C Parser Python Code | ||
4 | |||
5 | Copyright (C) 2005 Holger Hans Peter Freyther | ||
6 | |||
7 | Permission is hereby granted, free of charge, to any person obtaining a copy | ||
8 | of this software and associated documentation files (the "Software"), to deal | ||
9 | in the Software without restriction, including without limitation the rights | ||
10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
11 | copies of the Software, and to permit persons to whom the Software is | ||
12 | furnished to do so, subject to the following conditions: | ||
13 | |||
14 | The above copyright notice and this permission notice shall be included in all | ||
15 | copies or substantial portions of the Software. | ||
16 | |||
17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT | ||
20 | SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, | ||
21 | DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR | ||
22 | OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR | ||
23 | THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
24 | """ | ||
25 | |||
26 | __version__ = "0xdeadbeef" | ||
27 | |||
28 | class CParser: | ||
29 | """ | ||
30 | The C-based Parser for Bitbake | ||
31 | """ | ||
32 | def __init__(self, data, type): | ||
33 | """ | ||
34 | Constructor | ||
35 | """ | ||
36 | self._data = data | ||
37 | |||
38 | def _syntax_error(self, file, line): | ||
39 | """ | ||
40 | lemon/flex reports an syntax error to us and we will | ||
41 | raise an exception | ||
42 | """ | ||
43 | pass | ||
44 | |||
45 | def _export(self, data): | ||
46 | """ | ||
47 | EXPORT VAR = "MOO" | ||
48 | we will now export VAR | ||
49 | """ | ||
50 | pass | ||
51 | |||
52 | def _assign(self, key, value): | ||
53 | """ | ||
54 | VAR = "MOO" | ||
55 | we will assign moo to VAR | ||
56 | """ | ||
57 | pass | ||
58 | |||
59 | def _assign(self, key, value): | ||
60 | """ | ||
61 | """ | ||
62 | pass | ||
63 | |||
64 | def _append(self, key, value): | ||
65 | """ | ||
66 | VAR += "MOO" | ||
67 | we will append " MOO" to var | ||
68 | """ | ||
69 | pass | ||
70 | |||
71 | def _prepend(self, key, value): | ||
72 | """ | ||
73 | VAR =+ "MOO" | ||
74 | we will prepend "MOO " to var | ||
75 | """ | ||
76 | pass | ||
77 | |||
78 | def _immediate(self, key, value): | ||
79 | """ | ||
80 | VAR := "MOO ${CVSDATE}" | ||
81 | we will assign immediately and expand vars | ||
82 | """ | ||
83 | pass | ||
84 | |||
85 | def _conditional(self, key, value): | ||
86 | """ | ||
87 | """ | ||
88 | pass | ||
89 | |||
90 | def _add_task(self, task, before = None, after = None): | ||
91 | """ | ||
92 | """ | ||
93 | pass | ||
94 | |||
95 | def _include(self, file): | ||
96 | """ | ||
97 | """ | ||
98 | pass | ||
99 | |||
100 | def _inherit(self, file): | ||
101 | """ | ||
102 | """ | ||
103 | pass | ||
104 | |||
105 | def _shell_procedure(self, name, body): | ||
106 | """ | ||
107 | """ | ||
108 | pass | ||
109 | |||
110 | def _python_procedure(self, name, body): | ||
111 | """ | ||
112 | """ | ||
113 | pass | ||
114 | |||
115 | def _fakeroot_procedure(self, name, body): | ||
116 | """ | ||
117 | """ | ||
118 | pass | ||
119 | |||
120 | def _def_procedure(self, a, b, c): | ||
121 | """ | ||
122 | """ | ||
123 | pass | ||
124 | |||
125 | def _export_func(self, name): | ||
126 | """ | ||
127 | """ | ||
128 | pass | ||
129 | |||
130 | def _add_handler(self, handler): | ||
131 | """ | ||
132 | """ | ||
133 | pass | ||
diff --git a/bitbake/lib/bb/parse/parse_c/bitbakeparser.y b/bitbake/lib/bb/parse/parse_c/bitbakeparser.y new file mode 100644 index 0000000000..4bc81a913a --- /dev/null +++ b/bitbake/lib/bb/parse/parse_c/bitbakeparser.y | |||
@@ -0,0 +1,161 @@ | |||
1 | /* bbp.lemon | ||
2 | |||
3 | written by Marc Singer | ||
4 | 6 January 2005 | ||
5 | |||
6 | This program is free software; you can redistribute it and/or | ||
7 | modify it under the terms of the GNU General Public License as | ||
8 | published by the Free Software Foundation; either version 2 of the | ||
9 | License, or (at your option) any later version. | ||
10 | |||
11 | This program is distributed in the hope that it will be useful, but | ||
12 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
14 | General Public License for more details. | ||
15 | |||
16 | You should have received a copy of the GNU General Public License | ||
17 | along with this program; if not, write to the Free Software | ||
18 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 | ||
19 | USA. | ||
20 | |||
21 | DESCRIPTION | ||
22 | ----------- | ||
23 | |||
24 | lemon parser specification file for a BitBake input file parser. | ||
25 | |||
26 | Most of the interesting shenanigans are done in the lexer. The | ||
27 | BitBake grammar is not regular. In order to emit tokens that | ||
28 | the parser can properly interpret in LALR fashion, the lexer | ||
29 | manages the interpretation state. This is why there are ISYMBOLs, | ||
30 | SYMBOLS, and TSYMBOLS. | ||
31 | |||
32 | This parser was developed by reading the limited available | ||
33 | documentation for BitBake and by analyzing the available BB files. | ||
34 | There is no assertion of correctness to be made about this parser. | ||
35 | |||
36 | */ | ||
37 | |||
38 | %token_type {token_t} | ||
39 | %name bbparse | ||
40 | %token_prefix T_ | ||
41 | %extra_argument {lex_t* lex} | ||
42 | |||
43 | %include { | ||
44 | #include "token.h" | ||
45 | } | ||
46 | |||
47 | |||
48 | %token_destructor { $$.release_this (); } | ||
49 | |||
50 | %syntax_error { printf ("%s:%d: syntax error\n", | ||
51 | lex->filename (), lex->line ()); } | ||
52 | |||
53 | program ::= statements. | ||
54 | |||
55 | statements ::= statements statement. | ||
56 | statements ::= . | ||
57 | |||
58 | variable(r) ::= SYMBOL(s). | ||
59 | { r.assignString( s.string() ); | ||
60 | s.assignString( 0 ); | ||
61 | s.release_this(); } | ||
62 | variable(r) ::= VARIABLE(v). | ||
63 | { | ||
64 | r.assignString( v.string() ); | ||
65 | v.assignString( 0 ); | ||
66 | v.release_this(); } | ||
67 | |||
68 | statement ::= EXPORT variable(s) OP_ASSIGN STRING(v). | ||
69 | { e_assign( s.string(), v.string() ); | ||
70 | e_export( s.string() ); | ||
71 | s.release_this(); v.release_this(); } | ||
72 | statement ::= EXPORT variable(s) OP_IMMEDIATE STRING(v). | ||
73 | { e_immediate (s.string(), v.string() ); | ||
74 | e_export( s.string() ); | ||
75 | s.release_this(); v.release_this(); } | ||
76 | statement ::= EXPORT variable(s) OP_COND STRING(v). | ||
77 | { e_cond( s.string(), v.string() ); | ||
78 | s.release_this(); v.release_this(); } | ||
79 | |||
80 | statement ::= variable(s) OP_ASSIGN STRING(v). | ||
81 | { e_assign( s.string(), v.string() ); | ||
82 | s.release_this(); v.release_this(); } | ||
83 | statement ::= variable(s) OP_PREPEND STRING(v). | ||
84 | { e_prepend( s.string(), v.string() ); | ||
85 | s.release_this(); v.release_this(); } | ||
86 | statement ::= variable(s) OP_APPEND STRING(v). | ||
87 | { e_append( s.string() , v.string() ); | ||
88 | s.release_this(); v.release_this(); } | ||
89 | statement ::= variable(s) OP_IMMEDIATE STRING(v). | ||
90 | { e_immediate( s.string(), v.string() ); | ||
91 | s.release_this(); v.release_this(); } | ||
92 | statement ::= variable(s) OP_COND STRING(v). | ||
93 | { e_cond( s.string(), v.string() ); | ||
94 | s.release_this(); v.release_this(); } | ||
95 | |||
96 | task ::= TSYMBOL(t) BEFORE TSYMBOL(b) AFTER TSYMBOL(a). | ||
97 | { e_addtask( t.string(), b.string(), a.string() ); | ||
98 | t.release_this(); b.release_this(); a.release_this(); } | ||
99 | task ::= TSYMBOL(t) AFTER TSYMBOL(a) BEFORE TSYMBOL(b). | ||
100 | { e_addtask( t.string(), b.string(), a.string()); | ||
101 | t.release_this(); a.release_this(); b.release_this(); } | ||
102 | task ::= TSYMBOL(t). | ||
103 | { e_addtask( t.string(), NULL, NULL); | ||
104 | t.release_this();} | ||
105 | task ::= TSYMBOL(t) BEFORE TSYMBOL(b). | ||
106 | { e_addtask( t.string(), b.string(), NULL); | ||
107 | t.release_this(); b.release_this(); } | ||
108 | task ::= TSYMBOL(t) AFTER TSYMBOL(a). | ||
109 | { e_addtask( t.string(), NULL, a.string()); | ||
110 | t.release_this(); a.release_this(); } | ||
111 | tasks ::= tasks task. | ||
112 | tasks ::= task. | ||
113 | statement ::= ADDTASK tasks. | ||
114 | |||
115 | statement ::= ADDHANDLER SYMBOL(s). | ||
116 | { e_addhandler( s.string()); s.release_this (); } | ||
117 | |||
118 | func ::= FSYMBOL(f). { e_export_func(f.string()); f.release_this(); } | ||
119 | funcs ::= funcs func. | ||
120 | funcs ::= func. | ||
121 | statement ::= EXPORT_FUNC funcs. | ||
122 | |||
123 | inherit ::= ISYMBOL(i). { e_inherit(i.string() ); i.release_this (); } | ||
124 | inherits ::= inherits inherit. | ||
125 | inherits ::= inherit. | ||
126 | statement ::= INHERIT inherits. | ||
127 | |||
128 | statement ::= INCLUDE ISYMBOL(i). | ||
129 | { e_include(i.string() ); i.release_this(); } | ||
130 | |||
131 | proc_body(r) ::= proc_body(l) PROC_BODY(b). | ||
132 | { /* concatenate body lines */ | ||
133 | r.assignString( token_t::concatString(l.string(), b.string()) ); | ||
134 | l.release_this (); | ||
135 | b.release_this (); | ||
136 | } | ||
137 | proc_body(b) ::= . { b.assignString(0); } | ||
138 | statement ::= variable(p) PROC_OPEN proc_body(b) PROC_CLOSE. | ||
139 | { e_proc( p.string(), b.string() ); | ||
140 | p.release_this(); b.release_this(); } | ||
141 | statement ::= PYTHON SYMBOL(p) PROC_OPEN proc_body(b) PROC_CLOSE. | ||
142 | { e_proc_python (p.string(), b.string() ); | ||
143 | p.release_this(); b.release_this(); } | ||
144 | statement ::= PYTHON PROC_OPEN proc_body(b) PROC_CLOSE. | ||
145 | { e_proc_python( NULL, b.string()); | ||
146 | b.release_this (); } | ||
147 | |||
148 | statement ::= FAKEROOT SYMBOL(p) PROC_OPEN proc_body(b) PROC_CLOSE. | ||
149 | { e_proc_fakeroot(p.string(), b.string() ); | ||
150 | p.release_this (); b.release_this (); } | ||
151 | |||
152 | def_body(r) ::= def_body(l) DEF_BODY(b). | ||
153 | { /* concatenate body lines */ | ||
154 | r.assignString( token_t::concatString(l.string(), b.string()); | ||
155 | l.release_this (); b.release_this (); | ||
156 | } | ||
157 | def_body(b) ::= . { b.sz = 0; } | ||
158 | statement ::= SYMBOL(p) DEF_ARGS(a) def_body(b). | ||
159 | { e_def( p.string(), a.string(), b.string()); | ||
160 | p.release_this(); a.release_this(); b.release_this(); } | ||
161 | |||
diff --git a/bitbake/lib/bb/parse/parse_c/lexer.h b/bitbake/lib/bb/parse/parse_c/lexer.h new file mode 100644 index 0000000000..1edf72dcf5 --- /dev/null +++ b/bitbake/lib/bb/parse/parse_c/lexer.h | |||
@@ -0,0 +1,41 @@ | |||
1 | /* | ||
2 | Copyright (C) 2005 Holger Hans Peter Freyther | ||
3 | |||
4 | Permission is hereby granted, free of charge, to any person obtaining a copy | ||
5 | of this software and associated documentation files (the "Software"), to deal | ||
6 | in the Software without restriction, including without limitation the rights | ||
7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
8 | copies of the Software, and to permit persons to whom the Software is | ||
9 | furnished to do so, subject to the following conditions: | ||
10 | |||
11 | The above copyright notice and this permission notice shall be included in all | ||
12 | copies or substantial portions of the Software. | ||
13 | |||
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT | ||
17 | SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, | ||
18 | DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR | ||
19 | OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR | ||
20 | THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
21 | |||
22 | */ | ||
23 | |||
24 | #ifndef LEXER_H | ||
25 | #define LEXER_H | ||
26 | |||
27 | struct lex_t { | ||
28 | void *parser; | ||
29 | void *scanner; | ||
30 | void* (*parse)(void*, int, token_t, lex_t*); | ||
31 | |||
32 | void accept(int token, const char* string = 0); | ||
33 | void input(char *buf, int *result, int_max_size); | ||
34 | int line()const; | ||
35 | const char* filename()const; | ||
36 | private: | ||
37 | const char* m_fileName; | ||
38 | }; | ||
39 | |||
40 | |||
41 | #endif | ||
diff --git a/bitbake/lib/bb/parse/parse_c/token.h b/bitbake/lib/bb/parse/parse_c/token.h new file mode 100644 index 0000000000..2351fda6b5 --- /dev/null +++ b/bitbake/lib/bb/parse/parse_c/token.h | |||
@@ -0,0 +1,83 @@ | |||
1 | /* | ||
2 | Copyright (C) 2005 Holger Hans Peter Freyther | ||
3 | |||
4 | Permission is hereby granted, free of charge, to any person obtaining a copy | ||
5 | of this software and associated documentation files (the "Software"), to deal | ||
6 | in the Software without restriction, including without limitation the rights | ||
7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
8 | copies of the Software, and to permit persons to whom the Software is | ||
9 | furnished to do so, subject to the following conditions: | ||
10 | |||
11 | The above copyright notice and this permission notice shall be included in all | ||
12 | copies or substantial portions of the Software. | ||
13 | |||
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT | ||
17 | SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, | ||
18 | DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR | ||
19 | OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR | ||
20 | THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
21 | |||
22 | */ | ||
23 | |||
24 | #ifndef TOKEN_H | ||
25 | #define TOKEN_H | ||
26 | |||
27 | #define PURE_METHOD | ||
28 | |||
29 | struct token_t { | ||
30 | const char* string()const PURE_METHOD; | ||
31 | |||
32 | static char* concatString(const char* l, const char* r); | ||
33 | void assignString(const char* str); | ||
34 | void copyString(const char* str); | ||
35 | |||
36 | void release_this(); | ||
37 | |||
38 | private: | ||
39 | char *m_string; | ||
40 | size_t m_stringLen; | ||
41 | }; | ||
42 | |||
43 | inline const char* token_t::string()const | ||
44 | { | ||
45 | return m_string; | ||
46 | } | ||
47 | |||
48 | /* | ||
49 | * append str to the current string | ||
50 | */ | ||
51 | inline char* token_t::concatString(const char* l, const char* r) | ||
52 | { | ||
53 | size_t cb = (l ? strlen (l) : 0) + strlen (r) + 1; | ||
54 | r_sz = new char[cb]; | ||
55 | *r_sz = 0; | ||
56 | if (l) strcat (r_sz, l); | ||
57 | strcat (r_sz, r); | ||
58 | |||
59 | return r_sz; | ||
60 | } | ||
61 | |||
62 | inline void token_t::assignString(const char* str) | ||
63 | { | ||
64 | m_string = str; | ||
65 | m_stringLen = str ? strlen(str) : 0; | ||
66 | } | ||
67 | |||
68 | inline void token_t::copyString(const char* str) | ||
69 | { | ||
70 | if( str ) { | ||
71 | m_stringLen = strlen(str); | ||
72 | m_string = new char[m_stringLen+1]; | ||
73 | strcpy(m_string, str) | ||
74 | } | ||
75 | } | ||
76 | |||
77 | inline void token_t::release_this() | ||
78 | { | ||
79 | delete m_string; | ||
80 | m_string = 0; | ||
81 | } | ||
82 | |||
83 | #endif | ||
diff --git a/bitbake/lib/bb/parse/parse_py/BBHandler.py b/bitbake/lib/bb/parse/parse_py/BBHandler.py new file mode 100644 index 0000000000..fac3e85b36 --- /dev/null +++ b/bitbake/lib/bb/parse/parse_py/BBHandler.py | |||
@@ -0,0 +1,378 @@ | |||
1 | #!/usr/bin/env python | ||
2 | # ex:ts=4:sw=4:sts=4:et | ||
3 | # -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- | ||
4 | """class for handling .bb files | ||
5 | |||
6 | Reads a .bb file and obtains its metadata | ||
7 | |||
8 | Copyright (C) 2003, 2004 Chris Larson | ||
9 | Copyright (C) 2003, 2004 Phil Blundell | ||
10 | |||
11 | This program is free software; you can redistribute it and/or modify it under | ||
12 | the terms of the GNU General Public License as published by the Free Software | ||
13 | Foundation; either version 2 of the License, or (at your option) any later | ||
14 | version. | ||
15 | |||
16 | This program is distributed in the hope that it will be useful, but WITHOUT | ||
17 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
18 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. | ||
19 | |||
20 | You should have received a copy of the GNU General Public License along with | ||
21 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple | ||
22 | Place, Suite 330, Boston, MA 02111-1307 USA.""" | ||
23 | |||
24 | import re, bb, os, sys | ||
25 | import bb.fetch, bb.build | ||
26 | from bb import debug, data, fetch, fatal | ||
27 | |||
28 | from ConfHandler import include, localpath, obtain, init | ||
29 | from bb.parse import ParseError | ||
30 | |||
31 | __func_start_regexp__ = re.compile( r"(((?P<py>python)|(?P<fr>fakeroot))\s*)*(?P<func>[\w\.\-\+\{\}\$]+)?\s*\(\s*\)\s*{$" ) | ||
32 | __inherit_regexp__ = re.compile( r"inherit\s+(.+)" ) | ||
33 | __export_func_regexp__ = re.compile( r"EXPORT_FUNCTIONS\s+(.+)" ) | ||
34 | __addtask_regexp__ = re.compile("addtask\s+(?P<func>\w+)\s*((before\s*(?P<before>((.*(?=after))|(.*))))|(after\s*(?P<after>((.*(?=before))|(.*)))))*") | ||
35 | __addhandler_regexp__ = re.compile( r"addhandler\s+(.+)" ) | ||
36 | __def_regexp__ = re.compile( r"def\s+(\w+).*:" ) | ||
37 | __python_func_regexp__ = re.compile( r"(\s+.*)|(^$)" ) | ||
38 | __word__ = re.compile(r"\S+") | ||
39 | |||
40 | __infunc__ = "" | ||
41 | __inpython__ = False | ||
42 | __body__ = [] | ||
43 | __bbpath_found__ = 0 | ||
44 | __classname__ = "" | ||
45 | classes = [ None, ] | ||
46 | |||
47 | def supports(fn, d): | ||
48 | localfn = localpath(fn, d) | ||
49 | return localfn[-3:] == ".bb" or localfn[-8:] == ".bbclass" or localfn[-4:] == ".inc" | ||
50 | |||
51 | def inherit(files, d): | ||
52 | __inherit_cache = data.getVar('__inherit_cache', d) or "" | ||
53 | fn = "" | ||
54 | lineno = 0 | ||
55 | for f in files: | ||
56 | file = data.expand(f, d) | ||
57 | if file[0] != "/" and file[-8:] != ".bbclass": | ||
58 | file = os.path.join('classes', '%s.bbclass' % file) | ||
59 | |||
60 | if not file in __inherit_cache.split(): | ||
61 | debug(2, "BB %s:%d: inheriting %s" % (fn, lineno, file)) | ||
62 | __inherit_cache += " %s" % file | ||
63 | include(fn, file, d) | ||
64 | data.setVar('__inherit_cache', __inherit_cache, d) | ||
65 | |||
66 | |||
67 | def handle(fn, d, include = 0): | ||
68 | global __func_start_regexp__, __inherit_regexp__, __export_func_regexp__, __addtask_regexp__, __addhandler_regexp__, __infunc__, __body__, __bbpath_found__, __residue__ | ||
69 | __body__ = [] | ||
70 | __bbpath_found__ = 0 | ||
71 | __infunc__ = "" | ||
72 | __classname__ = "" | ||
73 | __residue__ = [] | ||
74 | |||
75 | if include == 0: | ||
76 | debug(2, "BB " + fn + ": handle(data)") | ||
77 | else: | ||
78 | debug(2, "BB " + fn + ": handle(data, include)") | ||
79 | |||
80 | (root, ext) = os.path.splitext(os.path.basename(fn)) | ||
81 | init(d) | ||
82 | |||
83 | if ext == ".bbclass": | ||
84 | __classname__ = root | ||
85 | classes.append(__classname__) | ||
86 | |||
87 | if include != 0: | ||
88 | oldfile = data.getVar('FILE', d) | ||
89 | else: | ||
90 | oldfile = None | ||
91 | |||
92 | fn = obtain(fn, d) | ||
93 | bbpath = (data.getVar('BBPATH', d, 1) or '').split(':') | ||
94 | if not os.path.isabs(fn): | ||
95 | f = None | ||
96 | for p in bbpath: | ||
97 | p = data.expand(p, d) | ||
98 | j = os.path.join(p, fn) | ||
99 | if os.access(j, os.R_OK): | ||
100 | abs_fn = j | ||
101 | f = open(j, 'r') | ||
102 | break | ||
103 | if f is None: | ||
104 | raise IOError("file not found") | ||
105 | else: | ||
106 | f = open(fn,'r') | ||
107 | abs_fn = fn | ||
108 | |||
109 | if ext != ".bbclass": | ||
110 | bbpath.insert(0, os.path.dirname(abs_fn)) | ||
111 | data.setVar('BBPATH', ":".join(bbpath), d) | ||
112 | |||
113 | if include: | ||
114 | bb.parse.mark_dependency(d, abs_fn) | ||
115 | |||
116 | if ext != ".bbclass": | ||
117 | data.setVar('FILE', fn, d) | ||
118 | i = (data.getVar("INHERIT", d, 1) or "").split() | ||
119 | if not "base" in i and __classname__ != "base": | ||
120 | i[0:0] = ["base"] | ||
121 | inherit(i, d) | ||
122 | |||
123 | lineno = 0 | ||
124 | while 1: | ||
125 | lineno = lineno + 1 | ||
126 | s = f.readline() | ||
127 | if not s: break | ||
128 | s = s.rstrip() | ||
129 | feeder(lineno, s, fn, d) | ||
130 | if __inpython__: | ||
131 | # add a blank line to close out any python definition | ||
132 | feeder(lineno + 1, "", fn, d) | ||
133 | if ext == ".bbclass": | ||
134 | classes.remove(__classname__) | ||
135 | else: | ||
136 | if include == 0: | ||
137 | data.expandKeys(d) | ||
138 | data.update_data(d) | ||
139 | anonqueue = data.getVar("__anonqueue", d, 1) or [] | ||
140 | for anon in anonqueue: | ||
141 | data.setVar("__anonfunc", anon["content"], d) | ||
142 | data.setVarFlags("__anonfunc", anon["flags"], d) | ||
143 | from bb import build | ||
144 | try: | ||
145 | t = data.getVar('T', d) | ||
146 | data.setVar('T', '${TMPDIR}/', d) | ||
147 | build.exec_func("__anonfunc", d) | ||
148 | data.delVar('T', d) | ||
149 | if t: | ||
150 | data.setVar('T', t, d) | ||
151 | except Exception, e: | ||
152 | bb.debug(1, "executing anonymous function: %s" % e) | ||
153 | raise | ||
154 | data.delVar("__anonqueue", d) | ||
155 | data.delVar("__anonfunc", d) | ||
156 | set_additional_vars(fn, d, include) | ||
157 | data.update_data(d) | ||
158 | |||
159 | for var in data.keys(d): | ||
160 | if data.getVarFlag(var, 'handler', d): | ||
161 | bb.event.register(data.getVar(var, d)) | ||
162 | continue | ||
163 | |||
164 | if not data.getVarFlag(var, 'task', d): | ||
165 | continue | ||
166 | |||
167 | deps = data.getVarFlag(var, 'deps', d) or [] | ||
168 | postdeps = data.getVarFlag(var, 'postdeps', d) or [] | ||
169 | bb.build.add_task(var, deps, d) | ||
170 | for p in postdeps: | ||
171 | pdeps = data.getVarFlag(p, 'deps', d) or [] | ||
172 | pdeps.append(var) | ||
173 | data.setVarFlag(p, 'deps', pdeps, d) | ||
174 | bb.build.add_task(p, pdeps, d) | ||
175 | bbpath.pop(0) | ||
176 | if oldfile: | ||
177 | bb.data.setVar("FILE", oldfile, d) | ||
178 | return d | ||
179 | |||
180 | def feeder(lineno, s, fn, d): | ||
181 | global __func_start_regexp__, __inherit_regexp__, __export_func_regexp__, __addtask_regexp__, __addhandler_regexp__, __def_regexp__, __python_func_regexp__, __inpython__,__infunc__, __body__, __bbpath_found__, classes, bb, __residue__ | ||
182 | if __infunc__: | ||
183 | if s == '}': | ||
184 | __body__.append('') | ||
185 | data.setVar(__infunc__, '\n'.join(__body__), d) | ||
186 | data.setVarFlag(__infunc__, "func", 1, d) | ||
187 | if __infunc__ == "__anonymous": | ||
188 | anonqueue = bb.data.getVar("__anonqueue", d) or [] | ||
189 | anonitem = {} | ||
190 | anonitem["content"] = bb.data.getVar("__anonymous", d) | ||
191 | anonitem["flags"] = bb.data.getVarFlags("__anonymous", d) | ||
192 | anonqueue.append(anonitem) | ||
193 | bb.data.setVar("__anonqueue", anonqueue, d) | ||
194 | bb.data.delVarFlags("__anonymous", d) | ||
195 | bb.data.delVar("__anonymous", d) | ||
196 | __infunc__ = "" | ||
197 | __body__ = [] | ||
198 | else: | ||
199 | __body__.append(s) | ||
200 | return | ||
201 | |||
202 | if __inpython__: | ||
203 | m = __python_func_regexp__.match(s) | ||
204 | if m: | ||
205 | __body__.append(s) | ||
206 | return | ||
207 | else: | ||
208 | text = '\n'.join(__body__) | ||
209 | comp = compile(text, "<bb>", "exec") | ||
210 | exec comp in __builtins__ | ||
211 | __body__ = [] | ||
212 | __inpython__ = False | ||
213 | funcs = data.getVar('__functions__', d) or "" | ||
214 | data.setVar('__functions__', "%s\n%s" % (funcs, text), d) | ||
215 | # fall through | ||
216 | |||
217 | if s == '' or s[0] == '#': return # skip comments and empty lines | ||
218 | |||
219 | if s[-1] == '\\': | ||
220 | __residue__.append(s[:-1]) | ||
221 | return | ||
222 | |||
223 | s = "".join(__residue__) + s | ||
224 | __residue__ = [] | ||
225 | |||
226 | m = __func_start_regexp__.match(s) | ||
227 | if m: | ||
228 | __infunc__ = m.group("func") or "__anonymous" | ||
229 | key = __infunc__ | ||
230 | if data.getVar(key, d): | ||
231 | # clean up old version of this piece of metadata, as its | ||
232 | # flags could cause problems | ||
233 | data.setVarFlag(key, 'python', None, d) | ||
234 | data.setVarFlag(key, 'fakeroot', None, d) | ||
235 | if m.group("py") is not None: | ||
236 | data.setVarFlag(key, "python", "1", d) | ||
237 | else: | ||
238 | data.delVarFlag(key, "python", d) | ||
239 | if m.group("fr") is not None: | ||
240 | data.setVarFlag(key, "fakeroot", "1", d) | ||
241 | else: | ||
242 | data.delVarFlag(key, "fakeroot", d) | ||
243 | return | ||
244 | |||
245 | m = __def_regexp__.match(s) | ||
246 | if m: | ||
247 | __body__.append(s) | ||
248 | __inpython__ = True | ||
249 | return | ||
250 | |||
251 | m = __export_func_regexp__.match(s) | ||
252 | if m: | ||
253 | fns = m.group(1) | ||
254 | n = __word__.findall(fns) | ||
255 | for f in n: | ||
256 | allvars = [] | ||
257 | allvars.append(f) | ||
258 | allvars.append(classes[-1] + "_" + f) | ||
259 | |||
260 | vars = [[ allvars[0], allvars[1] ]] | ||
261 | if len(classes) > 1 and classes[-2] is not None: | ||
262 | allvars.append(classes[-2] + "_" + f) | ||
263 | vars = [] | ||
264 | vars.append([allvars[2], allvars[1]]) | ||
265 | vars.append([allvars[0], allvars[2]]) | ||
266 | |||
267 | for (var, calledvar) in vars: | ||
268 | if data.getVar(var, d) and not data.getVarFlag(var, 'export_func', d): | ||
269 | continue | ||
270 | |||
271 | if data.getVar(var, d): | ||
272 | data.setVarFlag(var, 'python', None, d) | ||
273 | data.setVarFlag(var, 'func', None, d) | ||
274 | |||
275 | for flag in [ "func", "python" ]: | ||
276 | if data.getVarFlag(calledvar, flag, d): | ||
277 | data.setVarFlag(var, flag, data.getVarFlag(calledvar, flag, d), d) | ||
278 | for flag in [ "dirs" ]: | ||
279 | if data.getVarFlag(var, flag, d): | ||
280 | data.setVarFlag(calledvar, flag, data.getVarFlag(var, flag, d), d) | ||
281 | |||
282 | if data.getVarFlag(calledvar, "python", d): | ||
283 | data.setVar(var, "\tbb.build.exec_func('" + calledvar + "', d)\n", d) | ||
284 | else: | ||
285 | data.setVar(var, "\t" + calledvar + "\n", d) | ||
286 | data.setVarFlag(var, 'export_func', '1', d) | ||
287 | |||
288 | return | ||
289 | |||
290 | m = __addtask_regexp__.match(s) | ||
291 | if m: | ||
292 | func = m.group("func") | ||
293 | before = m.group("before") | ||
294 | after = m.group("after") | ||
295 | if func is None: | ||
296 | return | ||
297 | var = "do_" + func | ||
298 | |||
299 | data.setVarFlag(var, "task", 1, d) | ||
300 | |||
301 | if after is not None: | ||
302 | # set up deps for function | ||
303 | data.setVarFlag(var, "deps", after.split(), d) | ||
304 | if before is not None: | ||
305 | # set up things that depend on this func | ||
306 | data.setVarFlag(var, "postdeps", before.split(), d) | ||
307 | return | ||
308 | |||
309 | m = __addhandler_regexp__.match(s) | ||
310 | if m: | ||
311 | fns = m.group(1) | ||
312 | hs = __word__.findall(fns) | ||
313 | for h in hs: | ||
314 | data.setVarFlag(h, "handler", 1, d) | ||
315 | return | ||
316 | |||
317 | m = __inherit_regexp__.match(s) | ||
318 | if m: | ||
319 | |||
320 | files = m.group(1) | ||
321 | n = __word__.findall(files) | ||
322 | inherit(n, d) | ||
323 | return | ||
324 | |||
325 | from bb.parse import ConfHandler | ||
326 | return ConfHandler.feeder(lineno, s, fn, d) | ||
327 | |||
328 | __pkgsplit_cache__={} | ||
329 | def vars_from_file(mypkg, d): | ||
330 | if not mypkg: | ||
331 | return (None, None, None) | ||
332 | if mypkg in __pkgsplit_cache__: | ||
333 | return __pkgsplit_cache__[mypkg] | ||
334 | |||
335 | myfile = os.path.splitext(os.path.basename(mypkg)) | ||
336 | parts = myfile[0].split('_') | ||
337 | __pkgsplit_cache__[mypkg] = parts | ||
338 | exp = 3 - len(parts) | ||
339 | tmplist = [] | ||
340 | while exp != 0: | ||
341 | exp -= 1 | ||
342 | tmplist.append(None) | ||
343 | parts.extend(tmplist) | ||
344 | return parts | ||
345 | |||
346 | def set_additional_vars(file, d, include): | ||
347 | """Deduce rest of variables, e.g. ${A} out of ${SRC_URI}""" | ||
348 | |||
349 | debug(2,"BB %s: set_additional_vars" % file) | ||
350 | |||
351 | src_uri = data.getVar('SRC_URI', d) | ||
352 | if not src_uri: | ||
353 | return | ||
354 | src_uri = data.expand(src_uri, d) | ||
355 | |||
356 | a = data.getVar('A', d) | ||
357 | if a: | ||
358 | a = data.expand(a, d).split() | ||
359 | else: | ||
360 | a = [] | ||
361 | |||
362 | from bb import fetch | ||
363 | try: | ||
364 | fetch.init(src_uri.split(), d) | ||
365 | except fetch.NoMethodError: | ||
366 | pass | ||
367 | except bb.MalformedUrl,e: | ||
368 | raise ParseError("Unable to generate local paths for SRC_URI due to malformed uri: %s" % e) | ||
369 | |||
370 | a += fetch.localpaths(d) | ||
371 | del fetch | ||
372 | data.setVar('A', " ".join(a), d) | ||
373 | |||
374 | |||
375 | # Add us to the handlers list | ||
376 | from bb.parse import handlers | ||
377 | handlers.append({'supports': supports, 'handle': handle, 'init': init}) | ||
378 | del handlers | ||
diff --git a/bitbake/lib/bb/parse/parse_py/BBHandler.pyc b/bitbake/lib/bb/parse/parse_py/BBHandler.pyc new file mode 100644 index 0000000000..bfaa4c6004 --- /dev/null +++ b/bitbake/lib/bb/parse/parse_py/BBHandler.pyc | |||
Binary files differ | |||
diff --git a/bitbake/lib/bb/parse/parse_py/ConfHandler.py b/bitbake/lib/bb/parse/parse_py/ConfHandler.py new file mode 100644 index 0000000000..41ef96d557 --- /dev/null +++ b/bitbake/lib/bb/parse/parse_py/ConfHandler.py | |||
@@ -0,0 +1,199 @@ | |||
1 | #!/usr/bin/env python | ||
2 | # ex:ts=4:sw=4:sts=4:et | ||
3 | # -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- | ||
4 | """class for handling configuration data files | ||
5 | |||
6 | Reads a .conf file and obtains its metadata | ||
7 | |||
8 | Copyright (C) 2003, 2004 Chris Larson | ||
9 | Copyright (C) 2003, 2004 Phil Blundell | ||
10 | |||
11 | This program is free software; you can redistribute it and/or modify it under | ||
12 | the terms of the GNU General Public License as published by the Free Software | ||
13 | Foundation; either version 2 of the License, or (at your option) any later | ||
14 | version. | ||
15 | |||
16 | This program is distributed in the hope that it will be useful, but WITHOUT | ||
17 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
18 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. | ||
19 | |||
20 | You should have received a copy of the GNU General Public License along with | ||
21 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple | ||
22 | Place, Suite 330, Boston, MA 02111-1307 USA.""" | ||
23 | |||
24 | import re, bb.data, os, sys | ||
25 | from bb import debug, fatal | ||
26 | from bb.parse import ParseError | ||
27 | |||
28 | #__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)$") | ||
29 | __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)$") | ||
30 | __include_regexp__ = re.compile( r"include\s+(.+)" ) | ||
31 | |||
32 | def init(data): | ||
33 | if not bb.data.getVar('TOPDIR', data): | ||
34 | bb.data.setVar('TOPDIR', os.getcwd(), data) | ||
35 | if not bb.data.getVar('BBPATH', data): | ||
36 | bb.data.setVar('BBPATH', os.path.join(sys.prefix, 'share', 'bitbake'), data) | ||
37 | |||
38 | def supports(fn, d): | ||
39 | return localpath(fn, d)[-5:] == ".conf" | ||
40 | |||
41 | def localpath(fn, d): | ||
42 | if os.path.exists(fn): | ||
43 | return fn | ||
44 | |||
45 | localfn = None | ||
46 | try: | ||
47 | localfn = bb.fetch.localpath(fn, d) | ||
48 | except bb.MalformedUrl: | ||
49 | pass | ||
50 | |||
51 | if not localfn: | ||
52 | localfn = fn | ||
53 | return localfn | ||
54 | |||
55 | def obtain(fn, data = bb.data.init()): | ||
56 | import sys, bb | ||
57 | fn = bb.data.expand(fn, data) | ||
58 | localfn = bb.data.expand(localpath(fn, data), data) | ||
59 | |||
60 | if localfn != fn: | ||
61 | dldir = bb.data.getVar('DL_DIR', data, 1) | ||
62 | if not dldir: | ||
63 | debug(1, "obtain: DL_DIR not defined") | ||
64 | return localfn | ||
65 | bb.mkdirhier(dldir) | ||
66 | try: | ||
67 | bb.fetch.init([fn]) | ||
68 | except bb.fetch.NoMethodError: | ||
69 | (type, value, traceback) = sys.exc_info() | ||
70 | debug(1, "obtain: no method: %s" % value) | ||
71 | return localfn | ||
72 | |||
73 | try: | ||
74 | bb.fetch.go(data) | ||
75 | except bb.fetch.MissingParameterError: | ||
76 | (type, value, traceback) = sys.exc_info() | ||
77 | debug(1, "obtain: missing parameters: %s" % value) | ||
78 | return localfn | ||
79 | except bb.fetch.FetchError: | ||
80 | (type, value, traceback) = sys.exc_info() | ||
81 | debug(1, "obtain: failed: %s" % value) | ||
82 | return localfn | ||
83 | return localfn | ||
84 | |||
85 | |||
86 | def include(oldfn, fn, data = bb.data.init()): | ||
87 | if oldfn == fn: # prevent infinate recursion | ||
88 | return None | ||
89 | |||
90 | import bb | ||
91 | fn = bb.data.expand(fn, data) | ||
92 | oldfn = bb.data.expand(oldfn, data) | ||
93 | |||
94 | from bb.parse import handle | ||
95 | try: | ||
96 | ret = handle(fn, data, 1) | ||
97 | except IOError: | ||
98 | debug(2, "CONF file '%s' not found" % fn) | ||
99 | |||
100 | def handle(fn, data = bb.data.init(), include = 0): | ||
101 | if include: | ||
102 | inc_string = "including" | ||
103 | else: | ||
104 | inc_string = "reading" | ||
105 | init(data) | ||
106 | |||
107 | if include == 0: | ||
108 | bb.data.inheritFromOS(data) | ||
109 | oldfile = None | ||
110 | else: | ||
111 | oldfile = bb.data.getVar('FILE', data) | ||
112 | |||
113 | fn = obtain(fn, data) | ||
114 | bbpath = [] | ||
115 | if not os.path.isabs(fn): | ||
116 | f = None | ||
117 | vbbpath = bb.data.getVar("BBPATH", data) | ||
118 | if vbbpath: | ||
119 | bbpath += vbbpath.split(":") | ||
120 | for p in bbpath: | ||
121 | currname = os.path.join(bb.data.expand(p, data), fn) | ||
122 | if os.access(currname, os.R_OK): | ||
123 | f = open(currname, 'r') | ||
124 | abs_fn = currname | ||
125 | debug(1, "CONF %s %s" % (inc_string, currname)) | ||
126 | break | ||
127 | if f is None: | ||
128 | raise IOError("file not found") | ||
129 | else: | ||
130 | f = open(fn,'r') | ||
131 | debug(1, "CONF %s %s" % (inc_string,fn)) | ||
132 | abs_fn = fn | ||
133 | |||
134 | if include: | ||
135 | bb.parse.mark_dependency(data, abs_fn) | ||
136 | |||
137 | lineno = 0 | ||
138 | bb.data.setVar('FILE', fn, data) | ||
139 | while 1: | ||
140 | lineno = lineno + 1 | ||
141 | s = f.readline() | ||
142 | if not s: break | ||
143 | w = s.strip() | ||
144 | if not w: continue # skip empty lines | ||
145 | s = s.rstrip() | ||
146 | if s[0] == '#': continue # skip comments | ||
147 | while s[-1] == '\\': | ||
148 | s2 = f.readline()[:-1].strip() | ||
149 | lineno = lineno + 1 | ||
150 | s = s[:-1] + s2 | ||
151 | feeder(lineno, s, fn, data) | ||
152 | |||
153 | if oldfile: | ||
154 | bb.data.setVar('FILE', oldfile, data) | ||
155 | return data | ||
156 | |||
157 | def feeder(lineno, s, fn, data = bb.data.init()): | ||
158 | m = __config_regexp__.match(s) | ||
159 | if m: | ||
160 | groupd = m.groupdict() | ||
161 | key = groupd["var"] | ||
162 | if "exp" in groupd and groupd["exp"] != None: | ||
163 | bb.data.setVarFlag(key, "export", 1, data) | ||
164 | if "ques" in groupd and groupd["ques"] != None: | ||
165 | val = bb.data.getVar(key, data) | ||
166 | if val == None: | ||
167 | val = groupd["value"] | ||
168 | elif "colon" in groupd and groupd["colon"] != None: | ||
169 | val = bb.data.expand(groupd["value"], data) | ||
170 | elif "append" in groupd and groupd["append"] != None: | ||
171 | val = "%s %s" % ((bb.data.getVar(key, data) or ""), groupd["value"]) | ||
172 | elif "prepend" in groupd and groupd["prepend"] != None: | ||
173 | val = "%s %s" % (groupd["value"], (bb.data.getVar(key, data) or "")) | ||
174 | elif "postdot" in groupd and groupd["postdot"] != None: | ||
175 | val = "%s%s" % ((bb.data.getVar(key, data) or ""), groupd["value"]) | ||
176 | elif "predot" in groupd and groupd["predot"] != None: | ||
177 | val = "%s%s" % (groupd["value"], (bb.data.getVar(key, data) or "")) | ||
178 | else: | ||
179 | val = groupd["value"] | ||
180 | if 'flag' in groupd and groupd['flag'] != None: | ||
181 | # bb.note("setVarFlag(%s, %s, %s, data)" % (key, groupd['flag'], val)) | ||
182 | bb.data.setVarFlag(key, groupd['flag'], val, data) | ||
183 | else: | ||
184 | bb.data.setVar(key, val, data) | ||
185 | return | ||
186 | |||
187 | m = __include_regexp__.match(s) | ||
188 | if m: | ||
189 | s = bb.data.expand(m.group(1), data) | ||
190 | # debug(2, "CONF %s:%d: including %s" % (fn, lineno, s)) | ||
191 | include(fn, s, data) | ||
192 | return | ||
193 | |||
194 | raise ParseError("%s:%d: unparsed line: '%s'" % (fn, lineno, s)); | ||
195 | |||
196 | # Add us to the handlers list | ||
197 | from bb.parse import handlers | ||
198 | handlers.append({'supports': supports, 'handle': handle, 'init': init}) | ||
199 | del handlers | ||
diff --git a/bitbake/lib/bb/parse/parse_py/ConfHandler.pyc b/bitbake/lib/bb/parse/parse_py/ConfHandler.pyc new file mode 100644 index 0000000000..e0ec666ed1 --- /dev/null +++ b/bitbake/lib/bb/parse/parse_py/ConfHandler.pyc | |||
Binary files differ | |||
diff --git a/bitbake/lib/bb/parse/parse_py/__init__.py b/bitbake/lib/bb/parse/parse_py/__init__.py new file mode 100644 index 0000000000..6a2ce4059d --- /dev/null +++ b/bitbake/lib/bb/parse/parse_py/__init__.py | |||
@@ -0,0 +1,32 @@ | |||
1 | #!/usr/bin/env python | ||
2 | # ex:ts=4:sw=4:sts=4:et | ||
3 | # -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- | ||
4 | """ | ||
5 | BitBake Parsers | ||
6 | |||
7 | File parsers for the BitBake build tools. | ||
8 | |||
9 | Copyright (C) 2003, 2004 Chris Larson | ||
10 | Copyright (C) 2003, 2004 Phil Blundell | ||
11 | |||
12 | This program is free software; you can redistribute it and/or modify it under | ||
13 | the terms of the GNU General Public License as published by the Free Software | ||
14 | Foundation; either version 2 of the License, or (at your option) any later | ||
15 | version. | ||
16 | |||
17 | This program is distributed in the hope that it will be useful, but WITHOUT | ||
18 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
19 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. | ||
20 | |||
21 | You should have received a copy of the GNU General Public License along with | ||
22 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple | ||
23 | Place, Suite 330, Boston, MA 02111-1307 USA. | ||
24 | |||
25 | Based on functions from the base bb module, Copyright 2003 Holger Schurig | ||
26 | """ | ||
27 | __version__ = '1.0' | ||
28 | |||
29 | __all__ = [ 'ConfHandler', 'BBHandler'] | ||
30 | |||
31 | import ConfHandler | ||
32 | import BBHandler | ||
diff --git a/bitbake/lib/bb/parse/parse_py/__init__.pyc b/bitbake/lib/bb/parse/parse_py/__init__.pyc new file mode 100644 index 0000000000..c081e02727 --- /dev/null +++ b/bitbake/lib/bb/parse/parse_py/__init__.pyc | |||
Binary files differ | |||