]> xenbits.xensource.com Git - people/liuw/xtf.git/commitdiff
build: Generate xl configurations with a python script rather than by hand
authorAndrew Cooper <andrew.cooper3@citrix.com>
Tue, 26 Jul 2016 18:55:26 +0000 (19:55 +0100)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Thu, 28 Jul 2016 13:06:48 +0000 (14:06 +0100)
It is about to get more complicated.  Additionally, specify a dependency on
$(TEST-EXTRA-CFG) if specified by a test.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
build/gen.mk
build/mkcfg.py [new file with mode: 0644]

index f33738be98c413cee6b3bd6d99f34ff439988337..72f1f696811b94e0941b1f133fbece5cab69aebe 100644 (file)
@@ -50,12 +50,8 @@ endif
 
 cfg-$(1) ?= $(defcfg-$(1))
 
-test-$(1)-$(NAME).cfg: $$(cfg-$(1)) FORCE
-       @{ cat $$< $(TEST-EXTRA-CFG) ;} | \
-       sed -e "s/@@NAME@@/$$(NAME)/g" \
-               -e "s/@@ENV@@/$(1)/g" \
-               -e "s!@@XTFDIR@@!$$(xtfdir)!g" \
-               > $$@.tmp
+test-$(1)-$(NAME).cfg: $(ROOT)/build/mkcfg.py $$(cfg-$(1)) $(TEST-EXTRA-CFG) FORCE
+       @$(PYTHON) $$< $$@.tmp "$$(cfg-$(1))" "$(TEST-EXTRA-CFG)"
        @$(call move-if-changed,$$@.tmp,$$@)
 
 -include $$(link-$(1):%.lds=%.d)
diff --git a/build/mkcfg.py b/build/mkcfg.py
new file mode 100644 (file)
index 0000000..a0143c2
--- /dev/null
@@ -0,0 +1,33 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+"""
+Construct an xl configuration file for a test (from various fragments), and
+substitue variables appropriately.
+"""
+
+import sys, os
+
+# Usage: mkcfg.py $OUT $DEFAULT-CFG $EXTRA-CFG
+_, out, defcfg, extracfg = sys.argv
+
+# Evaluate environment and name from $OUT
+_, env, name = out.split('.')[0].split('-', 2)
+
+def expand(text):
+    """ Expand certain variables in text """
+    return (text
+            .replace("@@NAME@@",   name)
+            .replace("@@ENV@@",    env)
+            .replace("@@XTFDIR@@", os.environ["xtfdir"])
+        )
+
+config = open(defcfg).read()
+
+if extracfg:
+    config += "\n# Test Extra Configuration:\n"
+    config += open(extracfg).read()
+
+cfg = expand(config)
+
+open(out, "w").write(cfg)