[elbe-devel] [PATCH 2/3] xmlpreprocess: Add ELBE_VARIANTS and change default variant

Olivier Dion dion at linutronix.de
Wed Aug 26 17:16:11 CEST 2020


The environment variable ELBE_VARIANTS=variant0:variant1:variantN
allows to add variants to the preprocessor.  Also the default variant
is changed from [] to [""], allowing us to make default option when no
variant are selected.

This basically allows us to do a 'switch' statement on a XML
node. e.g.
----------------------------------------------------------------------
<foo variant="">default</foo>
<foo variant="bar">bar</foo>
----------------------------------------------------------------------

In this example, the first variant is selected when no variant are
passed to Elbe, acting as the default value.  However, if the variant
'bar' is passed to Elbe, the second node is selected instead.

Signed-off-by: Olivier Dion <dion at linutronix.de>
---
 elbepack/xmlpreprocess.py | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/elbepack/xmlpreprocess.py b/elbepack/xmlpreprocess.py
index fdc037b4..685f8e5c 100644
--- a/elbepack/xmlpreprocess.py
+++ b/elbepack/xmlpreprocess.py
@@ -238,10 +238,14 @@ def xmlpreprocess(fname, output, variants=None, proxy=None):
 
     # first convert variants to a set
     if not variants:
-        variants = set([])
+        variants = set([""])
     else:
         variants = set(variants)
 
+    if "ELBE_VARIANTS" in os.environ:
+        for variant in os.environ["ELBE_VARIANTS"].split(':'):
+            variants.add(variant)
+
     schema_file = "https://www.linutronix.de/projects/Elbe/dbsfed.xsd"
     parser = XMLParser(huge_tree=True)
     schema_tree = etree.parse(schema_file)
-- 
2.28.0



More information about the elbe-devel mailing list