diff options
Diffstat (limited to 'bitbake/lib/bb/parse/parse_c/bitbakec.pyx')
-rw-r--r-- | bitbake/lib/bb/parse/parse_c/bitbakec.pyx | 205 |
1 files changed, 139 insertions, 66 deletions
diff --git a/bitbake/lib/bb/parse/parse_c/bitbakec.pyx b/bitbake/lib/bb/parse/parse_c/bitbakec.pyx index 362cc2021e..c666e9b6b1 100644 --- a/bitbake/lib/bb/parse/parse_c/bitbakec.pyx +++ b/bitbake/lib/bb/parse/parse_c/bitbakec.pyx | |||
@@ -6,96 +6,107 @@ cdef extern from "stdio.h": | |||
6 | FILE *fopen(char*, char*) | 6 | FILE *fopen(char*, char*) |
7 | int fclose(FILE *fp) | 7 | int fclose(FILE *fp) |
8 | 8 | ||
9 | cdef extern from "string.h": | ||
10 | int strlen(char*) | ||
9 | 11 | ||
10 | cdef extern from "lexerc.h": | 12 | cdef extern from "lexerc.h": |
11 | ctypedef struct lex_t: | 13 | ctypedef struct lex_t: |
12 | void* parser | 14 | void* parser |
13 | void* scanner | 15 | void* scanner |
16 | char* name | ||
14 | FILE* file | 17 | FILE* file |
18 | int config | ||
15 | void* data | 19 | void* data |
16 | 20 | ||
17 | int lineError | 21 | int lineError |
18 | int errorParse | 22 | int errorParse |
19 | 23 | ||
20 | cdef extern void parse(FILE*, object) | 24 | cdef extern int parse(FILE*, char*, object, int) |
21 | 25 | ||
22 | def parsefile(object file, object data): | 26 | def parsefile(object file, object data, object config): |
23 | print "parsefile: 1", file, data | 27 | #print "parsefile: 1", file, data |
24 | 28 | ||
25 | # Open the file | 29 | # Open the file |
26 | cdef FILE* f | 30 | cdef FILE* f |
27 | 31 | ||
28 | f = fopen(file, "r") | 32 | f = fopen(file, "r") |
29 | print "parsefile: 2 opening file" | 33 | #print "parsefile: 2 opening file" |
30 | if (f == NULL): | 34 | if (f == NULL): |
31 | raise IOError("No such file %s." % file) | 35 | raise IOError("No such file %s." % file) |
32 | 36 | ||
33 | print "parsefile: 3 parse" | 37 | #print "parsefile: 3 parse" |
34 | parse(f, data) | 38 | parse(f, file, data, config) |
35 | 39 | ||
36 | # Close the file | 40 | # Close the file |
37 | print "parsefile: 4 closing" | ||
38 | fclose(f) | 41 | fclose(f) |
39 | 42 | ||
40 | 43 | ||
41 | cdef public void e_assign(lex_t* container, char* key, char* what): | 44 | cdef public void e_assign(lex_t* container, char* key, char* what): |
42 | print "e_assign", key, what | 45 | #print "e_assign", key, what |
46 | if what == NULL: | ||
47 | print "FUTURE Warning empty string: use \"\"" | ||
48 | what = "" | ||
49 | |||
43 | d = <object>container.data | 50 | d = <object>container.data |
44 | d.setVar(key, what) | 51 | d.setVar(key, what) |
45 | 52 | ||
46 | cdef public void e_export(lex_t* c, char* what): | 53 | cdef public void e_export(lex_t* c, char* what): |
47 | print "e_export", what | 54 | #print "e_export", what |
48 | #exp: | 55 | #exp: |
49 | # bb.data.setVarFlag(key, "export", 1, data) | 56 | # bb.data.setVarFlag(key, "export", 1, data) |
50 | d = <object>container.data | 57 | d = <object>c.data |
51 | d.setVarFlag(key, "export", 1) | 58 | d.setVarFlag(what, "export", 1) |
52 | 59 | ||
53 | cdef public void e_immediate(lex_t* c, char* key, char* what): | 60 | cdef public void e_immediate(lex_t* c, char* key, char* what): |
54 | print "e_immediate", key, what | 61 | #print "e_immediate", key, what |
55 | #colon: | 62 | #colon: |
56 | # val = bb.data.expand(groupd["value"], data) | 63 | # val = bb.data.expand(groupd["value"], data) |
57 | d = <object>c.data | 64 | d = <object>c.data |
58 | d.setVar(key, d.expand(what)) | 65 | d.setVar(key, d.expand(what,d)) |
59 | 66 | ||
60 | cdef public void e_cond(lex_t* c, char* key, char* what): | 67 | cdef public void e_cond(lex_t* c, char* key, char* what): |
61 | print "e_cond", key, what | 68 | #print "e_cond", key, what |
62 | #ques: | 69 | #ques: |
63 | # val = bb.data.getVar(key, data) | 70 | # val = bb.data.getVar(key, data) |
64 | # if val == None: | 71 | # if val == None: |
65 | # val = groupd["value"] | 72 | # val = groupd["value"] |
73 | if what == NULL: | ||
74 | print "FUTURE warning: Use \"\" for", key | ||
75 | what = "" | ||
76 | |||
66 | d = <object>c.data | 77 | d = <object>c.data |
67 | d.setVar(key, (d.getVar(key) or what)) | 78 | d.setVar(key, (d.getVar(key,False) or what)) |
68 | 79 | ||
69 | cdef public void e_prepend(lex_t* c, char* key, char* what): | 80 | cdef public void e_prepend(lex_t* c, char* key, char* what): |
70 | print "e_prepend", key, what | 81 | #print "e_prepend", key, what |
71 | #prepend: | 82 | #prepend: |
72 | # val = "%s %s" % (groupd["value"], (bb.data.getVar(key, data) or "")) | 83 | # val = "%s %s" % (groupd["value"], (bb.data.getVar(key, data) or "")) |
73 | d = <object>c.data | 84 | d = <object>c.data |
74 | d.setVar(key, what + " " + (d.getVar(key) or "")) | 85 | d.setVar(key, what + " " + (d.getVar(key,0) or "")) |
75 | 86 | ||
76 | cdef public void e_append(lex_t* c, char* key, char* what): | 87 | cdef public void e_append(lex_t* c, char* key, char* what): |
77 | print "e_append", key, what | 88 | #print "e_append", key, what |
78 | #append: | 89 | #append: |
79 | # val = "%s %s" % ((bb.data.getVar(key, data) or ""), groupd["value"]) | 90 | # val = "%s %s" % ((bb.data.getVar(key, data) or ""), groupd["value"]) |
80 | d = <object>c.data | 91 | d = <object>c.data |
81 | d.setVar(key, (d.getVar(key) or "") + " " + what) | 92 | d.setVar(key, (d.getVar(key,0) or "") + " " + what) |
82 | 93 | ||
83 | cdef public void e_precat(lex_t* c, char* key, char* what): | 94 | cdef public void e_precat(lex_t* c, char* key, char* what): |
84 | print "e_precat", key, what | 95 | #print "e_precat", key, what |
85 | #predot: | 96 | #predot: |
86 | # val = "%s%s" % (groupd["value"], (bb.data.getVar(key, data) or "")) | 97 | # val = "%s%s" % (groupd["value"], (bb.data.getVar(key, data) or "")) |
87 | d = <object>c.data | 98 | d = <object>c.data |
88 | d.setVar(key, what + (d.getVar(key) or "")) | 99 | d.setVar(key, what + (d.getVar(key,0) or "")) |
89 | 100 | ||
90 | cdef public void e_postcat(lex_t* c, char* key, char* what): | 101 | cdef public void e_postcat(lex_t* c, char* key, char* what): |
91 | print "e_postcat", key, what | 102 | #print "e_postcat", key, what |
92 | #postdot: | 103 | #postdot: |
93 | # val = "%s%s" % ((bb.data.getVar(key, data) or ""), groupd["value"]) | 104 | # val = "%s%s" % ((bb.data.getVar(key, data) or ""), groupd["value"]) |
94 | d = <object>c.data | 105 | d = <object>c.data |
95 | d.setVar(key, (d.getVar(key) or "") + what) | 106 | d.setVar(key, (d.getVar(key,0) or "") + what) |
96 | 107 | ||
97 | cdef public void e_addtask(lex_t* c, char* name, char* before, char* after): | 108 | cdef public int e_addtask(lex_t* c, char* name, char* before, char* after) except -1: |
98 | print "e_addtask", name, before, after | 109 | #print "e_addtask", name |
99 | # func = m.group("func") | 110 | # func = m.group("func") |
100 | # before = m.group("before") | 111 | # before = m.group("before") |
101 | # after = m.group("after") | 112 | # after = m.group("after") |
@@ -112,69 +123,131 @@ cdef public void e_addtask(lex_t* c, char* name, char* before, char* after): | |||
112 | # # set up things that depend on this func | 123 | # # set up things that depend on this func |
113 | # data.setVarFlag(var, "postdeps", before.split(), d) | 124 | # data.setVarFlag(var, "postdeps", before.split(), d) |
114 | # return | 125 | # return |
115 | 126 | ||
116 | do = "do_%s" % name | 127 | if c.config == 1: |
128 | from bb.parse import ParseError | ||
129 | raise ParseError("No tasks allowed in config files") | ||
130 | return -1 | ||
131 | |||
117 | d = <object>c.data | 132 | d = <object>c.data |
133 | do = "do_%s" % name | ||
118 | d.setVarFlag(do, "task", 1) | 134 | d.setVarFlag(do, "task", 1) |
119 | 135 | ||
120 | if strlen(before) > 0: | 136 | if before != NULL and strlen(before) > 0: |
137 | #print "Before", before | ||
138 | d.setVarFlag(do, "postdeps", ("%s" % before).split()) | ||
139 | if after != NULL and strlen(after) > 0: | ||
140 | #print "After", after | ||
121 | d.setVarFlag(do, "deps", ("%s" % after).split()) | 141 | d.setVarFlag(do, "deps", ("%s" % after).split()) |
122 | if strlen(after) > 0: | ||
123 | d.setVarFlag(do, "deps", ("%s" % before).split()) | ||
124 | 142 | ||
143 | return 0 | ||
125 | 144 | ||
126 | cdef public void e_addhandler(lex_t* c, char* h): | 145 | cdef public int e_addhandler(lex_t* c, char* h) except -1: |
127 | print "e_addhandler", h | 146 | #print "e_addhandler", h |
128 | # data.setVarFlag(h, "handler", 1, d) | 147 | # data.setVarFlag(h, "handler", 1, d) |
148 | if c.config == 1: | ||
149 | from bb.parse import ParseError | ||
150 | raise ParseError("No handlers allowed in config files") | ||
151 | return -1 | ||
152 | |||
129 | d = <object>c.data | 153 | d = <object>c.data |
130 | d.setVarFlag(h, "handler", 1) | 154 | d.setVarFlag(h, "handler", 1) |
155 | return 0 | ||
156 | |||
157 | cdef public int e_export_func(lex_t* c, char* function) except -1: | ||
158 | #print "e_export_func", function | ||
159 | if c.config == 1: | ||
160 | from bb.parse import ParseError | ||
161 | raise ParseError("No functions allowed in config files") | ||
162 | return -1 | ||
163 | |||
164 | return 0 | ||
165 | |||
166 | cdef public int e_inherit(lex_t* c, char* file) except -1: | ||
167 | #print "e_inherit", file | ||
131 | 168 | ||
132 | cdef public void e_export_func(lex_t* c, char* function): | 169 | if c.config == 1: |
133 | print "e_export_func", function | 170 | from bb.parse import ParseError |
134 | pass | 171 | raise ParseError("No inherits allowed in config files") |
172 | return -1 | ||
135 | 173 | ||
136 | cdef public void e_inherit(lex_t* c, char* file): | 174 | return 0 |
137 | print "e_inherit", file | ||
138 | pass | ||
139 | 175 | ||
140 | cdef public void e_include(lex_t* c, char* file): | 176 | cdef public void e_include(lex_t* c, char* file): |
141 | print "e_include", file | 177 | from bb.parse import handle |
142 | d = <object>c.data | 178 | d = <object>c.data |
143 | d.expand(file) | 179 | |
144 | |||
145 | try: | 180 | try: |
146 | parsefile(file, d) | 181 | handle(d.expand(file,d), d, True) |
147 | except IOError: | 182 | except IOError: |
148 | print "Could not include required file %s" % file | 183 | print "Could not include file", file |
149 | 184 | ||
150 | 185 | ||
151 | cdef public void e_require(lex_t* c, char* file): | 186 | cdef public int e_require(lex_t* c, char* file) except -1: |
152 | print "e_require", file | 187 | #print "e_require", file |
188 | from bb.parse import handle | ||
153 | d = <object>c.data | 189 | d = <object>c.data |
154 | d.expand(file) | 190 | |
155 | |||
156 | try: | 191 | try: |
157 | parsefile(file, d) | 192 | handle(d.expand(file,d), d, True) |
158 | except IOError: | 193 | except IOError: |
159 | raise CParseError("Could not include required file %s" % file) | 194 | print "ParseError", file |
195 | from bb.parse import ParseError | ||
196 | raise ParseError("Could not include required file %s" % file) | ||
197 | return -1 | ||
198 | |||
199 | return 0 | ||
200 | |||
201 | cdef public int e_proc(lex_t* c, char* key, char* what) except -1: | ||
202 | #print "e_proc", key, what | ||
203 | if c.config == 1: | ||
204 | from bb.parse import ParseError | ||
205 | raise ParseError("No inherits allowed in config files") | ||
206 | return -1 | ||
207 | |||
208 | return 0 | ||
209 | |||
210 | cdef public int e_proc_python(lex_t* c, char* key, char* what) except -1: | ||
211 | #print "e_proc_python" | ||
212 | if c.config == 1: | ||
213 | from bb.parse import ParseError | ||
214 | raise ParseError("No pythin allowed in config files") | ||
215 | return -1 | ||
216 | |||
217 | if key != NULL: | ||
218 | pass | ||
219 | #print "Key", key | ||
220 | if what != NULL: | ||
221 | pass | ||
222 | #print "What", what | ||
223 | |||
224 | return 0 | ||
225 | |||
226 | cdef public int e_proc_fakeroot(lex_t* c, char* key, char* what) except -1: | ||
227 | #print "e_fakeroot", key, what | ||
228 | |||
229 | if c.config == 1: | ||
230 | from bb.parse import ParseError | ||
231 | raise ParseError("No fakeroot allowed in config files") | ||
232 | return -1 | ||
233 | |||
234 | return 0 | ||
235 | |||
236 | cdef public int e_def(lex_t* c, char* a, char* b, char* d) except -1: | ||
237 | #print "e_def", a, b, d | ||
160 | 238 | ||
161 | cdef public void e_proc(lex_t* c, char* key, char* what): | 239 | if c.config == 1: |
162 | print "e_proc", key, what | 240 | from bb.parse import ParseError |
163 | pass | 241 | raise ParseError("No defs allowed in config files") |
242 | return -1 | ||
164 | 243 | ||
165 | cdef public void e_proc_python(lex_t* c, char* key, char* what): | 244 | return 0 |
166 | print "e_proc_python", key, what | ||
167 | pass | ||
168 | 245 | ||
169 | cdef public void e_proc_fakeroot(lex_t* c, char* key, char* what): | 246 | cdef public int e_parse_error(lex_t* c) except -1: |
170 | print "e_fakeroot", key, what | 247 | print "e_parse_error", c.name, "line:", lineError, "parse:", errorParse |
171 | pass | ||
172 | 248 | ||
173 | cdef public void e_def(lex_t* c, char* a, char* b, char* d): | ||
174 | print "e_def", key, what | ||
175 | pass | ||
176 | 249 | ||
177 | cdef public void e_parse_error(lex_t* c): | 250 | from bb.parse import ParseError |
178 | print "e_parse_error", "line:", lineError, "parse:", errorParse | 251 | raise ParseError("There was an parse error, sorry unable to give more information at the current time. File: %s Line: %d" % (c.name,lineError) ) |
179 | raise CParseError("There was an parse error, sorry unable to give more information at the current time.") | 252 | return -1 |
180 | 253 | ||