@@ -720,6 +720,10 @@ overview of their function and contents.
pressure on the system. Monitor the varying value after ``Mem:`` above
to set a sensible value.
+ :term:`__BB_RECIPE_FILE`
+ Specifies the name of the recipe file that is being parsed. This is the
+ same even if when evalated in a bbappend, include or bbclass file.
+
:term:`BB_RUNFMT`
Specifies the name of the executable script files (i.e. run files)
saved into ``${``\ :term:`T`\ ``}``. By default, the
@@ -512,6 +512,8 @@ class CookerDataBuilder(object):
bb_data.setVar("__BBMULTICONFIG", mc)
bb_data.setVar("FILE_LAYERNAME", layername)
+ bb_data.setVar("__BB_RECIPE_FILE", bbfile)
+
bbfile_loc = os.path.abspath(os.path.dirname(bbfile))
bb.parse.cached_mtime_noerror(bbfile_loc)
new file mode 100644
@@ -0,0 +1,5 @@
+# At least one task is required for bitbake to parse
+do_fetch() {
+ :
+}
+addtask do_fetch
new file mode 100644
@@ -0,0 +1,2 @@
+BBCLASS_RECIPE_FILE := "${@os.path.basename(d.getVar('__BB_RECIPE_FILE'))}"
+BBCLASS_FILE := "${@os.path.basename(d.getVar('FILE'))}"
new file mode 100644
@@ -0,0 +1,15 @@
+CACHE = "${TOPDIR}/cache"
+THISDIR = "${@os.path.dirname(d.getVar('FILE'))}"
+COREBASE := "${@os.path.normpath(os.path.dirname(d.getVar('FILE')+'/../../'))}"
+EXTRA_BBFILES ?= ""
+BBFILES = "${COREBASE}/recipes/*.bb ${COREBASE}/recipes/*.bbappend ${EXTRA_BBFILES}"
+PROVIDES = "${PN}"
+PN = "${@bb.parse.vars_from_file(d.getVar('FILE', False),d)[0]}"
+PF = "${BB_CURRENT_MC}:${PN}"
+export PATH
+TMPDIR ??= "${TOPDIR}"
+STAMP = "${TMPDIR}/stamps/${PN}"
+T = "${TMPDIR}/workdir/${PN}/temp"
+BB_NUMBER_THREADS = "4"
+
+BB_BASEHASH_IGNORE_VARS = "BB_CURRENT_MC BB_HASHSERVE TMPDIR TOPDIR SLOWTASKS SSTATEVALID FILE BB_CURRENTTASK"
@@ -11,6 +11,8 @@ import tempfile
import logging
import bb
import os
+import subprocess
+import textwrap
logger = logging.getLogger('BitBake.TestParse')
@@ -210,7 +212,7 @@ python () {
#
# Test based upon a real world data corruption issue. One
# data store changing a variable poked through into a different data
- # store. This test case replicates that issue where the value 'B' would
+ # store. This test case replicates that issue where the value 'B' would
# become unset/disappear.
#
def test_parse_classextend_contamination(self):
@@ -508,3 +510,131 @@ EXTRA_OECONF:append = " foobar"
test_helper("require some3.conf", " foobar")
test_helper("include_all some.conf", " bar foo")
test_helper("include_all some3.conf", " foobar")
+
+ def test_file_variables(self):
+ # Tests the values of FILE and __BB_RECIPE_FILE in different
+ # combinations of bbappends, includes, and inherits
+
+ def write_file(path, data):
+ with open(path, "w") as f:
+ f.write(textwrap.dedent(data))
+
+ def run_bitbake(cmd, builddir, extraenv={}):
+ env = os.environ.copy()
+ env["BBPATH"] = os.path.realpath(os.path.join(os.path.dirname(__file__), "parse-tests"))
+ env["BB_ENV_PASSTHROUGH_ADDITIONS"] = "TOPDIR"
+ env["TOPDIR"] = builddir
+ for k, v in extraenv.items():
+ env[k] = v
+ env["BB_ENV_PASSTHROUGH_ADDITIONS"] = env["BB_ENV_PASSTHROUGH_ADDITIONS"] + " " + k
+ try:
+ return subprocess.check_output(cmd, env=env, stderr=subprocess.STDOUT, universal_newlines=True, cwd=builddir)
+ except subprocess.CalledProcessError as e:
+ self.fail("Command %s failed with %s" % (cmd, e.output))
+
+ with tempfile.TemporaryDirectory(prefix="parserecipes") as recipes, tempfile.TemporaryDirectory(prefix="parsetest") as builddir:
+ extraenv = {
+ "EXTRA_BBFILES": f"{recipes}/*.bb {recipes}/*.bbappend",
+ }
+
+ inc_path = f"{recipes}/recipe-file.inc"
+ bbappend_path = f"{recipes}/recipe-%.bbappend"
+ recipe_path = f"{recipes}/recipe-file1.bb"
+
+ # __BB_RECIPE_FILE should always be the name of .bb file, even
+ # when set in a bbappend. FILE is the name of the bbappend
+ write_file(recipe_path, "")
+ write_file(bbappend_path,
+ """\
+ BBAPPEND_RECIPE_FILE := "${@os.path.basename(d.getVar('__BB_RECIPE_FILE'))}"
+ BBAPPEND_FILE := "${@os.path.basename(d.getVar('FILE'))}"
+ """
+ )
+ output = run_bitbake(["bitbake", "-e", "recipe-file1"], builddir, extraenv).splitlines()
+ self.assertIn('BBAPPEND_FILE="recipe-%.bbappend"', output)
+ self.assertIn(f'BBAPPEND_RECIPE_FILE="recipe-file1.bb"', output)
+
+ # __BB_RECIPE_FILE should always be the name of .bb file, even when
+ # set in an include file. FILE is the name of the include
+ write_file(recipe_path,
+ """\
+ require recipe-file.inc
+ """
+ )
+ write_file(inc_path,
+ """\
+ INC_RECIPE_FILE := "${@os.path.basename(d.getVar('__BB_RECIPE_FILE'))}"
+ INC_FILE := "${@os.path.basename(d.getVar('FILE'))}"
+ """
+ )
+ output = run_bitbake(["bitbake", "-e", "recipe-file1"], builddir, extraenv).splitlines()
+ self.assertIn('INC_FILE="recipe-file.inc"', output)
+ self.assertIn(f'INC_RECIPE_FILE="recipe-file1.bb"', output)
+
+ # Test when the include file is included from a bbappend
+ write_file(recipe_path, "")
+ write_file(bbappend_path,
+ """\
+ require recipe-file.inc
+ """
+ )
+ output = run_bitbake(["bitbake", "-e", "recipe-file1"], builddir, extraenv).splitlines()
+ self.assertIn('INC_FILE="recipe-file.inc"', output)
+ self.assertIn(f'INC_RECIPE_FILE="recipe-file1.bb"', output)
+
+ # Test the variables in a bbclass when inherited directly in the
+ # recipe. Note that FILE still refers to the recipe in a bbclass
+ write_file(recipe_path,
+ """\
+ inherit recipe-file-class
+ """
+ )
+ output = run_bitbake(["bitbake", "-e", "recipe-file1"], builddir, extraenv).splitlines()
+ self.assertIn('BBCLASS_FILE="recipe-file1.bb"', output)
+ self.assertIn(f'BBCLASS_RECIPE_FILE="recipe-file1.bb"', output)
+
+ # Test the variables when the inherit is in a bbappend. In this
+ # case, FILE is the bbappend
+ write_file(recipe_path, "")
+ write_file(bbappend_path,
+ """\
+ inherit recipe-file-class
+ """
+ )
+ output = run_bitbake(["bitbake", "-e", "recipe-file1"], builddir, extraenv).splitlines()
+ self.assertIn('BBCLASS_FILE="recipe-%.bbappend"', output)
+ self.assertIn(f'BBCLASS_RECIPE_FILE="recipe-file1.bb"', output)
+
+ # Test the variables when the inherit is in a include. In this
+ # case, FILE is the include file
+ write_file(recipe_path,
+ """\
+ require recipe-file.inc
+ """
+ )
+ write_file(bbappend_path, "")
+ write_file(inc_path,
+ """\
+ inherit recipe-file-class
+ """
+ )
+ output = run_bitbake(["bitbake", "-e", "recipe-file1"], builddir, extraenv).splitlines()
+ self.assertIn('BBCLASS_FILE="recipe-file.inc"', output)
+ self.assertIn(f'BBCLASS_RECIPE_FILE="recipe-file1.bb"', output)
+
+ # Test the variables when the inherit is in a include included from
+ # a bbappend. In this case, FILE is the include file
+ write_file(recipe_path, "")
+ write_file(bbappend_path,
+ """\
+ require recipe-file.inc
+ """
+ )
+ write_file(inc_path,
+ """\
+ inherit recipe-file-class
+ """
+ )
+ output = run_bitbake(["bitbake", "-e", "recipe-file1"], builddir, extraenv).splitlines()
+ self.assertIn('BBCLASS_FILE="recipe-file.inc"', output)
+ self.assertIn(f'BBCLASS_RECIPE_FILE="recipe-file1.bb"', output)