mirror of
https://git.yoctoproject.org/poky
synced 2026-06-01 13:09:50 +00:00
Initial population
git-svn-id: https://svn.o-hand.com/repos/poky@2 311d38ba-8fff-0310-9ca6-ca027cbcb966
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,70 @@
|
||||
"""
|
||||
BitBake Parsers
|
||||
|
||||
File parsers for the BitBake build tools.
|
||||
|
||||
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 as published by the Free Software
|
||||
Foundation; either version 2 of the License, or (at your option) any later
|
||||
version.
|
||||
|
||||
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., 59 Temple
|
||||
Place, Suite 330, Boston, MA 02111-1307 USA.
|
||||
|
||||
Based on functions from the base bb module, Copyright 2003 Holger Schurig
|
||||
"""
|
||||
|
||||
__all__ = [ 'ParseError', 'SkipPackage', 'cached_mtime', 'mark_dependency',
|
||||
'supports', 'handle', 'init' ]
|
||||
handlers = []
|
||||
|
||||
class ParseError(Exception):
|
||||
"""Exception raised when parsing fails"""
|
||||
|
||||
class SkipPackage(Exception):
|
||||
"""Exception raised to skip this package"""
|
||||
|
||||
__mtime_cache = {}
|
||||
def cached_mtime(f):
|
||||
import os
|
||||
if not __mtime_cache.has_key(f):
|
||||
__mtime_cache[f] = os.stat(f)[8]
|
||||
return __mtime_cache[f]
|
||||
|
||||
def mark_dependency(d, f):
|
||||
import bb, os
|
||||
if f.startswith('./'):
|
||||
f = "%s/%s" % (os.getcwd(), f[2:])
|
||||
deps = (bb.data.getVar('__depends', d) or "").split()
|
||||
deps.append("%s@%s" % (f, cached_mtime(f)))
|
||||
bb.data.setVar('__depends', " ".join(deps), d)
|
||||
|
||||
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
|
||||
|
||||
def handle(fn, data, include = 0):
|
||||
"""Call the handler that is appropriate for this file"""
|
||||
for h in handlers:
|
||||
if h['supports'](fn, data):
|
||||
return h['handle'](fn, data, include)
|
||||
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)
|
||||
|
||||
|
||||
from parse_py import __version__, ConfHandler, BBHandler
|
||||
Binary file not shown.
@@ -0,0 +1,288 @@
|
||||
/* bbf.flex
|
||||
|
||||
written by Marc Singer
|
||||
6 January 2005
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation; either version 2 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
USA.
|
||||
|
||||
DESCRIPTION
|
||||
-----------
|
||||
|
||||
flex lexer specification for a BitBake input file parser.
|
||||
|
||||
Unfortunately, flex doesn't welcome comments within the rule sets.
|
||||
I say unfortunately because this lexer is unreasonably complex and
|
||||
comments would make the code much easier to comprehend.
|
||||
|
||||
The BitBake grammar is not regular. In order to interpret all
|
||||
of the available input files, the lexer maintains much state as it
|
||||
parses. There are places where this lexer will emit tokens that
|
||||
are invalid. The parser will tend to catch these.
|
||||
|
||||
The lexer requires C++ at the moment. The only reason for this has
|
||||
to do with a very small amount of managed state. Producing a C
|
||||
lexer should be a reasonably easy task as long as the %reentrant
|
||||
option is used.
|
||||
|
||||
|
||||
NOTES
|
||||
-----
|
||||
|
||||
o RVALUES. There are three kinds of RVALUES. There are unquoted
|
||||
values, double quote enclosed strings, and single quote
|
||||
strings. Quoted strings may contain unescaped quotes (of either
|
||||
type), *and* any type may span more than one line by using a
|
||||
continuation '\' at the end of the line. This requires us to
|
||||
recognize all types of values with a single expression.
|
||||
Moreover, the only reason to quote a value is to include
|
||||
trailing or leading whitespace. Whitespace within a value is
|
||||
preserved, ugh.
|
||||
|
||||
o CLASSES. C_ patterns define classes. Classes ought not include
|
||||
a repitition operator, instead letting the reference to the class
|
||||
define the repitition count.
|
||||
|
||||
C_SS - symbol start
|
||||
C_SB - symbol body
|
||||
C_SP - whitespace
|
||||
|
||||
*/
|
||||
|
||||
%option never-interactive
|
||||
%option yylineno
|
||||
%option noyywrap
|
||||
%option reentrant stack
|
||||
|
||||
|
||||
%{
|
||||
|
||||
#include "token.h"
|
||||
#include "lexer.h"
|
||||
#include <ctype.h>
|
||||
|
||||
extern void *bbparseAlloc(void *(*mallocProc)(size_t));
|
||||
extern void bbparseFree(void *p, void (*freeProc)(void*));
|
||||
extern void *bbparseAlloc(void *(*mallocProc)(size_t));
|
||||
extern void *bbparse(void*, int, token_t, lex_t*);
|
||||
extern void bbparseTrace(FILE *TraceFILE, char *zTracePrompt);
|
||||
|
||||
//static const char* rgbInput;
|
||||
//static size_t cbInput;
|
||||
|
||||
|
||||
int lineError;
|
||||
int errorParse;
|
||||
|
||||
enum {
|
||||
errorNone = 0,
|
||||
errorUnexpectedInput,
|
||||
errorUnsupportedFeature,
|
||||
};
|
||||
|
||||
#define YY_EXTRA_TYPE lex_t*
|
||||
|
||||
/* Read from buffer */
|
||||
#define YY_INPUT(buf,result,max_size) \
|
||||
{ yyextra->input(buf, &result, max_size); }
|
||||
|
||||
//#define YY_DECL static size_t yylex ()
|
||||
|
||||
#define ERROR(e) \
|
||||
do { lineError = yylineno; errorParse = e; yyterminate (); } while (0)
|
||||
|
||||
static const char* fixup_escapes (const char* sz);
|
||||
|
||||
%}
|
||||
|
||||
|
||||
C_SP [ \t]
|
||||
COMMENT #.*\n
|
||||
OP_ASSIGN "="
|
||||
OP_IMMEDIATE ":="
|
||||
OP_PREPEND "=+"
|
||||
OP_APPEND "+="
|
||||
OP_COND "?="
|
||||
B_OPEN "{"
|
||||
B_CLOSE "}"
|
||||
|
||||
K_ADDTASK "addtask"
|
||||
K_ADDHANDLER "addhandler"
|
||||
K_AFTER "after"
|
||||
K_BEFORE "before"
|
||||
K_DEF "def"
|
||||
K_INCLUDE "include"
|
||||
K_INHERIT "inherit"
|
||||
K_PYTHON "python"
|
||||
K_FAKEROOT "fakeroot"
|
||||
K_EXPORT "export"
|
||||
K_EXPORT_FUNC "EXPORT_FUNCTIONS"
|
||||
|
||||
STRING \"([^\n\r]|"\\\n")*\"
|
||||
SSTRING \'([^\n\r]|"\\\n")*\'
|
||||
VALUE ([^'" \t\n])|([^'" \t\n]([^\n]|(\\\n))*[^'" \t\n])
|
||||
|
||||
C_SS [a-zA-Z_]
|
||||
C_SB [a-zA-Z0-9_+-.]
|
||||
REF $\{{C_SS}{C_SB}*\}
|
||||
SYMBOL {C_SS}{C_SB}*
|
||||
VARIABLE $?{C_SS}({C_SB}*|{REF})*(\[[a-zA-Z0-9_]*\])?
|
||||
FILENAME ([a-zA-Z_./]|{REF})(([-+a-zA-Z0-9_./]*)|{REF})*
|
||||
|
||||
PROC \({C_SP}*\)
|
||||
|
||||
%s S_DEF
|
||||
%s S_DEF_ARGS
|
||||
%s S_DEF_BODY
|
||||
%s S_FUNC
|
||||
%s S_INCLUDE
|
||||
%s S_INHERIT
|
||||
%s S_PROC
|
||||
%s S_RVALUE
|
||||
%s S_TASK
|
||||
|
||||
%%
|
||||
|
||||
{OP_APPEND} { BEGIN S_RVALUE;
|
||||
yyextra->accept (T_OP_APPEND); }
|
||||
{OP_PREPEND} { BEGIN S_RVALUE;
|
||||
yyextra->accept (T_OP_PREPEND); }
|
||||
{OP_IMMEDIATE} { BEGIN S_RVALUE;
|
||||
yyextra->accept (T_OP_IMMEDIATE); }
|
||||
{OP_ASSIGN} { BEGIN S_RVALUE;
|
||||
yyextra->accept (T_OP_ASSIGN); }
|
||||
{OP_COND} { BEGIN S_RVALUE;
|
||||
yyextra->accept (T_OP_COND); }
|
||||
|
||||
<S_RVALUE>\\\n{C_SP}* { }
|
||||
<S_RVALUE>{STRING} { BEGIN INITIAL;
|
||||
size_t cb = yyleng;
|
||||
while (cb && isspace (yytext[cb - 1]))
|
||||
--cb;
|
||||
yytext[cb - 1] = 0;
|
||||
yyextra->accept (T_STRING, yytext + 1); }
|
||||
<S_RVALUE>{SSTRING} { BEGIN INITIAL;
|
||||
size_t cb = yyleng;
|
||||
while (cb && isspace (yytext[cb - 1]))
|
||||
--cb;
|
||||
yytext[cb - 1] = 0;
|
||||
yyextra->accept (T_STRING, yytext + 1); }
|
||||
|
||||
<S_RVALUE>{VALUE} { ERROR (errorUnexpectedInput); }
|
||||
<S_RVALUE>{C_SP}*\n+ { BEGIN INITIAL;
|
||||
yyextra->accept (T_STRING, NULL); }
|
||||
|
||||
{K_INCLUDE} { BEGIN S_INCLUDE;
|
||||
yyextra->accept (T_INCLUDE); }
|
||||
{K_INHERIT} { BEGIN S_INHERIT;
|
||||
yyextra->accept (T_INHERIT); }
|
||||
{K_ADDTASK} { BEGIN S_TASK;
|
||||
yyextra->accept (T_ADDTASK); }
|
||||
{K_ADDHANDLER} { yyextra->accept (T_ADDHANDLER); }
|
||||
{K_EXPORT_FUNC} { BEGIN S_FUNC;
|
||||
yyextra->accept (T_EXPORT_FUNC); }
|
||||
<S_TASK>{K_BEFORE} { yyextra->accept (T_BEFORE); }
|
||||
<S_TASK>{K_AFTER} { yyextra->accept (T_AFTER); }
|
||||
<INITIAL>{K_EXPORT} { yyextra->accept (T_EXPORT); }
|
||||
|
||||
<INITIAL>{K_FAKEROOT} { yyextra->accept (T_FAKEROOT); }
|
||||
<INITIAL>{K_PYTHON} { yyextra->accept (T_PYTHON); }
|
||||
{PROC}{C_SP}*{B_OPEN}{C_SP}*\n* { BEGIN S_PROC;
|
||||
yyextra->accept (T_PROC_OPEN); }
|
||||
<S_PROC>{B_CLOSE}{C_SP}*\n* { BEGIN INITIAL;
|
||||
yyextra->accept (T_PROC_CLOSE); }
|
||||
<S_PROC>([^}][^\n]*)?\n* { yyextra->accept (T_PROC_BODY, yytext); }
|
||||
|
||||
{K_DEF} { BEGIN S_DEF; }
|
||||
<S_DEF>{SYMBOL} { BEGIN S_DEF_ARGS;
|
||||
yyextra->accept (T_SYMBOL, yytext); }
|
||||
<S_DEF_ARGS>[^\n:]*: { yyextra->accept (T_DEF_ARGS, yytext); }
|
||||
<S_DEF_ARGS>{C_SP}*\n { BEGIN S_DEF_BODY; }
|
||||
<S_DEF_BODY>{C_SP}+[^\n]*\n { yyextra->accept (T_DEF_BODY, yytext); }
|
||||
<S_DEF_BODY>\n { yyextra->accept (T_DEF_BODY, yytext); }
|
||||
<S_DEF_BODY>. { BEGIN INITIAL; unput (yytext[0]); }
|
||||
|
||||
{COMMENT} { }
|
||||
|
||||
<INITIAL>{SYMBOL} { yyextra->accept (T_SYMBOL, yytext); }
|
||||
<INITIAL>{VARIABLE} { yyextra->accept (T_VARIABLE, yytext); }
|
||||
|
||||
<S_TASK>{SYMBOL} { yyextra->accept (T_TSYMBOL, yytext); }
|
||||
<S_FUNC>{SYMBOL} { yyextra->accept (T_FSYMBOL, yytext); }
|
||||
<S_INHERIT>{SYMBOL} { yyextra->accept (T_ISYMBOL, yytext); }
|
||||
<S_INCLUDE>{FILENAME} { BEGIN INITIAL;
|
||||
yyextra->accept (T_ISYMBOL, yytext); }
|
||||
|
||||
<S_TASK>\n { BEGIN INITIAL; }
|
||||
<S_FUNC>\n { BEGIN INITIAL; }
|
||||
<S_INHERIT>\n { BEGIN INITIAL; }
|
||||
|
||||
[ \t\r\n] /* Insignificant whitespace */
|
||||
|
||||
. { ERROR (errorUnexpectedInput); }
|
||||
|
||||
/* Check for premature termination */
|
||||
<<EOF>> { return T_EOF; }
|
||||
|
||||
%%
|
||||
|
||||
void lex_t::accept (int token, const char* sz)
|
||||
{
|
||||
token_t t;
|
||||
memset (&t, 0, sizeof (t));
|
||||
t.copyString(sz);
|
||||
|
||||
/* tell lemon to parse the token */
|
||||
parse (parser, token, t, this);
|
||||
}
|
||||
|
||||
int lex_t::line ()const
|
||||
{
|
||||
return yyget_lineno (scanner);
|
||||
}
|
||||
|
||||
const char* lex_t::filename ()const
|
||||
{
|
||||
return m_fileName;
|
||||
}
|
||||
|
||||
void parse (MappedFile* mf)
|
||||
{
|
||||
void* parser = bbparseAlloc (malloc);
|
||||
yyscan_t scanner;
|
||||
lex_t lex;
|
||||
|
||||
yylex_init (&scanner);
|
||||
|
||||
lex.parser = parser;
|
||||
lex.scanner = scanner;
|
||||
lex.mf = mf;
|
||||
lex.rgbInput = mf->m_rgb;
|
||||
lex.cbInput = mf->m_cb;
|
||||
lex.parse = bbparse;
|
||||
yyset_extra (&lex, scanner);
|
||||
|
||||
|
||||
int result = yylex (scanner);
|
||||
|
||||
lex.accept (0);
|
||||
bbparseTrace (NULL, NULL);
|
||||
|
||||
if (result != T_EOF)
|
||||
WARNING ("premature end of file\n");
|
||||
|
||||
yylex_destroy (scanner);
|
||||
bbparseFree (parser, free);
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
"""
|
||||
|
||||
BitBake C Parser Python Code
|
||||
|
||||
Copyright (C) 2005 Holger Hans Peter Freyther
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
|
||||
SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
|
||||
THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
"""
|
||||
|
||||
__version__ = "0xdeadbeef"
|
||||
|
||||
class CParser:
|
||||
"""
|
||||
The C-based Parser for Bitbake
|
||||
"""
|
||||
def __init__(self, data, type):
|
||||
"""
|
||||
Constructor
|
||||
"""
|
||||
self._data = data
|
||||
|
||||
def _syntax_error(self, file, line):
|
||||
"""
|
||||
lemon/flex reports an syntax error to us and we will
|
||||
raise an exception
|
||||
"""
|
||||
pass
|
||||
|
||||
def _export(self, data):
|
||||
"""
|
||||
EXPORT VAR = "MOO"
|
||||
we will now export VAR
|
||||
"""
|
||||
pass
|
||||
|
||||
def _assign(self, key, value):
|
||||
"""
|
||||
VAR = "MOO"
|
||||
we will assign moo to VAR
|
||||
"""
|
||||
pass
|
||||
|
||||
def _assign(self, key, value):
|
||||
"""
|
||||
"""
|
||||
pass
|
||||
|
||||
def _append(self, key, value):
|
||||
"""
|
||||
VAR += "MOO"
|
||||
we will append " MOO" to var
|
||||
"""
|
||||
pass
|
||||
|
||||
def _prepend(self, key, value):
|
||||
"""
|
||||
VAR =+ "MOO"
|
||||
we will prepend "MOO " to var
|
||||
"""
|
||||
pass
|
||||
|
||||
def _immediate(self, key, value):
|
||||
"""
|
||||
VAR := "MOO ${CVSDATE}"
|
||||
we will assign immediately and expand vars
|
||||
"""
|
||||
pass
|
||||
|
||||
def _conditional(self, key, value):
|
||||
"""
|
||||
"""
|
||||
pass
|
||||
|
||||
def _add_task(self, task, before = None, after = None):
|
||||
"""
|
||||
"""
|
||||
pass
|
||||
|
||||
def _include(self, file):
|
||||
"""
|
||||
"""
|
||||
pass
|
||||
|
||||
def _inherit(self, file):
|
||||
"""
|
||||
"""
|
||||
pass
|
||||
|
||||
def _shell_procedure(self, name, body):
|
||||
"""
|
||||
"""
|
||||
pass
|
||||
|
||||
def _python_procedure(self, name, body):
|
||||
"""
|
||||
"""
|
||||
pass
|
||||
|
||||
def _fakeroot_procedure(self, name, body):
|
||||
"""
|
||||
"""
|
||||
pass
|
||||
|
||||
def _def_procedure(self, a, b, c):
|
||||
"""
|
||||
"""
|
||||
pass
|
||||
|
||||
def _export_func(self, name):
|
||||
"""
|
||||
"""
|
||||
pass
|
||||
|
||||
def _add_handler(self, handler):
|
||||
"""
|
||||
"""
|
||||
pass
|
||||
@@ -0,0 +1,161 @@
|
||||
/* bbp.lemon
|
||||
|
||||
written by Marc Singer
|
||||
6 January 2005
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation; either version 2 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
USA.
|
||||
|
||||
DESCRIPTION
|
||||
-----------
|
||||
|
||||
lemon parser specification file for a BitBake input file parser.
|
||||
|
||||
Most of the interesting shenanigans are done in the lexer. The
|
||||
BitBake grammar is not regular. In order to emit tokens that
|
||||
the parser can properly interpret in LALR fashion, the lexer
|
||||
manages the interpretation state. This is why there are ISYMBOLs,
|
||||
SYMBOLS, and TSYMBOLS.
|
||||
|
||||
This parser was developed by reading the limited available
|
||||
documentation for BitBake and by analyzing the available BB files.
|
||||
There is no assertion of correctness to be made about this parser.
|
||||
|
||||
*/
|
||||
|
||||
%token_type {token_t}
|
||||
%name bbparse
|
||||
%token_prefix T_
|
||||
%extra_argument {lex_t* lex}
|
||||
|
||||
%include {
|
||||
#include "token.h"
|
||||
}
|
||||
|
||||
|
||||
%token_destructor { $$.release_this (); }
|
||||
|
||||
%syntax_error { printf ("%s:%d: syntax error\n",
|
||||
lex->filename (), lex->line ()); }
|
||||
|
||||
program ::= statements.
|
||||
|
||||
statements ::= statements statement.
|
||||
statements ::= .
|
||||
|
||||
variable(r) ::= SYMBOL(s).
|
||||
{ r.assignString( s.string() );
|
||||
s.assignString( 0 );
|
||||
s.release_this(); }
|
||||
variable(r) ::= VARIABLE(v).
|
||||
{
|
||||
r.assignString( v.string() );
|
||||
v.assignString( 0 );
|
||||
v.release_this(); }
|
||||
|
||||
statement ::= EXPORT variable(s) OP_ASSIGN STRING(v).
|
||||
{ e_assign( s.string(), v.string() );
|
||||
e_export( s.string() );
|
||||
s.release_this(); v.release_this(); }
|
||||
statement ::= EXPORT variable(s) OP_IMMEDIATE STRING(v).
|
||||
{ e_immediate (s.string(), v.string() );
|
||||
e_export( s.string() );
|
||||
s.release_this(); v.release_this(); }
|
||||
statement ::= EXPORT variable(s) OP_COND STRING(v).
|
||||
{ e_cond( s.string(), v.string() );
|
||||
s.release_this(); v.release_this(); }
|
||||
|
||||
statement ::= variable(s) OP_ASSIGN STRING(v).
|
||||
{ e_assign( s.string(), v.string() );
|
||||
s.release_this(); v.release_this(); }
|
||||
statement ::= variable(s) OP_PREPEND STRING(v).
|
||||
{ e_prepend( s.string(), v.string() );
|
||||
s.release_this(); v.release_this(); }
|
||||
statement ::= variable(s) OP_APPEND STRING(v).
|
||||
{ e_append( s.string() , v.string() );
|
||||
s.release_this(); v.release_this(); }
|
||||
statement ::= variable(s) OP_IMMEDIATE STRING(v).
|
||||
{ e_immediate( s.string(), v.string() );
|
||||
s.release_this(); v.release_this(); }
|
||||
statement ::= variable(s) OP_COND STRING(v).
|
||||
{ e_cond( s.string(), v.string() );
|
||||
s.release_this(); v.release_this(); }
|
||||
|
||||
task ::= TSYMBOL(t) BEFORE TSYMBOL(b) AFTER TSYMBOL(a).
|
||||
{ e_addtask( t.string(), b.string(), a.string() );
|
||||
t.release_this(); b.release_this(); a.release_this(); }
|
||||
task ::= TSYMBOL(t) AFTER TSYMBOL(a) BEFORE TSYMBOL(b).
|
||||
{ e_addtask( t.string(), b.string(), a.string());
|
||||
t.release_this(); a.release_this(); b.release_this(); }
|
||||
task ::= TSYMBOL(t).
|
||||
{ e_addtask( t.string(), NULL, NULL);
|
||||
t.release_this();}
|
||||
task ::= TSYMBOL(t) BEFORE TSYMBOL(b).
|
||||
{ e_addtask( t.string(), b.string(), NULL);
|
||||
t.release_this(); b.release_this(); }
|
||||
task ::= TSYMBOL(t) AFTER TSYMBOL(a).
|
||||
{ e_addtask( t.string(), NULL, a.string());
|
||||
t.release_this(); a.release_this(); }
|
||||
tasks ::= tasks task.
|
||||
tasks ::= task.
|
||||
statement ::= ADDTASK tasks.
|
||||
|
||||
statement ::= ADDHANDLER SYMBOL(s).
|
||||
{ e_addhandler( s.string()); s.release_this (); }
|
||||
|
||||
func ::= FSYMBOL(f). { e_export_func(f.string()); f.release_this(); }
|
||||
funcs ::= funcs func.
|
||||
funcs ::= func.
|
||||
statement ::= EXPORT_FUNC funcs.
|
||||
|
||||
inherit ::= ISYMBOL(i). { e_inherit(i.string() ); i.release_this (); }
|
||||
inherits ::= inherits inherit.
|
||||
inherits ::= inherit.
|
||||
statement ::= INHERIT inherits.
|
||||
|
||||
statement ::= INCLUDE ISYMBOL(i).
|
||||
{ e_include(i.string() ); i.release_this(); }
|
||||
|
||||
proc_body(r) ::= proc_body(l) PROC_BODY(b).
|
||||
{ /* concatenate body lines */
|
||||
r.assignString( token_t::concatString(l.string(), b.string()) );
|
||||
l.release_this ();
|
||||
b.release_this ();
|
||||
}
|
||||
proc_body(b) ::= . { b.assignString(0); }
|
||||
statement ::= variable(p) PROC_OPEN proc_body(b) PROC_CLOSE.
|
||||
{ e_proc( p.string(), b.string() );
|
||||
p.release_this(); b.release_this(); }
|
||||
statement ::= PYTHON SYMBOL(p) PROC_OPEN proc_body(b) PROC_CLOSE.
|
||||
{ e_proc_python (p.string(), b.string() );
|
||||
p.release_this(); b.release_this(); }
|
||||
statement ::= PYTHON PROC_OPEN proc_body(b) PROC_CLOSE.
|
||||
{ e_proc_python( NULL, b.string());
|
||||
b.release_this (); }
|
||||
|
||||
statement ::= FAKEROOT SYMBOL(p) PROC_OPEN proc_body(b) PROC_CLOSE.
|
||||
{ e_proc_fakeroot(p.string(), b.string() );
|
||||
p.release_this (); b.release_this (); }
|
||||
|
||||
def_body(r) ::= def_body(l) DEF_BODY(b).
|
||||
{ /* concatenate body lines */
|
||||
r.assignString( token_t::concatString(l.string(), b.string());
|
||||
l.release_this (); b.release_this ();
|
||||
}
|
||||
def_body(b) ::= . { b.sz = 0; }
|
||||
statement ::= SYMBOL(p) DEF_ARGS(a) def_body(b).
|
||||
{ e_def( p.string(), a.string(), b.string());
|
||||
p.release_this(); a.release_this(); b.release_this(); }
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
Copyright (C) 2005 Holger Hans Peter Freyther
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
|
||||
SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
|
||||
THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef LEXER_H
|
||||
#define LEXER_H
|
||||
|
||||
struct lex_t {
|
||||
void *parser;
|
||||
void *scanner;
|
||||
void* (*parse)(void*, int, token_t, lex_t*);
|
||||
|
||||
void accept(int token, const char* string = 0);
|
||||
void input(char *buf, int *result, int_max_size);
|
||||
int line()const;
|
||||
const char* filename()const;
|
||||
private:
|
||||
const char* m_fileName;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
Copyright (C) 2005 Holger Hans Peter Freyther
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
|
||||
SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
|
||||
THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef TOKEN_H
|
||||
#define TOKEN_H
|
||||
|
||||
#define PURE_METHOD
|
||||
|
||||
struct token_t {
|
||||
const char* string()const PURE_METHOD;
|
||||
|
||||
static char* concatString(const char* l, const char* r);
|
||||
void assignString(const char* str);
|
||||
void copyString(const char* str);
|
||||
|
||||
void release_this();
|
||||
|
||||
private:
|
||||
char *m_string;
|
||||
size_t m_stringLen;
|
||||
};
|
||||
|
||||
inline const char* token_t::string()const
|
||||
{
|
||||
return m_string;
|
||||
}
|
||||
|
||||
/*
|
||||
* append str to the current string
|
||||
*/
|
||||
inline char* token_t::concatString(const char* l, const char* r)
|
||||
{
|
||||
size_t cb = (l ? strlen (l) : 0) + strlen (r) + 1;
|
||||
r_sz = new char[cb];
|
||||
*r_sz = 0;
|
||||
if (l) strcat (r_sz, l);
|
||||
strcat (r_sz, r);
|
||||
|
||||
return r_sz;
|
||||
}
|
||||
|
||||
inline void token_t::assignString(const char* str)
|
||||
{
|
||||
m_string = str;
|
||||
m_stringLen = str ? strlen(str) : 0;
|
||||
}
|
||||
|
||||
inline void token_t::copyString(const char* str)
|
||||
{
|
||||
if( str ) {
|
||||
m_stringLen = strlen(str);
|
||||
m_string = new char[m_stringLen+1];
|
||||
strcpy(m_string, str)
|
||||
}
|
||||
}
|
||||
|
||||
inline void token_t::release_this()
|
||||
{
|
||||
delete m_string;
|
||||
m_string = 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,378 @@
|
||||
#!/usr/bin/env python
|
||||
# ex:ts=4:sw=4:sts=4:et
|
||||
# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
|
||||
"""class for handling .bb files
|
||||
|
||||
Reads a .bb file and obtains its metadata
|
||||
|
||||
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 as published by the Free Software
|
||||
Foundation; either version 2 of the License, or (at your option) any later
|
||||
version.
|
||||
|
||||
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., 59 Temple
|
||||
Place, Suite 330, Boston, MA 02111-1307 USA."""
|
||||
|
||||
import re, bb, os, sys
|
||||
import bb.fetch, bb.build
|
||||
from bb import debug, data, fetch, fatal
|
||||
|
||||
from ConfHandler import include, localpath, obtain, init
|
||||
from bb.parse import ParseError
|
||||
|
||||
__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+.*)|(^$)" )
|
||||
__word__ = re.compile(r"\S+")
|
||||
|
||||
__infunc__ = ""
|
||||
__inpython__ = False
|
||||
__body__ = []
|
||||
__bbpath_found__ = 0
|
||||
__classname__ = ""
|
||||
classes = [ None, ]
|
||||
|
||||
def supports(fn, d):
|
||||
localfn = localpath(fn, d)
|
||||
return localfn[-3:] == ".bb" or localfn[-8:] == ".bbclass" or localfn[-4:] == ".inc"
|
||||
|
||||
def inherit(files, d):
|
||||
__inherit_cache = data.getVar('__inherit_cache', d) or ""
|
||||
fn = ""
|
||||
lineno = 0
|
||||
for f in files:
|
||||
file = data.expand(f, d)
|
||||
if file[0] != "/" and file[-8:] != ".bbclass":
|
||||
file = os.path.join('classes', '%s.bbclass' % file)
|
||||
|
||||
if not file in __inherit_cache.split():
|
||||
debug(2, "BB %s:%d: inheriting %s" % (fn, lineno, file))
|
||||
__inherit_cache += " %s" % file
|
||||
include(fn, file, d)
|
||||
data.setVar('__inherit_cache', __inherit_cache, d)
|
||||
|
||||
|
||||
def handle(fn, d, include = 0):
|
||||
global __func_start_regexp__, __inherit_regexp__, __export_func_regexp__, __addtask_regexp__, __addhandler_regexp__, __infunc__, __body__, __bbpath_found__, __residue__
|
||||
__body__ = []
|
||||
__bbpath_found__ = 0
|
||||
__infunc__ = ""
|
||||
__classname__ = ""
|
||||
__residue__ = []
|
||||
|
||||
if include == 0:
|
||||
debug(2, "BB " + fn + ": handle(data)")
|
||||
else:
|
||||
debug(2, "BB " + fn + ": handle(data, include)")
|
||||
|
||||
(root, ext) = os.path.splitext(os.path.basename(fn))
|
||||
init(d)
|
||||
|
||||
if ext == ".bbclass":
|
||||
__classname__ = root
|
||||
classes.append(__classname__)
|
||||
|
||||
if include != 0:
|
||||
oldfile = data.getVar('FILE', d)
|
||||
else:
|
||||
oldfile = None
|
||||
|
||||
fn = obtain(fn, d)
|
||||
bbpath = (data.getVar('BBPATH', d, 1) or '').split(':')
|
||||
if not os.path.isabs(fn):
|
||||
f = None
|
||||
for p in bbpath:
|
||||
p = data.expand(p, d)
|
||||
j = os.path.join(p, fn)
|
||||
if os.access(j, os.R_OK):
|
||||
abs_fn = j
|
||||
f = open(j, 'r')
|
||||
break
|
||||
if f is None:
|
||||
raise IOError("file not found")
|
||||
else:
|
||||
f = open(fn,'r')
|
||||
abs_fn = fn
|
||||
|
||||
if ext != ".bbclass":
|
||||
bbpath.insert(0, os.path.dirname(abs_fn))
|
||||
data.setVar('BBPATH', ":".join(bbpath), d)
|
||||
|
||||
if include:
|
||||
bb.parse.mark_dependency(d, abs_fn)
|
||||
|
||||
if ext != ".bbclass":
|
||||
data.setVar('FILE', fn, d)
|
||||
i = (data.getVar("INHERIT", d, 1) or "").split()
|
||||
if not "base" in i and __classname__ != "base":
|
||||
i[0:0] = ["base"]
|
||||
inherit(i, d)
|
||||
|
||||
lineno = 0
|
||||
while 1:
|
||||
lineno = lineno + 1
|
||||
s = f.readline()
|
||||
if not s: break
|
||||
s = s.rstrip()
|
||||
feeder(lineno, s, fn, d)
|
||||
if __inpython__:
|
||||
# add a blank line to close out any python definition
|
||||
feeder(lineno + 1, "", fn, d)
|
||||
if ext == ".bbclass":
|
||||
classes.remove(__classname__)
|
||||
else:
|
||||
if include == 0:
|
||||
data.expandKeys(d)
|
||||
data.update_data(d)
|
||||
anonqueue = data.getVar("__anonqueue", d, 1) or []
|
||||
for anon in anonqueue:
|
||||
data.setVar("__anonfunc", anon["content"], d)
|
||||
data.setVarFlags("__anonfunc", anon["flags"], d)
|
||||
from bb import build
|
||||
try:
|
||||
t = data.getVar('T', d)
|
||||
data.setVar('T', '${TMPDIR}/', d)
|
||||
build.exec_func("__anonfunc", d)
|
||||
data.delVar('T', d)
|
||||
if t:
|
||||
data.setVar('T', t, d)
|
||||
except Exception, e:
|
||||
bb.debug(1, "executing anonymous function: %s" % e)
|
||||
raise
|
||||
data.delVar("__anonqueue", d)
|
||||
data.delVar("__anonfunc", d)
|
||||
set_additional_vars(fn, d, include)
|
||||
data.update_data(d)
|
||||
|
||||
for var in data.keys(d):
|
||||
if data.getVarFlag(var, 'handler', d):
|
||||
bb.event.register(data.getVar(var, d))
|
||||
continue
|
||||
|
||||
if not data.getVarFlag(var, 'task', d):
|
||||
continue
|
||||
|
||||
deps = data.getVarFlag(var, 'deps', d) or []
|
||||
postdeps = data.getVarFlag(var, 'postdeps', d) or []
|
||||
bb.build.add_task(var, deps, d)
|
||||
for p in postdeps:
|
||||
pdeps = data.getVarFlag(p, 'deps', d) or []
|
||||
pdeps.append(var)
|
||||
data.setVarFlag(p, 'deps', pdeps, d)
|
||||
bb.build.add_task(p, pdeps, d)
|
||||
bbpath.pop(0)
|
||||
if oldfile:
|
||||
bb.data.setVar("FILE", oldfile, d)
|
||||
return d
|
||||
|
||||
def feeder(lineno, s, fn, d):
|
||||
global __func_start_regexp__, __inherit_regexp__, __export_func_regexp__, __addtask_regexp__, __addhandler_regexp__, __def_regexp__, __python_func_regexp__, __inpython__,__infunc__, __body__, __bbpath_found__, classes, bb, __residue__
|
||||
if __infunc__:
|
||||
if s == '}':
|
||||
__body__.append('')
|
||||
data.setVar(__infunc__, '\n'.join(__body__), d)
|
||||
data.setVarFlag(__infunc__, "func", 1, d)
|
||||
if __infunc__ == "__anonymous":
|
||||
anonqueue = bb.data.getVar("__anonqueue", d) or []
|
||||
anonitem = {}
|
||||
anonitem["content"] = bb.data.getVar("__anonymous", d)
|
||||
anonitem["flags"] = bb.data.getVarFlags("__anonymous", d)
|
||||
anonqueue.append(anonitem)
|
||||
bb.data.setVar("__anonqueue", anonqueue, d)
|
||||
bb.data.delVarFlags("__anonymous", d)
|
||||
bb.data.delVar("__anonymous", d)
|
||||
__infunc__ = ""
|
||||
__body__ = []
|
||||
else:
|
||||
__body__.append(s)
|
||||
return
|
||||
|
||||
if __inpython__:
|
||||
m = __python_func_regexp__.match(s)
|
||||
if m:
|
||||
__body__.append(s)
|
||||
return
|
||||
else:
|
||||
text = '\n'.join(__body__)
|
||||
comp = compile(text, "<bb>", "exec")
|
||||
exec comp in __builtins__
|
||||
__body__ = []
|
||||
__inpython__ = False
|
||||
funcs = data.getVar('__functions__', d) or ""
|
||||
data.setVar('__functions__', "%s\n%s" % (funcs, text), d)
|
||||
# fall through
|
||||
|
||||
if s == '' or s[0] == '#': return # skip comments and empty lines
|
||||
|
||||
if s[-1] == '\\':
|
||||
__residue__.append(s[:-1])
|
||||
return
|
||||
|
||||
s = "".join(__residue__) + s
|
||||
__residue__ = []
|
||||
|
||||
m = __func_start_regexp__.match(s)
|
||||
if m:
|
||||
__infunc__ = m.group("func") or "__anonymous"
|
||||
key = __infunc__
|
||||
if data.getVar(key, d):
|
||||
# clean up old version of this piece of metadata, as its
|
||||
# flags could cause problems
|
||||
data.setVarFlag(key, 'python', None, d)
|
||||
data.setVarFlag(key, 'fakeroot', None, d)
|
||||
if m.group("py") is not None:
|
||||
data.setVarFlag(key, "python", "1", d)
|
||||
else:
|
||||
data.delVarFlag(key, "python", d)
|
||||
if m.group("fr") is not None:
|
||||
data.setVarFlag(key, "fakeroot", "1", d)
|
||||
else:
|
||||
data.delVarFlag(key, "fakeroot", d)
|
||||
return
|
||||
|
||||
m = __def_regexp__.match(s)
|
||||
if m:
|
||||
__body__.append(s)
|
||||
__inpython__ = True
|
||||
return
|
||||
|
||||
m = __export_func_regexp__.match(s)
|
||||
if m:
|
||||
fns = m.group(1)
|
||||
n = __word__.findall(fns)
|
||||
for f in n:
|
||||
allvars = []
|
||||
allvars.append(f)
|
||||
allvars.append(classes[-1] + "_" + f)
|
||||
|
||||
vars = [[ allvars[0], allvars[1] ]]
|
||||
if len(classes) > 1 and classes[-2] is not None:
|
||||
allvars.append(classes[-2] + "_" + f)
|
||||
vars = []
|
||||
vars.append([allvars[2], allvars[1]])
|
||||
vars.append([allvars[0], allvars[2]])
|
||||
|
||||
for (var, calledvar) in vars:
|
||||
if data.getVar(var, d) and not data.getVarFlag(var, 'export_func', d):
|
||||
continue
|
||||
|
||||
if data.getVar(var, d):
|
||||
data.setVarFlag(var, 'python', None, d)
|
||||
data.setVarFlag(var, 'func', None, d)
|
||||
|
||||
for flag in [ "func", "python" ]:
|
||||
if data.getVarFlag(calledvar, flag, d):
|
||||
data.setVarFlag(var, flag, data.getVarFlag(calledvar, flag, d), d)
|
||||
for flag in [ "dirs" ]:
|
||||
if data.getVarFlag(var, flag, d):
|
||||
data.setVarFlag(calledvar, flag, data.getVarFlag(var, flag, d), d)
|
||||
|
||||
if data.getVarFlag(calledvar, "python", d):
|
||||
data.setVar(var, "\tbb.build.exec_func('" + calledvar + "', d)\n", d)
|
||||
else:
|
||||
data.setVar(var, "\t" + calledvar + "\n", d)
|
||||
data.setVarFlag(var, 'export_func', '1', d)
|
||||
|
||||
return
|
||||
|
||||
m = __addtask_regexp__.match(s)
|
||||
if m:
|
||||
func = m.group("func")
|
||||
before = m.group("before")
|
||||
after = m.group("after")
|
||||
if func is None:
|
||||
return
|
||||
var = "do_" + func
|
||||
|
||||
data.setVarFlag(var, "task", 1, d)
|
||||
|
||||
if after is not None:
|
||||
# set up deps for function
|
||||
data.setVarFlag(var, "deps", after.split(), d)
|
||||
if before is not None:
|
||||
# set up things that depend on this func
|
||||
data.setVarFlag(var, "postdeps", before.split(), d)
|
||||
return
|
||||
|
||||
m = __addhandler_regexp__.match(s)
|
||||
if m:
|
||||
fns = m.group(1)
|
||||
hs = __word__.findall(fns)
|
||||
for h in hs:
|
||||
data.setVarFlag(h, "handler", 1, d)
|
||||
return
|
||||
|
||||
m = __inherit_regexp__.match(s)
|
||||
if m:
|
||||
|
||||
files = m.group(1)
|
||||
n = __word__.findall(files)
|
||||
inherit(n, d)
|
||||
return
|
||||
|
||||
from bb.parse import ConfHandler
|
||||
return ConfHandler.feeder(lineno, s, fn, d)
|
||||
|
||||
__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
|
||||
exp = 3 - len(parts)
|
||||
tmplist = []
|
||||
while exp != 0:
|
||||
exp -= 1
|
||||
tmplist.append(None)
|
||||
parts.extend(tmplist)
|
||||
return parts
|
||||
|
||||
def set_additional_vars(file, d, include):
|
||||
"""Deduce rest of variables, e.g. ${A} out of ${SRC_URI}"""
|
||||
|
||||
debug(2,"BB %s: set_additional_vars" % file)
|
||||
|
||||
src_uri = data.getVar('SRC_URI', d)
|
||||
if not src_uri:
|
||||
return
|
||||
src_uri = data.expand(src_uri, d)
|
||||
|
||||
a = data.getVar('A', d)
|
||||
if a:
|
||||
a = data.expand(a, d).split()
|
||||
else:
|
||||
a = []
|
||||
|
||||
from bb import fetch
|
||||
try:
|
||||
fetch.init(src_uri.split(), d)
|
||||
except fetch.NoMethodError:
|
||||
pass
|
||||
except bb.MalformedUrl,e:
|
||||
raise ParseError("Unable to generate local paths for SRC_URI due to malformed uri: %s" % e)
|
||||
|
||||
a += fetch.localpaths(d)
|
||||
del fetch
|
||||
data.setVar('A', " ".join(a), d)
|
||||
|
||||
|
||||
# Add us to the handlers list
|
||||
from bb.parse import handlers
|
||||
handlers.append({'supports': supports, 'handle': handle, 'init': init})
|
||||
del handlers
|
||||
Binary file not shown.
@@ -0,0 +1,199 @@
|
||||
#!/usr/bin/env python
|
||||
# ex:ts=4:sw=4:sts=4:et
|
||||
# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
|
||||
"""class for handling configuration data files
|
||||
|
||||
Reads a .conf file and obtains its metadata
|
||||
|
||||
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 as published by the Free Software
|
||||
Foundation; either version 2 of the License, or (at your option) any later
|
||||
version.
|
||||
|
||||
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., 59 Temple
|
||||
Place, Suite 330, Boston, MA 02111-1307 USA."""
|
||||
|
||||
import re, bb.data, os, sys
|
||||
from bb import debug, fatal
|
||||
from bb.parse import ParseError
|
||||
|
||||
#__config_regexp__ = re.compile( r"(?P<exp>export\s*)?(?P<var>[a-zA-Z0-9\-_+.${}]+)\s*(?P<colon>:)?(?P<ques>\?)?=\s*(?P<apo>['\"]?)(?P<value>.*)(?P=apo)$")
|
||||
__config_regexp__ = re.compile( r"(?P<exp>export\s*)?(?P<var>[a-zA-Z0-9\-_+.${}/]+)(\[(?P<flag>[a-zA-Z0-9\-_+.]+)\])?\s*((?P<colon>:=)|(?P<ques>\?=)|(?P<append>\+=)|(?P<prepend>=\+)|(?P<predot>=\.)|(?P<postdot>\.=)|=)\s*(?P<apo>['\"]?)(?P<value>.*)(?P=apo)$")
|
||||
__include_regexp__ = re.compile( r"include\s+(.+)" )
|
||||
|
||||
def init(data):
|
||||
if not bb.data.getVar('TOPDIR', data):
|
||||
bb.data.setVar('TOPDIR', os.getcwd(), data)
|
||||
if not bb.data.getVar('BBPATH', data):
|
||||
bb.data.setVar('BBPATH', os.path.join(sys.prefix, 'share', 'bitbake'), data)
|
||||
|
||||
def supports(fn, d):
|
||||
return localpath(fn, d)[-5:] == ".conf"
|
||||
|
||||
def localpath(fn, d):
|
||||
if os.path.exists(fn):
|
||||
return fn
|
||||
|
||||
localfn = None
|
||||
try:
|
||||
localfn = bb.fetch.localpath(fn, d)
|
||||
except bb.MalformedUrl:
|
||||
pass
|
||||
|
||||
if not localfn:
|
||||
localfn = fn
|
||||
return localfn
|
||||
|
||||
def obtain(fn, data = bb.data.init()):
|
||||
import sys, bb
|
||||
fn = bb.data.expand(fn, data)
|
||||
localfn = bb.data.expand(localpath(fn, data), data)
|
||||
|
||||
if localfn != fn:
|
||||
dldir = bb.data.getVar('DL_DIR', data, 1)
|
||||
if not dldir:
|
||||
debug(1, "obtain: DL_DIR not defined")
|
||||
return localfn
|
||||
bb.mkdirhier(dldir)
|
||||
try:
|
||||
bb.fetch.init([fn])
|
||||
except bb.fetch.NoMethodError:
|
||||
(type, value, traceback) = sys.exc_info()
|
||||
debug(1, "obtain: no method: %s" % value)
|
||||
return localfn
|
||||
|
||||
try:
|
||||
bb.fetch.go(data)
|
||||
except bb.fetch.MissingParameterError:
|
||||
(type, value, traceback) = sys.exc_info()
|
||||
debug(1, "obtain: missing parameters: %s" % value)
|
||||
return localfn
|
||||
except bb.fetch.FetchError:
|
||||
(type, value, traceback) = sys.exc_info()
|
||||
debug(1, "obtain: failed: %s" % value)
|
||||
return localfn
|
||||
return localfn
|
||||
|
||||
|
||||
def include(oldfn, fn, data = bb.data.init()):
|
||||
if oldfn == fn: # prevent infinate recursion
|
||||
return None
|
||||
|
||||
import bb
|
||||
fn = bb.data.expand(fn, data)
|
||||
oldfn = bb.data.expand(oldfn, data)
|
||||
|
||||
from bb.parse import handle
|
||||
try:
|
||||
ret = handle(fn, data, 1)
|
||||
except IOError:
|
||||
debug(2, "CONF file '%s' not found" % fn)
|
||||
|
||||
def handle(fn, data = bb.data.init(), include = 0):
|
||||
if include:
|
||||
inc_string = "including"
|
||||
else:
|
||||
inc_string = "reading"
|
||||
init(data)
|
||||
|
||||
if include == 0:
|
||||
bb.data.inheritFromOS(data)
|
||||
oldfile = None
|
||||
else:
|
||||
oldfile = bb.data.getVar('FILE', data)
|
||||
|
||||
fn = obtain(fn, data)
|
||||
bbpath = []
|
||||
if not os.path.isabs(fn):
|
||||
f = None
|
||||
vbbpath = bb.data.getVar("BBPATH", data)
|
||||
if vbbpath:
|
||||
bbpath += vbbpath.split(":")
|
||||
for p in bbpath:
|
||||
currname = os.path.join(bb.data.expand(p, data), fn)
|
||||
if os.access(currname, os.R_OK):
|
||||
f = open(currname, 'r')
|
||||
abs_fn = currname
|
||||
debug(1, "CONF %s %s" % (inc_string, currname))
|
||||
break
|
||||
if f is None:
|
||||
raise IOError("file not found")
|
||||
else:
|
||||
f = open(fn,'r')
|
||||
debug(1, "CONF %s %s" % (inc_string,fn))
|
||||
abs_fn = fn
|
||||
|
||||
if include:
|
||||
bb.parse.mark_dependency(data, abs_fn)
|
||||
|
||||
lineno = 0
|
||||
bb.data.setVar('FILE', fn, data)
|
||||
while 1:
|
||||
lineno = lineno + 1
|
||||
s = f.readline()
|
||||
if not s: break
|
||||
w = s.strip()
|
||||
if not w: continue # skip empty lines
|
||||
s = s.rstrip()
|
||||
if s[0] == '#': continue # skip comments
|
||||
while s[-1] == '\\':
|
||||
s2 = f.readline()[:-1].strip()
|
||||
lineno = lineno + 1
|
||||
s = s[:-1] + s2
|
||||
feeder(lineno, s, fn, data)
|
||||
|
||||
if oldfile:
|
||||
bb.data.setVar('FILE', oldfile, data)
|
||||
return data
|
||||
|
||||
def feeder(lineno, s, fn, data = bb.data.init()):
|
||||
m = __config_regexp__.match(s)
|
||||
if m:
|
||||
groupd = m.groupdict()
|
||||
key = groupd["var"]
|
||||
if "exp" in groupd and groupd["exp"] != None:
|
||||
bb.data.setVarFlag(key, "export", 1, data)
|
||||
if "ques" in groupd and groupd["ques"] != None:
|
||||
val = bb.data.getVar(key, data)
|
||||
if val == None:
|
||||
val = groupd["value"]
|
||||
elif "colon" in groupd and groupd["colon"] != None:
|
||||
val = bb.data.expand(groupd["value"], data)
|
||||
elif "append" in groupd and groupd["append"] != None:
|
||||
val = "%s %s" % ((bb.data.getVar(key, data) or ""), groupd["value"])
|
||||
elif "prepend" in groupd and groupd["prepend"] != None:
|
||||
val = "%s %s" % (groupd["value"], (bb.data.getVar(key, data) or ""))
|
||||
elif "postdot" in groupd and groupd["postdot"] != None:
|
||||
val = "%s%s" % ((bb.data.getVar(key, data) or ""), groupd["value"])
|
||||
elif "predot" in groupd and groupd["predot"] != None:
|
||||
val = "%s%s" % (groupd["value"], (bb.data.getVar(key, data) or ""))
|
||||
else:
|
||||
val = groupd["value"]
|
||||
if 'flag' in groupd and groupd['flag'] != None:
|
||||
# bb.note("setVarFlag(%s, %s, %s, data)" % (key, groupd['flag'], val))
|
||||
bb.data.setVarFlag(key, groupd['flag'], val, data)
|
||||
else:
|
||||
bb.data.setVar(key, val, data)
|
||||
return
|
||||
|
||||
m = __include_regexp__.match(s)
|
||||
if m:
|
||||
s = bb.data.expand(m.group(1), data)
|
||||
# debug(2, "CONF %s:%d: including %s" % (fn, lineno, s))
|
||||
include(fn, s, data)
|
||||
return
|
||||
|
||||
raise ParseError("%s:%d: unparsed line: '%s'" % (fn, lineno, s));
|
||||
|
||||
# Add us to the handlers list
|
||||
from bb.parse import handlers
|
||||
handlers.append({'supports': supports, 'handle': handle, 'init': init})
|
||||
del handlers
|
||||
Binary file not shown.
@@ -0,0 +1,32 @@
|
||||
#!/usr/bin/env python
|
||||
# ex:ts=4:sw=4:sts=4:et
|
||||
# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
|
||||
"""
|
||||
BitBake Parsers
|
||||
|
||||
File parsers for the BitBake build tools.
|
||||
|
||||
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 as published by the Free Software
|
||||
Foundation; either version 2 of the License, or (at your option) any later
|
||||
version.
|
||||
|
||||
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., 59 Temple
|
||||
Place, Suite 330, Boston, MA 02111-1307 USA.
|
||||
|
||||
Based on functions from the base bb module, Copyright 2003 Holger Schurig
|
||||
"""
|
||||
__version__ = '1.0'
|
||||
|
||||
__all__ = [ 'ConfHandler', 'BBHandler']
|
||||
|
||||
import ConfHandler
|
||||
import BBHandler
|
||||
Binary file not shown.
Reference in New Issue
Block a user