lib/bb/parse/parser_c: Handle includes, requires, cope with our syntax
[vuplus_bitbake] / lib / bb / parse / parse_c / bitbakec.pyx
1 # ex:ts=4:sw=4:sts=4:et
2 # -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
3
4 cdef extern from "stdio.h":
5     ctypedef int FILE
6     FILE *fopen(char*, char*)
7     int fclose(FILE *fp)
8
9 cdef extern from "string.h":
10     int strlen(char*)
11
12 cdef extern from "lexerc.h":
13     ctypedef struct lex_t:
14         void* parser
15         void* scanner
16         FILE* file
17         void* data
18
19     int lineError
20     int errorParse
21
22     cdef extern void parse(FILE*, object)
23
24 def parsefile(object file, object data):
25     #print "parsefile: 1", file, data
26
27     # Open the file
28     cdef FILE* f
29
30     f = fopen(file, "r")
31     #print "parsefile: 2 opening file"
32     if (f == NULL):
33         raise IOError("No such file %s." % file)
34
35     #print "parsefile: 3 parse"
36     parse(f, data)
37
38     # Close the file
39     #print "parsefile: 4 closing"
40     fclose(f)
41
42
43 cdef public void e_assign(lex_t* container, char* key, char* what):
44     #print "e_assign", key, what
45     d = <object>container.data
46     d.setVar(key, what)
47
48 cdef public void e_export(lex_t* c, char* what):
49     #print "e_export", what
50     #exp:
51     # bb.data.setVarFlag(key, "export", 1, data)
52     d = <object>c.data
53     d.setVarFlag(what, "export", 1)
54
55 cdef public void e_immediate(lex_t* c, char* key, char* what):
56     #print "e_immediate", key, what
57     #colon:
58     # val = bb.data.expand(groupd["value"], data)
59     d = <object>c.data
60     d.setVar(key, d.expand(what,None))
61
62 cdef public void e_cond(lex_t* c, char* key, char* what):
63     #print "e_cond", key, what
64     #ques:
65     # val = bb.data.getVar(key, data)
66     # if val == None:    
67     #    val = groupd["value"]
68     d = <object>c.data
69     d.setVar(key, (d.getVar(key,0) or what))
70
71 cdef public void e_prepend(lex_t* c, char* key, char* what):
72     #print "e_prepend", key, what
73     #prepend:
74     # val = "%s %s" % (groupd["value"], (bb.data.getVar(key, data) or ""))
75     d = <object>c.data
76     d.setVar(key, what + " " + (d.getVar(key,0) or ""))
77
78 cdef public void e_append(lex_t* c, char* key, char* what):
79     #print "e_append", key, what
80     #append:
81     # val = "%s %s" % ((bb.data.getVar(key, data) or ""), groupd["value"])
82     d = <object>c.data
83     d.setVar(key, (d.getVar(key,0) or "") + " " + what)
84
85 cdef public void e_precat(lex_t* c, char* key, char* what):
86     #print "e_precat", key, what
87     #predot:
88     # val = "%s%s" % (groupd["value"], (bb.data.getVar(key, data) or ""))
89     d = <object>c.data
90     d.setVar(key, what + (d.getVar(key,0) or ""))
91
92 cdef public void e_postcat(lex_t* c, char* key, char* what):
93     #print "e_postcat", key, what
94     #postdot:
95     # val = "%s%s" % ((bb.data.getVar(key, data) or ""), groupd["value"])
96     d = <object>c.data
97     d.setVar(key, (d.getVar(key,0) or "") + what)
98
99 cdef public void e_addtask(lex_t* c, char* name, char* before, char* after):
100     #print "e_addtask", name
101     # func = m.group("func")
102     # before = m.group("before")
103     # after = m.group("after")
104     # if func is None:
105     #     return
106     # var = "do_" + func
107     #
108     # data.setVarFlag(var, "task", 1, d)
109     #
110     # if after is not None:
111     # #  set up deps for function
112     #     data.setVarFlag(var, "deps", after.split(), d)
113     # if before is not None:
114     # #   set up things that depend on this func
115     #     data.setVarFlag(var, "postdeps", before.split(), d)
116     # return
117
118     do = "do_%s" % name
119     d = <object>c.data
120     d.setVarFlag(do, "task", 1)
121
122     if before != NULL and strlen(before) > 0:
123         #print "Before", before
124         d.setVarFlag(do, "postdeps", ("%s" % before).split())
125     if after  != NULL and strlen(after) > 0:
126         #print "After", after
127         d.setVarFlag(do, "deps", ("%s" % after).split())
128
129
130 cdef public void e_addhandler(lex_t* c, char* h):
131     #print "e_addhandler", h
132     # data.setVarFlag(h, "handler", 1, d)
133     d = <object>c.data
134     d.setVarFlag(h, "handler", 1)
135
136 cdef public void e_export_func(lex_t* c, char* function):
137     #print "e_export_func", function
138     pass
139
140 cdef public void e_inherit(lex_t* c, char* file):
141     #print "e_inherit", file
142     pass
143
144 cdef public void e_include(lex_t* c, char* file):
145     from bb.parse import handle
146     d = <object>c.data
147
148     try:
149         handle(d.expand(file,d), d, True)
150     except IOError:
151         print "Could not include file", file
152
153
154 cdef public void e_require(lex_t* c, char* file):
155     #print "e_require", file
156     from bb.parse import handle
157     d = <object>c.data
158
159     try:
160         handle(d.expand(file,d), d, True)
161     except IOError:
162         print "ParseError", file
163         from bb.parse import ParseError
164         raise ParseError("Could not include required file %s" % file)
165
166 cdef public void e_proc(lex_t* c, char* key, char* what):
167     #print "e_proc", key, what
168     pass
169
170 cdef public void e_proc_python(lex_t* c, char* key, char* what):
171     #print "e_proc_python"
172     if key != NULL:
173         pass
174         #print "Key", key
175     if what != NULL:
176         pass
177         #print "What", what
178     pass
179
180 cdef public void e_proc_fakeroot(lex_t* c, char* key, char* what):
181     #print "e_fakeroot", key, what
182     pass
183
184 cdef public void e_def(lex_t* c, char* a, char* b, char* d):
185     #print "e_def", a, b, d
186     pass
187
188 cdef public void e_parse_error(lex_t* c):
189     print "e_parse_error", "line:", lineError, "parse:", errorParse
190
191
192     from bb.parse import ParseError
193     raise ParseError("There was an parse error, sorry unable to give more information at the current time.")
194