From c69a1aed4a8bf23161c9043765a46daa80320354 Mon Sep 17 00:00:00 2001 From: Richard Purdie Date: Tue, 5 Aug 2025 13:40:57 -0600 Subject: bitbake: data_smart: Add setVarFilter function to implement variabl filtering Adds a new setVarFilter() API to the data store allowing filters to be applied to variables. Note that filters are applied to the non-override part of the variable name so a filter set against RDEPENDS would apply against RDEPENDS:${PN} and friends. The filter function is applied before returning the final variable value. (Bitbake rev: a9471c10d1de039474ddb4738abd286b928d82f4) Signed-off-by: Joshua Watt Signed-off-by: Richard Purdie --- bitbake/lib/bb/data_smart.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'bitbake/lib/bb') diff --git a/bitbake/lib/bb/data_smart.py b/bitbake/lib/bb/data_smart.py index 8e7dd98384..2e0d308588 100644 --- a/bitbake/lib/bb/data_smart.py +++ b/bitbake/lib/bb/data_smart.py @@ -24,6 +24,7 @@ from collections.abc import MutableMapping import logging import hashlib import bb, bb.codeparser +import bb.filter from bb import utils from bb.COW import COWDictBase @@ -427,6 +428,7 @@ class DataSmart(MutableMapping): self.inchistory = IncludeHistory() self.varhistory = VariableHistory(self) + self.filters = {} self._tracking = False self._var_renames = {} self._var_renames.update(bitbake_renamed_vars) @@ -678,6 +680,7 @@ class DataSmart(MutableMapping): srcflags = self.getVarFlags(key, False, True) or {} for i in srcflags: + if i not in (__setvar_keyword__): continue src = srcflags[i] @@ -895,6 +898,12 @@ class DataSmart(MutableMapping): if expand: value = parser.value + if value and expand and flag == "_content": + basevar = var.split(":")[0] + if basevar in self.filters: + value = bb.filter.apply_filters(value, [self.filters[basevar],]) + parser.value = value + if parser: self.expand_cache[cachename] = parser @@ -1000,6 +1009,7 @@ class DataSmart(MutableMapping): data.varhistory = self.varhistory.copy() data.varhistory.dataroot = data data.inchistory = self.inchistory.copy() + data.filters = self.filters.copy() data._tracking = self._tracking data._var_renames = self._var_renames @@ -1028,6 +1038,15 @@ class DataSmart(MutableMapping): if referrervalue and isinstance(referrervalue, str) and ref in referrervalue: self.setVar(key, referrervalue.replace(ref, value)) + def setVarFilter(self, var, filter): + if filter: + self.filters[var] = filter + else: + try: + del self.filters[var] + except KeyError: + pass + def localkeys(self): for key in self.dict: if key not in ['_data']: -- cgit v1.2.3-54-g00ecf