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 = []
|
|
|
|
|
2015-07-31 18:16:46 +00:00
|
|
|
import errno
|
|
|
|
import logging
|
2010-06-10 17:35:31 +00:00
|
|
|
import os
|
2011-01-03 19:57:19 +00:00
|
|
|
import stat
|
2010-06-10 17:35:31 +00:00
|
|
|
import bb
|
2010-04-10 00:11:03 +00:00
|
|
|
import bb.utils
|
2010-08-31 13:49:43 +00:00
|
|
|
import bb.siggen
|
2011-01-01 23:55:54 +00:00
|
|
|
|
2010-06-10 17:35:31 +00:00
|
|
|
logger = logging.getLogger("BitBake.Parsing")
|
2006-02-10 10:11:32 +00:00
|
|
|
|
2005-08-31 10:47:56 +00:00
|
|
|
class ParseError(Exception):
|
|
|
|
"""Exception raised when parsing fails"""
|
2012-02-23 17:38:08 +00:00
|
|
|
def __init__(self, msg, filename, lineno=0):
|
|
|
|
self.msg = msg
|
|
|
|
self.filename = filename
|
|
|
|
self.lineno = lineno
|
|
|
|
Exception.__init__(self, msg, filename, lineno)
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
if self.lineno:
|
|
|
|
return "ParseError at %s:%d: %s" % (self.filename, self.lineno, self.msg)
|
|
|
|
else:
|
|
|
|
return "ParseError in %s: %s" % (self.filename, self.msg)
|
2005-08-31 10:47:56 +00:00
|
|
|
|
2014-05-30 14:55:37 +00:00
|
|
|
class SkipRecipe(Exception):
|
|
|
|
"""Exception raised to skip this recipe"""
|
|
|
|
|
|
|
|
class SkipPackage(SkipRecipe):
|
|
|
|
"""Exception raised to skip this recipe (use SkipRecipe in new code)"""
|
2005-08-31 10:47:56 +00:00
|
|
|
|
|
|
|
__mtime_cache = {}
|
|
|
|
def cached_mtime(f):
|
2010-04-12 00:03:55 +00:00
|
|
|
if f not in __mtime_cache:
|
2011-01-03 19:57:19 +00:00
|
|
|
__mtime_cache[f] = os.stat(f)[stat.ST_MTIME]
|
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:
|
2011-01-03 19:57:19 +00:00
|
|
|
__mtime_cache[f] = os.stat(f)[stat.ST_MTIME]
|
2006-11-16 15:02:15 +00:00
|
|
|
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):
|
2015-08-17 11:12:28 +00:00
|
|
|
try:
|
|
|
|
__mtime_cache[f] = os.stat(f)[stat.ST_MTIME]
|
|
|
|
except OSError:
|
|
|
|
if f in __mtime_cache:
|
|
|
|
del __mtime_cache[f]
|
|
|
|
return 0
|
2008-09-16 19:14:49 +00:00
|
|
|
return __mtime_cache[f]
|
|
|
|
|
bitbake: cooker/cache/parse: Implement pyinofity based reconfigure
Memory resident bitbake has one current flaw, changes in the base configuration
are not noticed by bitbake. The parsing cache is also refreshed on each invocation
of bitbake (although the mtime cache is not cleared so its pointless).
This change adds in pyinotify support and adds two different watchers, one
for the base configuration and one for the parsed recipes.
Changes in the latter will trigger a reparse (and an update of the mtime cache).
The former will trigger a complete reload of the configuration.
Note that this code will also correctly handle creation of new configuration files
since the __depends and __base_depends variables already track these for cache
correctness purposes.
We could be a little more clever about parsing cache invalidation, right now we just
invalidate the whole thing and recheck. For now, its better than what we have and doesn't
seem to perform that badly though.
For education and QA purposes I can document a workflow that illustrates this:
$ source oe-init-build-env-memres
$ time bitbake bash
[base configuration is loaded, recipes are parsed, bash builds]
$ time bitbake bash
[command returns quickly since all caches are valid]
$ touch ../meta/classes/gettext.bbclass
$ time bitbake bash
[reparse is triggered, time is longer than above]
$ echo 'FOO = "1"' >> conf/local.conf
$ time bitbake bash
[reparse is triggered, but with a base configuration reload too]
As far as changes go, I like this one a lot, it makes memory resident bitbake
truly usable and may be the tweak we need to make it the default.
The new pyinotify dependency is covered in the previous commit.
(Bitbake rev: 0557d03c170fba8d7efe82be1b9641d0eb229213)
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2015-01-13 14:13:53 +00:00
|
|
|
def update_cache(f):
|
|
|
|
if f in __mtime_cache:
|
|
|
|
logger.debug(1, "Updating mtime cache for %s" % f)
|
|
|
|
update_mtime(f)
|
|
|
|
|
2005-08-31 10:47:56 +00:00
|
|
|
def mark_dependency(d, f):
|
|
|
|
if f.startswith('./'):
|
|
|
|
f = "%s/%s" % (os.getcwd(), f[2:])
|
2015-06-18 14:14:19 +00:00
|
|
|
deps = (d.getVar('__depends', False) or [])
|
2013-11-29 23:15:56 +00:00
|
|
|
s = (f, cached_mtime_noerror(f))
|
|
|
|
if s not in deps:
|
|
|
|
deps.append(s)
|
|
|
|
d.setVar('__depends', deps)
|
|
|
|
|
|
|
|
def check_dependency(d, f):
|
|
|
|
s = (f, cached_mtime_noerror(f))
|
2015-06-18 14:14:19 +00:00
|
|
|
deps = (d.getVar('__depends', False) or [])
|
2013-11-29 23:15:56 +00:00
|
|
|
return s in deps
|
|
|
|
|
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):
|
2013-01-18 11:45:22 +00:00
|
|
|
with data.inchistory.include(fn):
|
|
|
|
return h['handle'](fn, data, include)
|
2012-02-23 17:38:08 +00:00
|
|
|
raise ParseError("not a BitBake file", fn)
|
2005-08-31 10:47:56 +00:00
|
|
|
|
|
|
|
def init(fn, data):
|
|
|
|
for h in handlers:
|
|
|
|
if h['supports'](fn):
|
|
|
|
return h['init'](data)
|
|
|
|
|
2011-01-01 23:55:54 +00:00
|
|
|
def init_parser(d):
|
|
|
|
bb.parse.siggen = bb.siggen.init(d)
|
2010-08-31 13:49:43 +00:00
|
|
|
|
2009-05-17 04:19:39 +00:00
|
|
|
def resolve_file(fn, d):
|
|
|
|
if not os.path.isabs(fn):
|
2016-11-25 15:28:08 +00:00
|
|
|
bbpath = d.getVar("BBPATH")
|
2013-11-29 23:15:56 +00:00
|
|
|
newfn, attempts = bb.utils.which(bbpath, fn, history=True)
|
|
|
|
for af in attempts:
|
|
|
|
mark_dependency(d, af)
|
2010-06-04 20:10:00 +00:00
|
|
|
if not newfn:
|
2015-07-31 18:16:46 +00:00
|
|
|
raise IOError(errno.ENOENT, "file %s not found in %s" % (fn, bbpath))
|
2010-06-04 20:10:00 +00:00
|
|
|
fn = newfn
|
2009-05-19 11:59:50 +00:00
|
|
|
|
2013-11-29 23:15:56 +00:00
|
|
|
mark_dependency(d, fn)
|
2013-08-23 17:06:26 +00:00
|
|
|
if not os.path.isfile(fn):
|
2015-07-31 18:16:46 +00:00
|
|
|
raise IOError(errno.ENOENT, "file %s not found" % fn)
|
2013-08-23 17:06:26 +00:00
|
|
|
|
2009-05-19 11:59:50 +00:00
|
|
|
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):
|
2014-02-17 14:07:40 +00:00
|
|
|
if not mypkg or not mypkg.endswith((".bb", ".bbappend")):
|
2009-07-21 23:22:30 +00:00
|
|
|
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:
|
2012-02-23 17:38:08 +00:00
|
|
|
raise ParseError("Unable to generate default variables from filename (too many underscores)", mypkg)
|
2009-07-21 23:22:30 +00:00
|
|
|
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
|
|
|
|
2012-02-28 03:22:40 +00:00
|
|
|
def get_file_depends(d):
|
|
|
|
'''Return the dependent files'''
|
|
|
|
dep_files = []
|
2015-11-10 09:55:49 +00:00
|
|
|
depends = d.getVar('__base_depends', False) or []
|
|
|
|
depends = depends + (d.getVar('__depends', False) or [])
|
2012-02-28 03:22:40 +00:00
|
|
|
for (fn, _) in depends:
|
|
|
|
dep_files.append(os.path.abspath(fn))
|
|
|
|
return " ".join(dep_files)
|
|
|
|
|
2009-07-22 18:09:25 +00:00
|
|
|
from bb.parse.parse_py import __version__, ConfHandler, BBHandler
|