From 1d2b032026e6276cbb6e0f41f078c784e0d97fed Mon Sep 17 00:00:00 2001 From: Ralf Hubert Date: Thu, 24 Oct 2024 08:32:55 +0200 Subject: [PATCH] input: add substituteMetaEnvFail policy Since 227e0a66 substiution is applied to metaEnv variables. For older recipes this might fail if the string can't be substituted. Add a policy to make the new bob useable on old recipes as well. --- doc/manual/policies.rst | 15 +++++++++++++++ pym/bob/input.py | 9 ++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/doc/manual/policies.rst b/doc/manual/policies.rst index 38e8fc36..f2425299 100644 --- a/doc/manual/policies.rst +++ b/doc/manual/policies.rst @@ -272,6 +272,21 @@ New behavior The ``fileMode`` attribute is default initialized to ``0600``. All files will get the same mode, regardless of the URL schema. +substituteMetaEnvFail +~~~~~~~~~~~~~~~~~~~~~ + +Introduced in: 0.25 + +Starting with Bob 0.25, string substitution is applied on metaEnvironment. This +policy controls the behavior if the substitution fails. + +Old behavior + Try to apply substitution. If it fails issue a warning and return the + original string. + +New behavior + Apply substitution and raise a parse error on failures. + .. _policies-obsolete: Obsolete policies diff --git a/pym/bob/input.py b/pym/bob/input.py index 1b6b8d78..81a63088 100644 --- a/pym/bob/input.py +++ b/pym/bob/input.py @@ -2510,7 +2510,8 @@ 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) + metaEnv = { key : env.substitute(value, "metaEnvironment::"+key, + fail=self.__recipeSet.getPolicy('substituteMetaEnvFail')) for key, value in self.__metaEnv.items() } env.update(metaEnv) @@ -2999,6 +3000,7 @@ class RecipeSet: schema.Optional('gitCommitOnBranch') : bool, schema.Optional('fixImportScmVariant') : bool, schema.Optional('defaultFileMode') : bool, + schema.Optional('substituteMetaEnvFail') : bool, }, error="Invalid policy specified! Are you using an appropriate version of Bob?" ), @@ -3043,6 +3045,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.") ), + "substituteMetaEnvFail": ( + "0.25rc1", + InfoOnce("substituteMetaEnvFail is not set. MetaEnv will not be substituted if substitution failes.", + help="See http://bob-build-tool.readthedocs.io/en/latest/manual/policies.html#substituteMetaEnvFail for more information.") + ) } _ignoreCmdConfig = False