summaryrefslogtreecommitdiffstats
path: root/lib/bb/parse/parse_c/BBHandler.py
blob: 771a7a0d81f9aca9a8bc4c62d67977d1abfd1181 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# ex:ts=4:sw=4:sts=4:et
# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
#
# Copyright (C) 2006 Holger Hans Peter Freyther
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
# SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
# DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
# THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#

# The Module we will use here
from bb import data, parse
from bb.parse import ParseError
import bb

#
# This is the Python Part of the Native Parser Implementation.
# We will only parse .bbclass, .inc and .bb files but no
# configuration files.
# supports, init and handle are the public methods used by
# parser module
#
# The rest of the methods are internal implementation details.



#
# internal
#
def _init(fn, d):
    """
    Initialize the data implementation with values of
    the environment and data from the file.
    """
    pass

#
# public
#
def supports(fn, data):
    return fn[-3:] == ".bb" or fn[-8:] == ".bbclass" or fn[-4:] == ".inc"

def init(fn, data):
    if not bb.data.getVar('TOPDIR', data):
        bb.error('TOPDIR is not set')
    if not bb.data.getVar('BBPATH', data):
        bb.error('BBPATH is not set')


def handle(fn, d, include):
    print ""
    print "fn: %s" % fn
    print "data: %s" % data
    print "include: %s" % include

    # check if we include or are the beginning
    if include:
        oldfile = data.getVar('FILE', d)
    else:
        data.inheritFromOS(d)
        oldfile = None

    # find the file
    if not os.path.isabs(fn):
        bb.error("No Absolute FILE name")
        abs_fn = bb.which(data.getVar('BBPATH',d), fn)
    else:
        abs_fn = fn

    # check if the file exists
    if not os.path.exists(abs_fn):
        raise IOError("file '%(fn)' not found" % locals() )

    fn = file(abs_fn, 'r')

    # now we know the file is around mark it as dep
    if include:
        parse.mark_dependency(d, abs_fn)

    # now parse this file - by defering it to C++


    # restore the original FILE
    if oldfile:
        data.setVar('FILE', oldfile, data)

    return data

# Inform bitbake that we are a parser
# We need to define all three
from bb.parse import handlers
handlers.append( {'supports' : supports, 'handle': handle, 'init' : init})
del handlers