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
2016-05-12 07:22:18 +00:00
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
2015-05-14 16:56:51 +00:00
from . . import resolve_file , ast , logger , ParseError
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))|(.*)))))* " )
2013-12-18 10:44:30 +00:00
__deltask_regexp__ = re . compile ( " deltask \ s+(?P<func> \ w+) " )
2005-08-31 10:47:56 +00:00
__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
2015-05-14 16:56:51 +00:00
__infunc__ = [ ]
2005-08-31 10:47:56 +00:00
__inpython__ = False
__body__ = [ ]
__classname__ = " "
2009-05-19 11:53:12 +00:00
cached_statements = { }
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
2012-02-23 17:38:08 +00:00
def inherit ( files , fn , lineno , d ) :
2015-06-18 14:14:19 +00:00
__inherit_cache = d . getVar ( ' __inherit_cache ' , False ) or [ ]
2012-03-03 09:45:58 +00:00
files = d . expand ( files ) . split ( )
2006-11-29 22:52:37 +00:00
for file in files :
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 )
2012-12-11 00:02:50 +00:00
if not os . path . isabs ( file ) :
2016-11-25 15:28:08 +00:00
bbpath = d . getVar ( " BBPATH " )
2013-11-29 23:15:56 +00:00
abs_fn , attempts = bb . utils . which ( bbpath , file , history = True )
for af in attempts :
if af != abs_fn :
bb . parse . mark_dependency ( d , af )
2012-12-11 00:02:50 +00:00
if abs_fn :
file = abs_fn
2006-11-29 22:52:37 +00:00
if not file in __inherit_cache :
2014-05-11 12:05:40 +00:00
logger . debug ( 1 , " Inheriting %s (from %s : %d ) " % ( file , fn , lineno ) )
2006-11-29 22:52:37 +00:00
__inherit_cache . append ( file )
2013-01-18 11:46:30 +00:00
d . setVar ( ' __inherit_cache ' , __inherit_cache )
2012-02-23 17:38:08 +00:00
include ( fn , file , lineno , d , " inherit " )
2015-06-18 14:14:19 +00:00
__inherit_cache = d . getVar ( ' __inherit_cache ' , False ) 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 )
2013-05-09 21:06:45 +00:00
file . close ( )
2009-05-19 11:53:12 +00:00
if __inpython__ :
# add a blank line to close out any python definition
2015-12-20 13:21:14 +00:00
feeder ( lineno , " " , filename , base_name , statements , eof = True )
2009-05-19 11:53:12 +00:00
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 ) :
2012-12-11 00:01:56 +00:00
global __func_start_regexp__ , __inherit_regexp__ , __export_func_regexp__ , __addtask_regexp__ , __addhandler_regexp__ , __infunc__ , __body__ , __residue__ , __classname__
2005-08-31 10:47:56 +00:00
__body__ = [ ]
2015-05-14 16:56:51 +00:00
__infunc__ = [ ]
2005-08-31 10:47:56 +00:00
__classname__ = " "
__residue__ = [ ]
2012-12-07 18:08:42 +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
2015-06-18 14:14:19 +00:00
__inherit_cache = d . getVar ( ' __inherit_cache ' , False ) or [ ]
2008-03-03 22:01:45 +00:00
if not fn in __inherit_cache :
__inherit_cache . append ( fn )
2013-01-18 11:46:30 +00:00
d . setVar ( ' __inherit_cache ' , __inherit_cache )
2005-08-31 10:47:56 +00:00
if include != 0 :
2015-06-18 14:14:19 +00:00
oldfile = d . getVar ( ' FILE ' , False )
2005-08-31 10:47:56 +00:00
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
2015-06-04 09:42:26 +00:00
if ext != " .bbclass " and abs_fn != oldfile :
2013-01-18 11:46:30 +00:00
d . setVar ( ' FILE ' , abs_fn )
2009-05-19 10:10:37 +00:00
2012-12-14 12:33:01 +00:00
try :
statements . eval ( d )
2014-05-30 14:55:37 +00:00
except bb . parse . SkipRecipe :
2012-12-14 12:33:01 +00:00
bb . data . setVar ( " __SKIPPED " , True , d )
if include == 0 :
return { " " : d }
2009-05-19 10:10:37 +00:00
2015-05-14 16:56:51 +00:00
if __infunc__ :
raise ParseError ( " Shell function %s is never closed " % __infunc__ [ 0 ] , __infunc__ [ 1 ] , __infunc__ [ 2 ] )
if __residue__ :
raise ParseError ( " Leftover unparsed (incomplete?) data %s from %s " % __residue__ , fn )
2012-12-11 00:01:56 +00:00
if ext != " .bbclass " and include == 0 :
return ast . multi_finalize ( fn , d )
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
2015-06-04 09:42:26 +00:00
if ext != " .bbclass " and oldfile and abs_fn != oldfile :
2011-11-25 14:57:53 +00:00
d . setVar ( " FILE " , oldfile )
2006-05-09 15:44:08 +00:00
2005-08-31 10:47:56 +00:00
return d
2015-12-20 13:21:14 +00:00
def feeder ( lineno , s , fn , root , statements , eof = False ) :
2012-12-11 00:01:56 +00:00
global __func_start_regexp__ , __inherit_regexp__ , __export_func_regexp__ , __addtask_regexp__ , __addhandler_regexp__ , __def_regexp__ , __python_func_regexp__ , __inpython__ , __infunc__ , __body__ , bb , __residue__ , __classname__
2005-08-31 10:47:56 +00:00
if __infunc__ :
if s == ' } ' :
__body__ . append ( ' ' )
2016-02-09 15:10:56 +00:00
ast . handleMethod ( statements , fn , lineno , __infunc__ [ 0 ] , __body__ , __infunc__ [ 3 ] , __infunc__ [ 4 ] )
2015-05-14 16:56:51 +00:00
__infunc__ = [ ]
2005-08-31 10:47:56 +00:00
__body__ = [ ]
else :
__body__ . append ( s )
return
if __inpython__ :
m = __python_func_regexp__ . match ( s )
2015-12-20 13:21:14 +00:00
if m and not 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
2015-12-20 13:21:14 +00:00
if eof :
2006-11-16 15:02:15 +00:00
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 ] != " # " :
2012-12-14 13:53:32 +00:00
bb . fatal ( " 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 ) )
2013-01-21 11:00:52 +00:00
if len ( __residue__ ) != 0 and __residue__ [ 0 ] [ 0 ] == " # " and ( not s or s [ 0 ] != " # " ) :
2012-12-14 13:53:32 +00:00
bb . fatal ( " There is a confusing multiline, partially commented expression on line %s of file %s ( %s ). \n Please clarify whether this is all a comment or should be parsed. " % ( 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 :
2016-02-09 15:10:56 +00:00
__infunc__ = [ m . group ( " func " ) or " __anonymous " , fn , lineno , m . group ( " py " ) is not None , m . group ( " fr " ) is not None ]
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 :
2012-12-11 00:01:56 +00:00
ast . handleExportFuncs ( statements , fn , lineno , m , __classname__ )
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
2013-12-18 10:44:30 +00:00
m = __deltask_regexp__ . match ( s )
if m :
ast . handleDelTask ( statements , fn , lineno , m )
return
2005-08-31 10:47:56 +00:00
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