lib/bb/parse/parser_c: Handle includes, requires, cope with our syntax
[vuplus_bitbake] / lib / bb / parse / parse_c / BBHandler.py
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)
4
5     Reads a .bb file and obtains its metadata (using a C++ parser)
6
7     Copyright (C) 2006 Tim Robert Ansell
8         Copyright (C) 2006 Holger Hans Peter Freyther
9    
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
13     version.
14
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:
21
22         The above copyright notice and this permission notice shall be included in all
23         copies or substantial portions of the Software.
24
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.
32 """
33
34 import os
35
36 # The Module we will use here
37 import bb
38
39 from bitbakec import parsefile
40
41 #
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
46 # parser module
47 #
48 # The rest of the methods are internal implementation details.
49
50 def _init(fn, d):
51     """
52     Initialize the data implementation with values of
53     the environment and data from the file.
54     """
55     pass
56
57 #
58 # public
59 #
60 def supports(fn, data):
61     return fn[-3:] == ".bb" or fn[-8:] == ".bbclass" or fn[-4:] == ".inc" or fn[-5:] == ".conf"
62
63 def init(fn, data):
64     if not data.getVar('TOPDIR', False):
65         bb.error('TOPDIR is not set')
66     if not data.getVar('BBPATH', False):
67         bb.error('BBPATH is not set')
68
69
70 def handle(fn, d, include):
71     from bb import data, parse
72
73     #print ""
74     #print "fn: %s" % fn
75     #print "data: %s" % d
76     #print dir(d)
77     #print d.getVar.__doc__
78     print "include: %s" % fn
79
80     # check if we include or are the beginning
81     if include:
82         oldfile = d.getVar('FILE', False)
83     else:
84         if fn[-5:] == ".conf":
85             data.inheritFromOS(d)
86         oldfile = None
87
88     # find the file
89     if not os.path.isabs(fn):
90         abs_fn = bb.which(d.getVar('BBPATH', True), fn)
91     else:
92         abs_fn = fn
93
94     # check if the file exists
95     if not os.path.exists(abs_fn):
96         raise IOError("file '%(fn)s' not found" % locals() )
97
98     # now we know the file is around mark it as dep
99     if include:
100         parse.mark_dependency(d, abs_fn)
101
102     # now parse this file - by defering it to C++
103     parsefile(abs_fn, d)
104
105     # restore the original FILE
106     if oldfile:
107         d.setVar('FILE', oldfile)
108
109     return d
110
111 # Inform bitbake that we are a parser
112 # We need to define all three
113 from bb.parse import handlers
114 handlers.append( {'supports' : supports, 'handle': handle, 'init' : init})
115 del handlers