Skip to content

Commit

Permalink
Merge pull request #577 from rhubert/rh-metaenv-substitution
Browse files Browse the repository at this point in the history
input: apply env substitution to metaEnvironment
  • Loading branch information
jkloetzke committed Aug 1, 2024
2 parents d59abec + 227e0a6 commit e3cee03
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 16 deletions.
5 changes: 2 additions & 3 deletions doc/manual/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
21 changes: 12 additions & 9 deletions pym/bob/input.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
8 changes: 4 additions & 4 deletions test/unit/test_input_recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -691,8 +691,8 @@ def testMergeEnvironment(self):
"C" : "<lib><b>",
})

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" : {
Expand Down Expand Up @@ -721,7 +721,7 @@ def testMetaEnvrionmentNoSubstitution(self):
}
p = self.parseAndPrepare(recipe, classes, env=env).getPackageStep()
self.assertEqual(p.getEnv(), {
"A" : "<lib>${A:-}",
"B" : "<lib>${B:-}",
"A" : "<lib>a",
"B" : "<lib>b",
"C" : "<b>",
})

0 comments on commit e3cee03

Please sign in to comment.