summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJérémy Rosen <jeremy.rosen@smile.fr>2016-08-16 14:04:47 +0200
committerRichard Purdie <richard.purdie@linuxfoundation.org>2016-08-18 10:06:26 +0100
commit0eb6d709b6c38aa27f33d8b0ef977a33350f0d75 (patch)
treef4b503fb079669fdc021f9b7a78f6d814862d7f4
parentb50b14e37249fb23b8e4f3a86f9b245cba85ca86 (diff)
downloadpoky-0eb6d709b6c38aa27f33d8b0ef977a33350f0d75.tar.gz
bitbake: ast/ConfHandler: Add a syntax to clear variable
unset VAR will clear variable VAR unset VAR[flag] will clear flag "flag" from var VAR (Bitbake rev: bedbd46ece8d1285b5cd2ea07dc64b4875b479aa) Signed-off-by: Jérémy Rosen <jeremy.rosen@openwide.fr> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--bitbake/doc/bitbake-user-manual/bitbake-user-manual-metadata.xml17
-rw-r--r--bitbake/lib/bb/parse/ast.py33
-rw-r--r--bitbake/lib/bb/parse/parse_py/ConfHandler.py12
-rw-r--r--bitbake/lib/bb/tests/parse.py17
4 files changed, 79 insertions, 0 deletions
diff --git a/bitbake/doc/bitbake-user-manual/bitbake-user-manual-metadata.xml b/bitbake/doc/bitbake-user-manual/bitbake-user-manual-metadata.xml
index 5df00050ce..64f08157f6 100644
--- a/bitbake/doc/bitbake-user-manual/bitbake-user-manual-metadata.xml
+++ b/bitbake/doc/bitbake-user-manual/bitbake-user-manual-metadata.xml
@@ -435,6 +435,23 @@
435 </para> 435 </para>
436 </section> 436 </section>
437 437
438 <section id='unsetting-variables'>
439 <title>Unseting variables</title>
440
441 <para>
442 It is possible to completely remove a variable or a variable flag
443 from BitBake's internal data dictionary by using the "unset" keyword.
444 Here is an example:
445 <literallayout class='monospaced'>
446 unset DATE
447 unset do_fetch[noexec]
448 </literallayout>
449 These two statements remove the <filename>DATE</filename> and the
450 <filename>do_fetch[noexec]</filename> flag.
451 </para>
452
453 </section>
454
438 <section id='providing-pathnames'> 455 <section id='providing-pathnames'>
439 <title>Providing Pathnames</title> 456 <title>Providing Pathnames</title>
440 457
diff --git a/bitbake/lib/bb/parse/ast.py b/bitbake/lib/bb/parse/ast.py
index 0fc3a9e7a4..d7185b1664 100644
--- a/bitbake/lib/bb/parse/ast.py
+++ b/bitbake/lib/bb/parse/ast.py
@@ -69,6 +69,33 @@ class ExportNode(AstNode):
69 def eval(self, data): 69 def eval(self, data):
70 data.setVarFlag(self.var, "export", 1, op = 'exported') 70 data.setVarFlag(self.var, "export", 1, op = 'exported')
71 71
72class UnsetNode(AstNode):
73 def __init__(self, filename, lineno, var):
74 AstNode.__init__(self, filename, lineno)
75 self.var = var
76
77 def eval(self, data):
78 loginfo = {
79 'variable': self.var,
80 'file': self.filename,
81 'line': self.lineno,
82 }
83 data.delVar(self.var,**loginfo)
84
85class UnsetFlagNode(AstNode):
86 def __init__(self, filename, lineno, var, flag):
87 AstNode.__init__(self, filename, lineno)
88 self.var = var
89 self.flag = flag
90
91 def eval(self, data):
92 loginfo = {
93 'variable': self.var,
94 'file': self.filename,
95 'line': self.lineno,
96 }
97 data.delVarFlag(self.var, self.flag, **loginfo)
98
72class DataNode(AstNode): 99class DataNode(AstNode):
73 """ 100 """
74 Various data related updates. For the sake of sanity 101 Various data related updates. For the sake of sanity
@@ -270,6 +297,12 @@ def handleInclude(statements, filename, lineno, m, force):
270def handleExport(statements, filename, lineno, m): 297def handleExport(statements, filename, lineno, m):
271 statements.append(ExportNode(filename, lineno, m.group(1))) 298 statements.append(ExportNode(filename, lineno, m.group(1)))
272 299
300def handleUnset(statements, filename, lineno, m):
301 statements.append(UnsetNode(filename, lineno, m.group(1)))
302
303def handleUnsetFlag(statements, filename, lineno, m):
304 statements.append(UnsetFlagNode(filename, lineno, m.group(1), m.group(2)))
305
273def handleData(statements, filename, lineno, groupd): 306def handleData(statements, filename, lineno, groupd):
274 statements.append(DataNode(filename, lineno, groupd)) 307 statements.append(DataNode(filename, lineno, groupd))
275 308
diff --git a/bitbake/lib/bb/parse/parse_py/ConfHandler.py b/bitbake/lib/bb/parse/parse_py/ConfHandler.py
index b9712929f3..875250de40 100644
--- a/bitbake/lib/bb/parse/parse_py/ConfHandler.py
+++ b/bitbake/lib/bb/parse/parse_py/ConfHandler.py
@@ -57,6 +57,8 @@ __config_regexp__ = re.compile( r"""
57__include_regexp__ = re.compile( r"include\s+(.+)" ) 57__include_regexp__ = re.compile( r"include\s+(.+)" )
58__require_regexp__ = re.compile( r"require\s+(.+)" ) 58__require_regexp__ = re.compile( r"require\s+(.+)" )
59__export_regexp__ = re.compile( r"export\s+([a-zA-Z0-9\-_+.${}/]+)$" ) 59__export_regexp__ = re.compile( r"export\s+([a-zA-Z0-9\-_+.${}/]+)$" )
60__unset_regexp__ = re.compile( r"unset\s+([a-zA-Z0-9\-_+.${}/]+)$" )
61__unset_flag_regexp__ = re.compile( r"unset\s+([a-zA-Z0-9\-_+.${}/]+)\[([a-zA-Z0-9\-_+.${}/]+)\]$" )
60 62
61def init(data): 63def init(data):
62 topdir = data.getVar('TOPDIR', False) 64 topdir = data.getVar('TOPDIR', False)
@@ -185,6 +187,16 @@ def feeder(lineno, s, fn, statements):
185 ast.handleExport(statements, fn, lineno, m) 187 ast.handleExport(statements, fn, lineno, m)
186 return 188 return
187 189
190 m = __unset_regexp__.match(s)
191 if m:
192 ast.handleUnset(statements, fn, lineno, m)
193 return
194
195 m = __unset_flag_regexp__.match(s)
196 if m:
197 ast.handleUnsetFlag(statements, fn, lineno, m)
198 return
199
188 raise ParseError("unparsed line: '%s'" % s, fn, lineno); 200 raise ParseError("unparsed line: '%s'" % s, fn, lineno);
189 201
190# Add us to the handlers list 202# Add us to the handlers list
diff --git a/bitbake/lib/bb/tests/parse.py b/bitbake/lib/bb/tests/parse.py
index c296db2013..0b2706af02 100644
--- a/bitbake/lib/bb/tests/parse.py
+++ b/bitbake/lib/bb/tests/parse.py
@@ -68,6 +68,23 @@ C = "3"
68 with self.assertRaises(bb.parse.ParseError): 68 with self.assertRaises(bb.parse.ParseError):
69 d = bb.parse.handle(f.name, self.d)[''] 69 d = bb.parse.handle(f.name, self.d)['']
70 70
71 unsettest = """
72A = "1"
73B = "2"
74B[flag] = "3"
75
76unset A
77unset B[flag]
78"""
79
80 def test_parse_unset(self):
81 f = self.parsehelper(self.unsettest)
82 d = bb.parse.handle(f.name, self.d)['']
83 self.assertEqual(d.getVar("A", True), None)
84 self.assertEqual(d.getVarFlag("A","flag", True), None)
85 self.assertEqual(d.getVar("B", True), "2")
86
87
71 overridetest = """ 88 overridetest = """
72RRECOMMENDS_${PN} = "a" 89RRECOMMENDS_${PN} = "a"
73RRECOMMENDS_${PN}_libc = "b" 90RRECOMMENDS_${PN}_libc = "b"