Skip to content

Commit

Permalink
input: add substituteMetaEnv policy
Browse files Browse the repository at this point in the history
Since 227e0a6 substiution is applied to metaEnv variables. For older
recipes this might fail if the string can't be substituted.
  • Loading branch information
rhubert authored and jkloetzke committed Oct 24, 2024
1 parent 30ae46e commit 9420d3b
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 3 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
2 changes: 1 addition & 1 deletion test/unit/test_input_recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ def parseAndPrepare(self, recipe, classes={}, name="foo", env={}):
recipeSet = MagicMock()
recipeSet.loadBinary = MagicMock()
recipeSet.scriptLanguage = self.SCRIPT_LANGUAGE
recipeSet.getPolicy = lambda x: None
recipeSet.getPolicy = lambda x: True if x == "substituteMetaEnv" else None

cc = { n : Recipe(recipeSet, self.applyRecipeDefaults(r), "", n+".yaml",
cwd, n, n, {}, False)
Expand Down

0 comments on commit 9420d3b

Please sign in to comment.