summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/bb/parse/__init__.py
diff options
context:
space:
mode:
Diffstat (limited to 'bitbake/lib/bb/parse/__init__.py')
-rw-r--r--bitbake/lib/bb/parse/__init__.py157
1 files changed, 157 insertions, 0 deletions
diff --git a/bitbake/lib/bb/parse/__init__.py b/bitbake/lib/bb/parse/__init__.py
new file mode 100644
index 0000000000..e4a44dda11
--- /dev/null
+++ b/bitbake/lib/bb/parse/__init__.py
@@ -0,0 +1,157 @@
1"""
2BitBake Parsers
3
4File parsers for the BitBake build tools.
5
6"""
7
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
13# it under the terms of the GNU General Public License version 2 as
14# published by the Free Software Foundation.
15#
16# This program is distributed in the hope that it will be useful,
17# but WITHOUT ANY WARRANTY; without even the implied warranty of
18# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19# GNU General Public License for more details.
20#
21# You should have received a copy of the GNU General Public License along
22# with this program; if not, write to the Free Software Foundation, Inc.,
23# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24#
25# Based on functions from the base bb module, Copyright 2003 Holger Schurig
26
27handlers = []
28
29import os
30import stat
31import logging
32import bb
33import bb.utils
34import bb.siggen
35
36logger = logging.getLogger("BitBake.Parsing")
37
38class ParseError(Exception):
39 """Exception raised when parsing fails"""
40 def __init__(self, msg, filename, lineno=0):
41 self.msg = msg
42 self.filename = filename
43 self.lineno = lineno
44 Exception.__init__(self, msg, filename, lineno)
45
46 def __str__(self):
47 if self.lineno:
48 return "ParseError at %s:%d: %s" % (self.filename, self.lineno, self.msg)
49 else:
50 return "ParseError in %s: %s" % (self.filename, self.msg)
51
52class SkipPackage(Exception):
53 """Exception raised to skip this package"""
54
55__mtime_cache = {}
56def cached_mtime(f):
57 if f not in __mtime_cache:
58 __mtime_cache[f] = os.stat(f)[stat.ST_MTIME]
59 return __mtime_cache[f]
60
61def cached_mtime_noerror(f):
62 if f not in __mtime_cache:
63 try:
64 __mtime_cache[f] = os.stat(f)[stat.ST_MTIME]
65 except OSError:
66 return 0
67 return __mtime_cache[f]
68
69def update_mtime(f):
70 __mtime_cache[f] = os.stat(f)[stat.ST_MTIME]
71 return __mtime_cache[f]
72
73def mark_dependency(d, f):
74 if f.startswith('./'):
75 f = "%s/%s" % (os.getcwd(), f[2:])
76 deps = (d.getVar('__depends') or [])
77 s = (f, cached_mtime_noerror(f))
78 if s not in deps:
79 deps.append(s)
80 d.setVar('__depends', deps)
81
82def check_dependency(d, f):
83 s = (f, cached_mtime_noerror(f))
84 deps = (d.getVar('__depends') or [])
85 return s in deps
86
87def supports(fn, data):
88 """Returns true if we have a handler for this file, false otherwise"""
89 for h in handlers:
90 if h['supports'](fn, data):
91 return 1
92 return 0
93
94def handle(fn, data, include = 0):
95 """Call the handler that is appropriate for this file"""
96 for h in handlers:
97 if h['supports'](fn, data):
98 with data.inchistory.include(fn):
99 return h['handle'](fn, data, include)
100 raise ParseError("not a BitBake file", fn)
101
102def init(fn, data):
103 for h in handlers:
104 if h['supports'](fn):
105 return h['init'](data)
106
107def init_parser(d):
108 bb.parse.siggen = bb.siggen.init(d)
109
110def resolve_file(fn, d):
111 if not os.path.isabs(fn):
112 bbpath = d.getVar("BBPATH", True)
113 newfn, attempts = bb.utils.which(bbpath, fn, history=True)
114 for af in attempts:
115 mark_dependency(d, af)
116 if not newfn:
117 raise IOError("file %s not found in %s" % (fn, bbpath))
118 fn = newfn
119
120 mark_dependency(d, fn)
121 if not os.path.isfile(fn):
122 raise IOError("file %s not found" % fn)
123
124 logger.debug(2, "LOAD %s", fn)
125 return fn
126
127# Used by OpenEmbedded metadata
128__pkgsplit_cache__={}
129def vars_from_file(mypkg, d):
130 if not mypkg or not mypkg.endswith((".bb", ".bbappend")):
131 return (None, None, None)
132 if mypkg in __pkgsplit_cache__:
133 return __pkgsplit_cache__[mypkg]
134
135 myfile = os.path.splitext(os.path.basename(mypkg))
136 parts = myfile[0].split('_')
137 __pkgsplit_cache__[mypkg] = parts
138 if len(parts) > 3:
139 raise ParseError("Unable to generate default variables from filename (too many underscores)", mypkg)
140 exp = 3 - len(parts)
141 tmplist = []
142 while exp != 0:
143 exp -= 1
144 tmplist.append(None)
145 parts.extend(tmplist)
146 return parts
147
148def get_file_depends(d):
149 '''Return the dependent files'''
150 dep_files = []
151 depends = d.getVar('__base_depends', True) or []
152 depends = depends + (d.getVar('__depends', True) or [])
153 for (fn, _) in depends:
154 dep_files.append(os.path.abspath(fn))
155 return " ".join(dep_files)
156
157from bb.parse.parse_py import __version__, ConfHandler, BBHandler