From c38517df8398cbe87fec1431bc799d3ccf34c79e Mon Sep 17 00:00:00 2001 From: Benedikt Niedermayr Date: Thu, 10 Nov 2022 13:46:45 +0100 Subject: [PATCH] add conditional environment variables Until now all environment variables in the kas config's env section require a default value. In some cases we want to rely on the weak assignment of bitbake instead of relying on the default value of the variable in the kas config. This means if we assign the 'None' value or nothing to the variable in the kas config then it is only added to BB_ENV_EXTRAWHITE or BB_ENV_PASSTHROUGH_ADDITIONS without setting it as environment variable. Signed-off-by: Benedikt Niedermayr [Jan: fixed overlong line] Signed-off-by: Jan Kiszka --- docs/format-changelog.rst | 9 +++++++++ docs/userguide.rst | 11 ++++++++--- kas/__version__.py | 2 +- kas/libkas.py | 3 +++ kas/schema-kas.json | 2 +- 5 files changed, 22 insertions(+), 5 deletions(-) diff --git a/docs/format-changelog.rst b/docs/format-changelog.rst index c8a7218..23c5380 100644 --- a/docs/format-changelog.rst +++ b/docs/format-changelog.rst @@ -121,3 +121,12 @@ Added - For repositories, ``url`` and ``path`` can now be overridden with a null-value to switch between version-controlled repositories and unversioned local folders. + +Version 13 +---------- + +Added +~~~~~ + +- Variables used in the ``env`` section can now be assigned 'None' as value. In + this case the variables are only exported to the bb env whitelist. diff --git a/docs/userguide.rst b/docs/userguide.rst index 6c058f1..a8c72ea 100644 --- a/docs/userguide.rst +++ b/docs/userguide.rst @@ -354,9 +354,14 @@ Configuration reference should be specified via the environment variable. * ``env``: dict [optional] - Contains environment variable names with the default values. These - variables are made available to bitbake via ``BB_ENV_EXTRAWHITE`` and can - be overwritten by the variables of the environment in which kas is started. + Contains environment variable names with either default values or None. + These variables are made available to bitbake via ``BB_ENV_EXTRAWHITE`` + and can be overwritten by the variables of the environment in which + kas is started. + Either a string or nothing (None) can be assigned as value. + The former one serves as a default value whereas the latter one will lead + to add the variable only to ``BB_ENV_EXTRAWHITE`` and not to the + environment where kas is started. * ``task``: string [optional] Contains the task to build by bitbake. Can be overwritten by the diff --git a/kas/__version__.py b/kas/__version__.py index cf3ffa3..e7bf1f3 100644 --- a/kas/__version__.py +++ b/kas/__version__.py @@ -28,5 +28,5 @@ __copyright__ = 'Copyright (c) Siemens AG, 2017-2020' __version__ = '3.1' # Please update docs/format-changelog.rst when changing the file version. -__file_version__ = 12 +__file_version__ = 13 __compatible_file_version__ = 1 diff --git a/kas/libkas.py b/kas/libkas.py index 4801d32..3cf2249 100644 --- a/kas/libkas.py +++ b/kas/libkas.py @@ -275,6 +275,9 @@ def get_build_environ(build_system): if env_var in os.environ: env[env_var] = os.environ[env_var] + # filter out 'None' values + env = {k: v for (k, v) in env.items() if v is not None} + return env diff --git a/kas/schema-kas.json b/kas/schema-kas.json index ca4b513..e42a236 100644 --- a/kas/schema-kas.json +++ b/kas/schema-kas.json @@ -94,7 +94,7 @@ "env": { "type": "object", "additionalProperties": { - "type": "string" + "type": ["string", "null"] } }, "target": {