diff --git a/doc/manual/configuration.rst b/doc/manual/configuration.rst index 069c438d..ff474397 100644 --- a/doc/manual/configuration.rst +++ b/doc/manual/configuration.rst @@ -1532,9 +1532,8 @@ metaEnvironment Type: Dictionary (String -> String) metaEnvironment variables behave like :ref:`configuration-recipes-privateenv` variables. -They overrule other environment variables and can be used in all steps, but substitution is not -available. In addition all metaEnvironment variables are added to the audit no matter they are -used in a step or not. +They overrule other environment variables and can be used in all steps. In addition all +metaEnvironment variables are added to the audit no matter they are used in a step or not. This predestines metaEnvironment variables to add the license type or version of a package. The :ref:`manpage-query-meta` command can be used to retrieve metaEnvironment variables. diff --git a/pym/bob/input.py b/pym/bob/input.py index 1658924a..5c393721 100644 --- a/pym/bob/input.py +++ b/pym/bob/input.py @@ -1480,10 +1480,10 @@ def refDeref(self, stack, inputTools, inputSandbox, pathFormatter, cache=None): class CorePackage: __slots__ = ("recipe", "internalRef", "directDepSteps", "indirectDepSteps", "states", "tools", "sandbox", "checkoutStep", "buildStep", "packageStep", - "pkgId", "fingerprintMask") + "pkgId", "fingerprintMask", "metaEnv") def __init__(self, recipe, tools, diffTools, sandbox, diffSandbox, - directDepSteps, indirectDepSteps, states, pkgId, fingerprintMask): + directDepSteps, indirectDepSteps, states, pkgId, fingerprintMask, metaEnv): self.recipe = recipe self.tools = tools self.sandbox = sandbox @@ -1493,6 +1493,7 @@ def __init__(self, recipe, tools, diffTools, sandbox, diffSandbox, self.states = states self.pkgId = pkgId self.fingerprintMask = fingerprintMask + self.metaEnv = metaEnv def refDeref(self, stack, inputTools, inputSandbox, pathFormatter): tools, sandbox = self.internalRef.refDeref(stack, inputTools, inputSandbox, pathFormatter) @@ -1527,6 +1528,9 @@ def getName(self): """Name of the package""" return self.recipe.getPackageName() + def getMetaEnv(self): + return self.metaEnv + @property def jobServer(self): return self.recipe.jobServer() @@ -1583,7 +1587,7 @@ def getName(self): def getMetaEnv(self): """meta variables of package""" - return self.getRecipe().getMetaEnv() + return self.__corePackage.getMetaEnv() def getStack(self): """Returns the recipe processing stack leading to this package. @@ -2227,9 +2231,6 @@ def getName(self): """ return self.__baseName - def getMetaEnv(self): - return self.__metaEnv - def isRoot(self): """Returns True if this is a root recipe.""" return self.__root == True @@ -2488,8 +2489,10 @@ def prepare(self, inputEnv, sandboxEnabled, inputStates, inputSandbox=None, env = env.derive({ key : env.substitute(value, "privateEnvironment::"+key) for key, value in i.items() }) - # meta variables override existing variables but can not be substituted - env.update(self.__metaEnv) + # meta variables override existing variables + metaEnv = { key : env.substitute(value, "metaEnvironment::"+key) + for key, value in self.__metaEnv.items() } + env.update(metaEnv) # set fixed built-in variables env['BOB_RECIPE_NAME'] = self.__baseName @@ -2533,7 +2536,7 @@ def prepare(self, inputEnv, sandboxEnabled, inputStates, inputSandbox=None, # touchedTools = tools.touchedKeys() # diffTools = { n : t for n,t in diffTools.items() if n in touchedTools } p = CorePackage(self, toolsDetached, diffTools, sandbox, diffSandbox, - directPackages, indirectPackages, states, uidGen(), doFingerprint) + directPackages, indirectPackages, states, uidGen(), doFingerprint, metaEnv) # optional checkout step if self.__checkout != (None, None, None) or self.__checkoutSCMs or self.__checkoutAsserts: diff --git a/test/unit/test_input_recipe.py b/test/unit/test_input_recipe.py index 7a0f68c2..d5c83a97 100644 --- a/test/unit/test_input_recipe.py +++ b/test/unit/test_input_recipe.py @@ -691,8 +691,8 @@ def testMergeEnvironment(self): "C" : "", }) - def testMetaEnvrionmentNoSubstitution(self): - """metaEnvironment values are not substituted but merged on a key-by-key basis""" + def testMetaEnvrionmentSubstitution(self): + """metaEnvironment is substituted and merged on a key-by-key basis""" recipe = { "inherit" : ["a", "b"], "metaEnvironment" : { @@ -721,7 +721,7 @@ def testMetaEnvrionmentNoSubstitution(self): } p = self.parseAndPrepare(recipe, classes, env=env).getPackageStep() self.assertEqual(p.getEnv(), { - "A" : "${A:-}", - "B" : "${B:-}", + "A" : "a", + "B" : "b", "C" : "", })