From 65b98448c6501d235ceaa7c29babcae7aebc49d4 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Mon, 13 Sep 2021 17:24:20 +0200 Subject: [PATCH] Add support for defining variables from other variables or basic expression Using this we can now define variables in the variable section using basic expression that are evaluated as f-string. For example, you can use the syntax: ``` "mpp-vars": { "rootfs_uuid": {"mpp-format-string": "{__import__('uuid').uuid1()}"}, "bootfs_uuid": "156f0420-627b-4151-ae6f-fda298097515" }, ``` This will automatically call uuid.uuid1() for rootfs_uuid, thus allowing to dynamically set the uuid for the rootfs variable. This variable being able to be overridden via the -D argument of the osbuild-mpp tool. In addition, you can also define variable based on variables defined above, for example: ``` "mpp-vars": { "rootfs_size": 4294967296, "homefs_size": {"mpp-format-string": "{rootfs_size}"} }, ``` For context, we're in particular interested in this for the uuid generation, as we have had issues with xfs failing to mount a filesystem if the uuid is already mounted. In particular, if we built e.g. a raspberry pi image using osbuild and then we use that raspberry pi for building the same manifest (typically a later version of it) the osbuild fails in the loopback mount case. Being able to easily support reproducible fixed-uuid images, as well as ones with a real unique uuid makes a lot of sense. This commit was created with a lot of inputs from Alexander Larsson. Signed-off-by: Pierre-Yves Chibon --- tools/osbuild-mpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) mode change 100755 => 100644 tools/osbuild-mpp diff --git a/tools/osbuild-mpp b/tools/osbuild-mpp old mode 100755 new mode 100644 index 89bb9984..60a03cc4 --- a/tools/osbuild-mpp +++ b/tools/osbuild-mpp @@ -555,7 +555,10 @@ class ManifestFile: if not variables: return - self.vars.update(variables) + for k, v in variables.items(): + fakeroot = [v] + self._process_format(fakeroot) + self.vars[k] = fakeroot[0] self.substitute_vars(self.vars) def set_vars(self, args):