Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

input: apply env substitution to metaEnvironment #577

Merged
merged 1 commit into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>",
})
Loading