Skip to content

Commit

Permalink
Merge pull request #594 from rhubert/rh-metaEnvNoFail
Browse files Browse the repository at this point in the history
input: add substituteMetaEnv policy
  • Loading branch information
jkloetzke authored Oct 24, 2024
2 parents 30ae46e + 3834cfb commit c6d05b5
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 5 deletions.
4 changes: 4 additions & 0 deletions doc/manual/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1567,6 +1567,10 @@ This predestines metaEnvironment variables to add the license type or version of

The :ref:`manpage-query-meta` command can be used to retrieve metaEnvironment variables.

All metaEnvironment variables are subject to :ref:`string substitution
<configuration-principle-subst>`, unless the :ref:`policies-substituteMetaEnv`
policy is configured for the old behaviour.

multiPackage
~~~~~~~~~~~~

Expand Down
18 changes: 18 additions & 0 deletions doc/manual/policies.rst
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,24 @@ New behavior
The ``fileMode`` attribute is default initialized to ``0600``. All files
will get the same mode, regardless of the URL schema.

.. _policies-substituteMetaEnv:

substituteMetaEnv
~~~~~~~~~~~~~~~~~

Introduced in: 0.25

Bob versions 0.24 and before did not apply string substitution to
:ref:`configuration-recipes-metaenv` variables. Starting with Bob 0.25, regular
string substitution is performed. Because older recipes might contain
characters that need quoting, the substitution is subject to this policy.

Old behavior
No substitution is applied to :ref:`configuration-recipes-metaenv` variables.

New behavior
Apply string substitution to ``metaEnvironment`` variables.

.. _policies-obsolete:

Obsolete policies
Expand Down
13 changes: 11 additions & 2 deletions pym/bob/input.py
Original file line number Diff line number Diff line change
Expand Up @@ -2510,8 +2510,11 @@ def prepare(self, inputEnv, sandboxEnabled, inputStates, inputSandbox=None,
for key, value in i.items() })

# meta variables override existing variables
metaEnv = { key : env.substitute(value, "metaEnvironment::"+key)
for key, value in self.__metaEnv.items() }
if self.__recipeSet.getPolicy('substituteMetaEnv'):
metaEnv = { key : env.substitute(value, "metaEnvironment::"+key)
for key, value in self.__metaEnv.items() }
else:
metaEnv = self.__metaEnv
env.update(metaEnv)

# set fixed built-in variables
Expand Down Expand Up @@ -2999,6 +3002,7 @@ class RecipeSet:
schema.Optional('gitCommitOnBranch') : bool,
schema.Optional('fixImportScmVariant') : bool,
schema.Optional('defaultFileMode') : bool,
schema.Optional('substituteMetaEnv') : bool,
},
error="Invalid policy specified! Are you using an appropriate version of Bob?"
),
Expand Down Expand Up @@ -3043,6 +3047,11 @@ class RecipeSet:
InfoOnce("defaultFileMode policy not set. File mode of URL SCMs not set for locally copied files.",
help="See http://bob-build-tool.readthedocs.io/en/latest/manual/policies.html#defaultfilemode for more information.")
),
"substituteMetaEnv": (
"0.25rc1",
InfoOnce("substituteMetaEnv policy is not set. MetaEnv will not be substituted.",
help="See http://bob-build-tool.readthedocs.io/en/latest/manual/policies.html#substitutemetaenv for more information.")
)
}

_ignoreCmdConfig = False
Expand Down
23 changes: 20 additions & 3 deletions test/unit/test_input_recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,13 +194,13 @@ def applyRecipeDefaults(self, recipe):
r.setdefault("checkoutUpdateIf", False)
return r

def parseAndPrepare(self, recipe, classes={}, name="foo", env={}):
def parseAndPrepare(self, recipe, classes={}, name="foo", env={}, policies={}):

cwd = os.getcwd()
recipeSet = MagicMock()
recipeSet.loadBinary = MagicMock()
recipeSet.scriptLanguage = self.SCRIPT_LANGUAGE
recipeSet.getPolicy = lambda x: None
recipeSet.getPolicy = lambda x: policies.get(x)

cc = { n : Recipe(recipeSet, self.applyRecipeDefaults(r), "", n+".yaml",
cwd, n, n, {}, False)
Expand Down Expand Up @@ -691,6 +691,20 @@ def testMergeEnvironment(self):
"C" : "<lib><b>",
})

def testMetaEnvironmentLegacy(self):
"""Pre 0.25 versions did not apply substitution in metaEnvironment"""
recipe = {
"metaEnvironment" : {
"A" : "$A",
"B" : "$B'",
},
}
pkg = self.parseAndPrepare(recipe)
self.assertEqual(pkg.getMetaEnv(), {
"A" : "$A",
"B" : "$B'",
})

def testMetaEnvrionmentSubstitution(self):
"""metaEnvironment is substituted and merged on a key-by-key basis"""
recipe = {
Expand Down Expand Up @@ -719,7 +733,10 @@ def testMetaEnvrionmentSubstitution(self):
"A" : "a",
"B" : "b",
}
p = self.parseAndPrepare(recipe, classes, env=env).getPackageStep()
policies = {
"substituteMetaEnv" : True,
}
p = self.parseAndPrepare(recipe, classes, env=env, policies=policies).getPackageStep()
self.assertEqual(p.getEnv(), {
"A" : "<lib>a",
"B" : "<lib>b",
Expand Down

0 comments on commit c6d05b5

Please sign in to comment.