2005-08-31 10:47:56 +00:00
#!/usr/bin/env python
# ex:ts=4:sw=4:sts=4:et
# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
2007-01-08 23:53:01 +00:00
"""
class for handling . bb files
2005-08-31 10:47:56 +00:00
Reads a . bb file and obtains its metadata
2007-01-08 23:53:01 +00:00
"""
# Copyright (C) 2003, 2004 Chris Larson
# Copyright (C) 2003, 2004 Phil Blundell
2010-03-24 23:56:12 +00:00
#
2007-01-08 23:53:01 +00:00
# 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.
2005-08-31 10:47:56 +00:00
2010-06-20 19:07:34 +00:00
from __future__ import absolute_import
2010-04-08 17:22:29 +00:00
import re , bb , os
2010-06-10 17:35:31 +00:00
import logging
2011-01-08 02:26:28 +00:00
import bb . build , bb . utils
2010-04-08 17:22:29 +00:00
from bb import data
2005-08-31 10:47:56 +00:00
2010-06-20 19:07:34 +00:00
from . import ConfHandler
2010-06-10 17:35:31 +00:00
from . . import resolve_file , ast , logger
2010-06-20 19:07:34 +00:00
from . ConfHandler import include , init
2005-08-31 10:47:56 +00:00
2009-07-21 23:22:30 +00:00
# For compatibility
2010-04-09 23:51:09 +00:00
bb . deprecate_import ( __name__ , " bb.parse " , [ " vars_from_file " ] )
2009-07-21 23:22:30 +00:00
2005-08-31 10:47:56 +00:00
__func_start_regexp__ = re . compile ( r " (((?P<py>python)|(?P<fr>fakeroot)) \ s*)*(?P<func>[ \ w \ . \ - \ + \ { \ } \ $]+)? \ s* \ ( \ s* \ ) \ s* { $ " )
__inherit_regexp__ = re . compile ( r " inherit \ s+(.+) " )
__export_func_regexp__ = re . compile ( r " EXPORT_FUNCTIONS \ s+(.+) " )
__addtask_regexp__ = re . compile ( " addtask \ s+(?P<func> \ w+) \ s*((before \ s*(?P<before>((.*(?=after))|(.*))))|(after \ s*(?P<after>((.*(?=before))|(.*)))))* " )
__addhandler_regexp__ = re . compile ( r " addhandler \ s+(.+) " )
__def_regexp__ = re . compile ( r " def \ s+( \ w+).*: " )
__python_func_regexp__ = re . compile ( r " ( \ s+.*)|(^$) " )
2010-02-12 14:14:49 +00:00
2005-08-31 10:47:56 +00:00
__infunc__ = " "
__inpython__ = False
__body__ = [ ]
__classname__ = " "
classes = [ None , ]
2009-05-19 11:53:12 +00:00
cached_statements = { }
2006-11-16 15:02:15 +00:00
# We need to indicate EOF to the feeder. This code is so messy that
# factoring it out to a close_parse_file method is out of question.
# We will use the IN_PYTHON_EOF as an indicator to just close the method
#
# The two parts using it are tightly integrated anyway
IN_PYTHON_EOF = - 9999999999999
2006-05-09 15:44:08 +00:00
2009-05-17 11:00:42 +00:00
2005-08-31 10:47:56 +00:00
def supports ( fn , d ) :
2010-11-14 12:08:03 +00:00
""" Return True if fn has a supported extension """
return os . path . splitext ( fn ) [ - 1 ] in [ " .bb " , " .bbclass " , " .inc " ]
2005-08-31 10:47:56 +00:00
2009-05-19 10:10:37 +00:00
def inherit ( files , d ) :
2006-11-29 22:52:37 +00:00
__inherit_cache = data . getVar ( ' __inherit_cache ' , d ) or [ ]
2005-08-31 10:47:56 +00:00
fn = " "
lineno = 0
2006-11-29 22:52:37 +00:00
for file in files :
2010-04-20 18:53:31 +00:00
file = data . expand ( file , d )
2010-11-15 15:27:27 +00:00
if not os . path . isabs ( file ) and not file . endswith ( " .bbclass " ) :
2005-08-31 10:47:56 +00:00
file = os . path . join ( ' classes ' , ' %s .bbclass ' % file )
2006-11-29 22:52:37 +00:00
if not file in __inherit_cache :
2010-06-10 17:35:31 +00:00
logger . log ( logging . DEBUG - 1 , " BB %s : %d : inheriting %s " , fn , lineno , file )
2006-11-29 22:52:37 +00:00
__inherit_cache . append ( file )
2007-05-22 11:50:37 +00:00
data . setVar ( ' __inherit_cache ' , __inherit_cache , d )
2009-05-19 10:10:37 +00:00
include ( fn , file , d , " inherit " )
2007-05-22 11:50:37 +00:00
__inherit_cache = data . getVar ( ' __inherit_cache ' , d ) or [ ]
2005-08-31 10:47:56 +00:00
2010-06-09 16:06:57 +00:00
def get_statements ( filename , absolute_filename , base_name ) :
2009-05-19 11:53:12 +00:00
global cached_statements
try :
2010-06-09 16:06:57 +00:00
return cached_statements [ absolute_filename ]
2009-05-19 11:53:12 +00:00
except KeyError :
2010-06-09 16:06:57 +00:00
file = open ( absolute_filename , ' r ' )
2009-05-19 11:53:12 +00:00
statements = ast . StatementGroup ( )
lineno = 0
2010-04-12 00:03:55 +00:00
while True :
2009-05-19 11:53:12 +00:00
lineno = lineno + 1
s = file . readline ( )
if not s : break
s = s . rstrip ( )
feeder ( lineno , s , filename , base_name , statements )
if __inpython__ :
# add a blank line to close out any python definition
feeder ( IN_PYTHON_EOF , " " , filename , base_name , statements )
if filename . endswith ( " .bbclass " ) or filename . endswith ( " .inc " ) :
2010-06-09 16:06:57 +00:00
cached_statements [ absolute_filename ] = statements
2009-05-19 11:53:12 +00:00
return statements
2009-05-19 11:22:30 +00:00
2009-05-19 10:10:37 +00:00
def handle ( fn , d , include ) :
2006-11-29 22:52:37 +00:00
global __func_start_regexp__ , __inherit_regexp__ , __export_func_regexp__ , __addtask_regexp__ , __addhandler_regexp__ , __infunc__ , __body__ , __residue__
2005-08-31 10:47:56 +00:00
__body__ = [ ]
__infunc__ = " "
__classname__ = " "
__residue__ = [ ]
2009-05-18 17:24:07 +00:00
2005-08-31 10:47:56 +00:00
if include == 0 :
2010-06-10 17:35:31 +00:00
logger . debug ( 2 , " BB %s : handle(data) " , fn )
2005-08-31 10:47:56 +00:00
else :
2010-06-10 17:35:31 +00:00
logger . debug ( 2 , " BB %s : handle(data, include) " , fn )
2005-08-31 10:47:56 +00:00
2011-01-03 19:57:21 +00:00
base_name = os . path . basename ( fn )
( root , ext ) = os . path . splitext ( base_name )
2005-08-31 10:47:56 +00:00
init ( d )
if ext == " .bbclass " :
2008-06-12 10:37:02 +00:00
__classname__ = root
2005-08-31 10:47:56 +00:00
classes . append ( __classname__ )
2008-03-03 22:01:45 +00:00
__inherit_cache = data . getVar ( ' __inherit_cache ' , d ) or [ ]
if not fn in __inherit_cache :
__inherit_cache . append ( fn )
data . setVar ( ' __inherit_cache ' , __inherit_cache , d )
2005-08-31 10:47:56 +00:00
if include != 0 :
oldfile = data . getVar ( ' FILE ' , d )
else :
oldfile = None
2009-05-19 11:59:50 +00:00
abs_fn = resolve_file ( fn , d )
2005-08-31 10:47:56 +00:00
if include :
bb . parse . mark_dependency ( d , abs_fn )
2009-05-19 11:22:30 +00:00
# actual loading
2009-05-19 11:59:50 +00:00
statements = get_statements ( fn , abs_fn , base_name )
2009-05-19 10:10:37 +00:00
# DONE WITH PARSING... time to evaluate
if ext != " .bbclass " :
2011-11-18 14:21:15 +00:00
data . setVar ( ' FILE ' , abs_fn , d )
2009-05-19 10:10:37 +00:00
statements . eval ( d )
2005-08-31 10:47:56 +00:00
if ext == " .bbclass " :
classes . remove ( __classname__ )
else :
if include == 0 :
Implement BBVERSIONS
This implements a feature similar to BBCLASSEXTEND, but for generating
multiple versions of a given recipe. For example: BBVERSIONS = "1.0 2.0 git".
In addition to the above, one can utilize [a-b] style patterns, and can have a
:<basever> postfix, which allows you to essentially name the range of
versions. Both the current version and the basever end up in OVERRIDES, and
the basever gets placed into the BPV variable. The default BPV, if none is
specified, is the original PV of the recipe, before bbversions processing.
In this way, you can do things like:
BBVERSIONS = "1.0.[0-6]:1.0.0+
1.0.[7-9]:1.0.7+"
SRC_URI_append_1.0.7+ = "file://some_extra_patch.patch;patch=1"
Or you can create a recipe per range, and name the recipe file as such: nano_1.0.7+.bb.
(Bitbake rev: 4ee9a56e16f1eb3c1649eaa3127b09ab0e93d1ec)
Signed-off-by: Chris Larson <chris_larson@mentor.com>
Signed-off-by: Richard Purdie <rpurdie@linux.intel.com>
2010-03-20 00:22:19 +00:00
return ast . multi_finalize ( fn , d )
2005-08-31 10:47:56 +00:00
if oldfile :
2011-11-25 14:57:53 +00:00
d . setVar ( " FILE " , oldfile )
2006-05-09 15:44:08 +00:00
# we have parsed the bb class now
if ext == " .bbclass " or ext == " .inc " :
2010-02-12 14:14:49 +00:00
bb . methodpool . get_parsed_dict ( ) [ base_name ] = 1
2006-05-09 15:44:08 +00:00
2005-08-31 10:47:56 +00:00
return d
2009-05-19 10:10:37 +00:00
def feeder ( lineno , s , fn , root , statements ) :
2010-04-12 00:03:55 +00:00
global __func_start_regexp__ , __inherit_regexp__ , __export_func_regexp__ , __addtask_regexp__ , __addhandler_regexp__ , __def_regexp__ , __python_func_regexp__ , __inpython__ , __infunc__ , __body__ , classes , bb , __residue__
2005-08-31 10:47:56 +00:00
if __infunc__ :
if s == ' } ' :
__body__ . append ( ' ' )
2011-01-04 20:34:08 +00:00
ast . handleMethod ( statements , fn , lineno , __infunc__ , __body__ )
2005-08-31 10:47:56 +00:00
__infunc__ = " "
__body__ = [ ]
else :
__body__ . append ( s )
return
if __inpython__ :
m = __python_func_regexp__ . match ( s )
2006-11-16 15:02:15 +00:00
if m and lineno != IN_PYTHON_EOF :
2005-08-31 10:47:56 +00:00
__body__ . append ( s )
return
else :
2011-01-04 20:34:08 +00:00
ast . handlePythonMethod ( statements , fn , lineno , __inpython__ ,
root , __body__ )
2005-08-31 10:47:56 +00:00
__body__ = [ ]
__inpython__ = False
2006-05-09 15:44:08 +00:00
2006-11-16 15:02:15 +00:00
if lineno == IN_PYTHON_EOF :
return
2011-08-30 16:46:46 +00:00
if s and s [ 0 ] == ' # ' :
2011-02-22 21:45:26 +00:00
if len ( __residue__ ) != 0 and __residue__ [ 0 ] [ 0 ] != " # " :
bb . error ( " There is a comment on line %s of file %s ( %s ) which is in the middle of a multiline expression. \n Bitbake used to ignore these but no longer does so, please fix your metadata as errors are likely as a result of this change. " % ( lineno , fn , s ) )
2005-08-31 10:47:56 +00:00
2011-08-30 16:46:46 +00:00
if s and s [ - 1 ] == ' \\ ' :
2005-08-31 10:47:56 +00:00
__residue__ . append ( s [ : - 1 ] )
return
s = " " . join ( __residue__ ) + s
__residue__ = [ ]
2011-08-30 16:46:46 +00:00
# Skip empty lines
if s == ' ' :
return
2011-02-22 21:45:26 +00:00
# Skip comments
if s [ 0 ] == ' # ' :
return
2005-08-31 10:47:56 +00:00
m = __func_start_regexp__ . match ( s )
if m :
2008-06-12 10:37:02 +00:00
__infunc__ = m . group ( " func " ) or " __anonymous "
2011-01-04 20:34:08 +00:00
ast . handleMethodFlags ( statements , fn , lineno , __infunc__ , m )
2005-08-31 10:47:56 +00:00
return
m = __def_regexp__ . match ( s )
if m :
__body__ . append ( s )
2010-08-26 17:06:30 +00:00
__inpython__ = m . group ( 1 )
2005-08-31 10:47:56 +00:00
return
m = __export_func_regexp__ . match ( s )
if m :
2011-01-04 20:34:08 +00:00
ast . handleExportFuncs ( statements , fn , lineno , m , classes )
2005-08-31 10:47:56 +00:00
return
m = __addtask_regexp__ . match ( s )
if m :
2011-01-04 20:34:08 +00:00
ast . handleAddTask ( statements , fn , lineno , m )
2005-08-31 10:47:56 +00:00
return
m = __addhandler_regexp__ . match ( s )
if m :
2011-01-04 20:34:08 +00:00
ast . handleBBHandlers ( statements , fn , lineno , m )
2005-08-31 10:47:56 +00:00
return
m = __inherit_regexp__ . match ( s )
if m :
2011-01-04 20:34:08 +00:00
ast . handleInherit ( statements , fn , lineno , m )
2005-08-31 10:47:56 +00:00
return
2009-05-19 10:10:37 +00:00
return ConfHandler . feeder ( lineno , s , fn , statements )
2005-08-31 10:47:56 +00:00
# Add us to the handlers list
2010-06-20 19:07:34 +00:00
from . . import handlers
2005-08-31 10:47:56 +00:00
handlers . append ( { ' supports ' : supports , ' handle ' : handle , ' init ' : init } )
del handlers