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__.py164
1 files changed, 164 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..25effc2200
--- /dev/null
+++ b/bitbake/lib/bb/parse/__init__.py
@@ -0,0 +1,164 @@
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 SkipRecipe(Exception):
53 """Exception raised to skip this recipe"""
54
55class SkipPackage(SkipRecipe):
56 """Exception raised to skip this recipe (use SkipRecipe in new code)"""
57
58__mtime_cache = {}
59def cached_mtime(f):
60 if f not in __mtime_cache:
61 __mtime_cache[f] = os.stat(f)[stat.ST_MTIME]
62 return __mtime_cache[f]
63
64def cached_mtime_noerror(f):
65 if f not in __mtime_cache:
66 try:
67 __mtime_cache[f] = os.stat(f)[stat.ST_MTIME]
68 except OSError:
69 return 0
70 return __mtime_cache[f]
71
72def update_mtime(f):
73 __mtime_cache[f] = os.stat(f)[stat.ST_MTIME]
74 return __mtime_cache[f]
75
76def update_cache(f):
77 if f in __mtime_cache:
78 logger.debug(1, "Updating mtime cache for %s" % f)
79 update_mtime(f)
80
81def mark_dependency(d, f):
82 if f.startswith('./'):
83 f = "%s/%s" % (os.getcwd(), f[2:])
84 deps = (d.getVar('__depends') or [])
85 s = (f, cached_mtime_noerror(f))
86 if s not in deps:
87 deps.append(s)
88 d.setVar('__depends', deps)
89
90def check_dependency(d, f):
91 s = (f, cached_mtime_noerror(f))
92 deps = (d.getVar('__depends') or [])
93 return s in deps
94
95def supports(fn, data):
96 """Returns true if we have a handler for this file, false otherwise"""
97 for h in handlers:
98 if h['supports'](fn, data):
99 return 1
100 return 0
101
102def handle(fn, data, include = 0):
103 """Call the handler that is appropriate for this file"""
104 for h in handlers:
105 if h['supports'](fn, data):
106 with data.inchistory.include(fn):
107 return h['handle'](fn, data, include)
108 raise ParseError("not a BitBake file", fn)
109
110def init(fn, data):
111 for h in handlers:
112 if h['supports'](fn):
113 return h['init'](data)
114
115def init_parser(d):
116 bb.parse.siggen = bb.siggen.init(d)
117
118def resolve_file(fn, d):
119 if not os.path.isabs(fn):
120 bbpath = d.getVar("BBPATH", True)
121 newfn, attempts = bb.utils.which(bbpath, fn, history=True)
122 for af in attempts:
123 mark_dependency(d, af)
124 if not newfn:
125 raise IOError("file %s not found in %s" % (fn, bbpath))
126 fn = newfn
127
128 mark_dependency(d, fn)
129 if not os.path.isfile(fn):
130 raise IOError("file %s not found" % fn)
131
132 return fn
133
134# Used by OpenEmbedded metadata
135__pkgsplit_cache__={}
136def vars_from_file(mypkg, d):
137 if not mypkg or not mypkg.endswith((".bb", ".bbappend")):
138 return (None, None, None)
139 if mypkg in __pkgsplit_cache__:
140 return __pkgsplit_cache__[mypkg]
141
142 myfile = os.path.splitext(os.path.basename(mypkg))
143 parts = myfile[0].split('_')
144 __pkgsplit_cache__[mypkg] = parts
145 if len(parts) > 3:
146 raise ParseError("Unable to generate default variables from filename (too many underscores)", mypkg)
147 exp = 3 - len(parts)
148 tmplist = []
149 while exp != 0:
150 exp -= 1
151 tmplist.append(None)
152 parts.extend(tmplist)
153 return parts
154
155def get_file_depends(d):
156 '''Return the dependent files'''
157 dep_files = []
158 depends = d.getVar('__base_depends', True) or []
159 depends = depends + (d.getVar('__depends', True) or [])
160 for (fn, _) in depends:
161 dep_files.append(os.path.abspath(fn))
162 return " ".join(dep_files)
163
164from bb.parse.parse_py import __version__, ConfHandler, BBHandler