2005-08-31 10:47:56 +00:00
|
|
|
"""
|
|
|
|
BitBake Parsers
|
|
|
|
|
|
|
|
File parsers for the BitBake build tools.
|
|
|
|
|
2007-01-08 23:53:01 +00:00
|
|
|
"""
|
2005-08-31 10:47:56 +00:00
|
|
|
|
|
|
|
|
2007-01-08 23:53:01 +00:00
|
|
|
# Copyright (C) 2003, 2004 Chris Larson
|
|
|
|
# Copyright (C) 2003, 2004 Phil Blundell
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License version 2 as
|
|
|
|
# published by the Free Software Foundation.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License along
|
|
|
|
# with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
#
|
|
|
|
# Based on functions from the base bb module, Copyright 2003 Holger Schurig
|
2005-08-31 10:47:56 +00:00
|
|
|
|
|
|
|
handlers = []
|
|
|
|
|
2006-02-10 10:11:32 +00:00
|
|
|
import bb, os
|
2010-04-10 00:11:03 +00:00
|
|
|
import bb.utils
|
2006-02-10 10:11:32 +00:00
|
|
|
|
2005-08-31 10:47:56 +00:00
|
|
|
class ParseError(Exception):
|
|
|
|
"""Exception raised when parsing fails"""
|
|
|
|
|
|
|
|
class SkipPackage(Exception):
|
|
|
|
"""Exception raised to skip this package"""
|
|
|
|
|
|
|
|
__mtime_cache = {}
|
|
|
|
def cached_mtime(f):
|
2010-04-12 00:03:55 +00:00
|
|
|
if f not in __mtime_cache:
|
2006-11-16 15:02:15 +00:00
|
|
|
__mtime_cache[f] = os.stat(f)[8]
|
2005-08-31 10:47:56 +00:00
|
|
|
return __mtime_cache[f]
|
|
|
|
|
2006-11-16 15:02:15 +00:00
|
|
|
def cached_mtime_noerror(f):
|
2010-04-12 00:03:55 +00:00
|
|
|
if f not in __mtime_cache:
|
2006-11-16 15:02:15 +00:00
|
|
|
try:
|
|
|
|
__mtime_cache[f] = os.stat(f)[8]
|
|
|
|
except OSError:
|
|
|
|
return 0
|
|
|
|
return __mtime_cache[f]
|
2006-02-10 10:11:32 +00:00
|
|
|
|
2008-09-16 19:14:49 +00:00
|
|
|
def update_mtime(f):
|
|
|
|
__mtime_cache[f] = os.stat(f)[8]
|
|
|
|
return __mtime_cache[f]
|
|
|
|
|
2005-08-31 10:47:56 +00:00
|
|
|
def mark_dependency(d, f):
|
|
|
|
if f.startswith('./'):
|
|
|
|
f = "%s/%s" % (os.getcwd(), f[2:])
|
2006-05-09 15:44:08 +00:00
|
|
|
deps = bb.data.getVar('__depends', d) or []
|
|
|
|
deps.append( (f, cached_mtime(f)) )
|
|
|
|
bb.data.setVar('__depends', deps, d)
|
2005-08-31 10:47:56 +00:00
|
|
|
|
|
|
|
def supports(fn, data):
|
|
|
|
"""Returns true if we have a handler for this file, false otherwise"""
|
|
|
|
for h in handlers:
|
|
|
|
if h['supports'](fn, data):
|
|
|
|
return 1
|
|
|
|
return 0
|
|
|
|
|
2009-05-19 10:10:37 +00:00
|
|
|
def handle(fn, data, include = 0):
|
2005-08-31 10:47:56 +00:00
|
|
|
"""Call the handler that is appropriate for this file"""
|
|
|
|
for h in handlers:
|
|
|
|
if h['supports'](fn, data):
|
2009-05-19 10:10:37 +00:00
|
|
|
return h['handle'](fn, data, include)
|
2005-08-31 10:47:56 +00:00
|
|
|
raise ParseError("%s is not a BitBake file" % fn)
|
|
|
|
|
|
|
|
def init(fn, data):
|
|
|
|
for h in handlers:
|
|
|
|
if h['supports'](fn):
|
|
|
|
return h['init'](data)
|
|
|
|
|
2009-05-17 04:19:39 +00:00
|
|
|
def resolve_file(fn, d):
|
|
|
|
if not os.path.isabs(fn):
|
2010-06-04 20:10:00 +00:00
|
|
|
bbpath = bb.data.getVar("BBPATH", d, True)
|
|
|
|
newfn = bb.which(bbpath, fn)
|
|
|
|
if not newfn:
|
|
|
|
raise IOError("file %s not found in %s" % (fn, bbpath))
|
|
|
|
fn = newfn
|
2009-05-19 11:59:50 +00:00
|
|
|
|
|
|
|
bb.msg.debug(2, bb.msg.domain.Parsing, "LOAD %s" % fn)
|
|
|
|
return fn
|
2009-05-17 04:19:39 +00:00
|
|
|
|
2009-07-21 23:22:30 +00:00
|
|
|
# Used by OpenEmbedded metadata
|
|
|
|
__pkgsplit_cache__={}
|
|
|
|
def vars_from_file(mypkg, d):
|
|
|
|
if not mypkg:
|
|
|
|
return (None, None, None)
|
|
|
|
if mypkg in __pkgsplit_cache__:
|
|
|
|
return __pkgsplit_cache__[mypkg]
|
|
|
|
|
|
|
|
myfile = os.path.splitext(os.path.basename(mypkg))
|
|
|
|
parts = myfile[0].split('_')
|
|
|
|
__pkgsplit_cache__[mypkg] = parts
|
|
|
|
if len(parts) > 3:
|
|
|
|
raise ParseError("Unable to generate default variables from the filename: %s (too many underscores)" % mypkg)
|
|
|
|
exp = 3 - len(parts)
|
|
|
|
tmplist = []
|
|
|
|
while exp != 0:
|
|
|
|
exp -= 1
|
|
|
|
tmplist.append(None)
|
|
|
|
parts.extend(tmplist)
|
|
|
|
return parts
|
2005-08-31 10:47:56 +00:00
|
|
|
|
2009-07-22 18:09:25 +00:00
|
|
|
from bb.parse.parse_py import __version__, ConfHandler, BBHandler
|