summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/bb/tests/parse.py
diff options
context:
space:
mode:
Diffstat (limited to 'bitbake/lib/bb/tests/parse.py')
-rw-r--r--bitbake/lib/bb/tests/parse.py137
1 files changed, 130 insertions, 7 deletions
diff --git a/bitbake/lib/bb/tests/parse.py b/bitbake/lib/bb/tests/parse.py
index ee7f2534f1..72d1962e7e 100644
--- a/bitbake/lib/bb/tests/parse.py
+++ b/bitbake/lib/bb/tests/parse.py
@@ -186,14 +186,16 @@ deltask ${EMPTYVAR}
"""
def test_parse_addtask_deltask(self):
import sys
- f = self.parsehelper(self.addtask_deltask)
- d = bb.parse.handle(f.name, self.d)['']
- stdout = sys.stdout.getvalue()
- self.assertTrue("addtask contained multiple 'before' keywords" in stdout)
- self.assertTrue("addtask contained multiple 'after' keywords" in stdout)
- self.assertTrue('addtask ignored: " do_patch"' in stdout)
- #self.assertTrue('dependent task do_foo for do_patch does not exist' in stdout)
+ with self.assertLogs() as logs:
+ f = self.parsehelper(self.addtask_deltask)
+ d = bb.parse.handle(f.name, self.d)['']
+
+ output = "".join(logs.output)
+ self.assertTrue("addtask contained multiple 'before' keywords" in output)
+ self.assertTrue("addtask contained multiple 'after' keywords" in output)
+ self.assertTrue('addtask ignored: " do_patch"' in output)
+ #self.assertTrue('dependent task do_foo for do_patch does not exist' in output)
broken_multiline_comment = """
# First line of comment \\
@@ -218,3 +220,124 @@ VAR = " \\
with self.assertRaises(bb.BBHandledException):
d = bb.parse.handle(f.name, self.d)['']
+
+ at_sign_in_var_flag = """
+A[flag@.service] = "nonet"
+B[flag@.target] = "ntb"
+C[f] = "flag"
+
+unset A[flag@.service]
+"""
+ def test_parse_at_sign_in_var_flag(self):
+ f = self.parsehelper(self.at_sign_in_var_flag)
+ d = bb.parse.handle(f.name, self.d)['']
+ self.assertEqual(d.getVar("A"), None)
+ self.assertEqual(d.getVar("B"), None)
+ self.assertEqual(d.getVarFlag("A","flag@.service"), None)
+ self.assertEqual(d.getVarFlag("B","flag@.target"), "ntb")
+ self.assertEqual(d.getVarFlag("C","f"), "flag")
+
+ def test_parse_invalid_at_sign_in_var_flag(self):
+ invalid_at_sign = self.at_sign_in_var_flag.replace("B[f", "B[@f")
+ f = self.parsehelper(invalid_at_sign)
+ with self.assertRaises(bb.parse.ParseError):
+ d = bb.parse.handle(f.name, self.d)['']
+
+ export_function_recipe = """
+inherit someclass
+"""
+
+ export_function_recipe2 = """
+inherit someclass
+
+do_compile () {
+ false
+}
+
+python do_compilepython () {
+ bb.note("Something else")
+}
+
+"""
+ export_function_class = """
+someclass_do_compile() {
+ true
+}
+
+python someclass_do_compilepython () {
+ bb.note("Something")
+}
+
+EXPORT_FUNCTIONS do_compile do_compilepython
+"""
+
+ export_function_class2 = """
+secondclass_do_compile() {
+ true
+}
+
+python secondclass_do_compilepython () {
+ bb.note("Something")
+}
+
+EXPORT_FUNCTIONS do_compile do_compilepython
+"""
+
+ def test_parse_export_functions(self):
+ def check_function_flags(d):
+ self.assertEqual(d.getVarFlag("do_compile", "func"), 1)
+ self.assertEqual(d.getVarFlag("do_compilepython", "func"), 1)
+ self.assertEqual(d.getVarFlag("do_compile", "python"), None)
+ self.assertEqual(d.getVarFlag("do_compilepython", "python"), "1")
+
+ with tempfile.TemporaryDirectory() as tempdir:
+ self.d.setVar("__bbclasstype", "recipe")
+ recipename = tempdir + "/recipe.bb"
+ os.makedirs(tempdir + "/classes")
+ with open(tempdir + "/classes/someclass.bbclass", "w") as f:
+ f.write(self.export_function_class)
+ f.flush()
+ with open(tempdir + "/classes/secondclass.bbclass", "w") as f:
+ f.write(self.export_function_class2)
+ f.flush()
+
+ with open(recipename, "w") as f:
+ f.write(self.export_function_recipe)
+ f.flush()
+ os.chdir(tempdir)
+ d = bb.parse.handle(recipename, bb.data.createCopy(self.d))['']
+ self.assertIn("someclass_do_compile", d.getVar("do_compile"))
+ self.assertIn("someclass_do_compilepython", d.getVar("do_compilepython"))
+ check_function_flags(d)
+
+ recipename2 = tempdir + "/recipe2.bb"
+ with open(recipename2, "w") as f:
+ f.write(self.export_function_recipe2)
+ f.flush()
+
+ d = bb.parse.handle(recipename2, bb.data.createCopy(self.d))['']
+ self.assertNotIn("someclass_do_compile", d.getVar("do_compile"))
+ self.assertNotIn("someclass_do_compilepython", d.getVar("do_compilepython"))
+ self.assertIn("false", d.getVar("do_compile"))
+ self.assertIn("else", d.getVar("do_compilepython"))
+ check_function_flags(d)
+
+ with open(recipename, "a+") as f:
+ f.write("\ninherit secondclass\n")
+ f.flush()
+ with open(recipename2, "a+") as f:
+ f.write("\ninherit secondclass\n")
+ f.flush()
+
+ d = bb.parse.handle(recipename, bb.data.createCopy(self.d))['']
+ self.assertIn("secondclass_do_compile", d.getVar("do_compile"))
+ self.assertIn("secondclass_do_compilepython", d.getVar("do_compilepython"))
+ check_function_flags(d)
+
+ d = bb.parse.handle(recipename2, bb.data.createCopy(self.d))['']
+ self.assertNotIn("someclass_do_compile", d.getVar("do_compile"))
+ self.assertNotIn("someclass_do_compilepython", d.getVar("do_compilepython"))
+ self.assertIn("false", d.getVar("do_compile"))
+ self.assertIn("else", d.getVar("do_compilepython"))
+ check_function_flags(d)
+