From: Andrew Cooper Date: Tue, 26 Jul 2016 18:55:26 +0000 (+0100) Subject: build: Generate xl configurations with a python script rather than by hand X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=bda82e8db489ba390b5aea555d9fef891ebfbf41;p=people%2Fandrewcoop%2Fxen-test-framework.git build: Generate xl configurations with a python script rather than by hand 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 --- diff --git a/build/gen.mk b/build/gen.mk index f33738b..72f1f69 100644 --- a/build/gen.mk +++ b/build/gen.mk @@ -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 index 0000000..a0143c2 --- /dev/null +++ b/build/mkcfg.py @@ -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)