config-tools: introduce xslt transform and clang-format in genconf.sh

Add "transform" to generate following files with xsltproc in genconf.sh:
  - ivshmem_cfg.h
  - misc_cfg.h
  - pt_intx.c
  - vm_configurations.c
  - vm_configurations.h

Add code formatter using clang-format. It formats the gernerated code
with customized condfiguration if clang-format package and configuraion
file ".clang-format" exist.

Add sed in genconf.sh "transform" to replace the copyright "YEAR" of generated files.

Tracked-On: #5980
Signed-off-by: Yang,Yu-chu <yu-chu.yang@intel.com>
Reviewed-by: Junjie Mao <junjie.mao@intel.com>
This commit is contained in:
Yang,Yu-chu
2021-03-08 12:39:05 -08:00
committed by wenlingz
parent 6d81112428
commit 5f2f82f4d8
3 changed files with 125 additions and 2 deletions

View File

@@ -6,6 +6,9 @@ base_dir=$1
board_xml=$2
scenario_xml=$3
out=$4
unified_xml=$5
scenario=$(xmllint --xpath "string(//@scenario)" --xinclude $unified_xml)
year=$(date +'%Y')
apply_patch () {
echo "Applying patch ${1}:"
@@ -26,6 +29,37 @@ if [ $? -ne 0 ]; then
exit $?
fi
if ! which xsltproc ; then
echo "xsltproc cannot be found, please install it and make sure it is in your PATH."
exit 1
fi
transform() {
echo "Generating ${1}:"
xsltproc -o ${out}/scenarios/${scenario}/${1} --xinclude --xincludestyle ${tool_dir}/xforms/${1}.xsl ${unified_xml}
if [ $? -ne 0 ]; then
echo "Failed to generate ${1} with xsltproc!"
exit 1
fi
sed -i -e "s/YEAR/$year/" ${out}/scenarios/${scenario}/${1}
echo "${1} was generated using xsltproc succesfully."
}
transform vm_configurations.c
transform vm_configurations.h
transform pt_intx.c
transform ivshmem_cfg.h
transform misc_cfg.h
if which clang-format ; then
find ${out}/scenarios/${scenario} -iname *.h -o -iname *.c \
| xargs clang-format --style=file -i --fallback-style=none
else
echo "clang-format cannot be found. The generated files under ${out}/scenarios/${scenario} are not formatted."
echo "clang-format is a tool to format the C code automatically and improve the code readibility."
echo "Please install clang-format and format the generated files if those need to be included and reviewed."
fi
if [ -f ${diffconfig_list} ]; then
cd ${out} &&
cat ${diffconfig_list} | while read line; do

View File

@@ -238,7 +238,7 @@ $(HV_CONFIG_H): $(HV_UNIFIED_XML)
@echo "$@ generated"
$(HV_CONFIG_TIMESTAMP): $(HV_UNIFIED_XML) ${HV_DIFFCONFIG_LIST} | $(HV_CONFIG_DIR)
@sh $(BASEDIR)/scripts/genconf.sh $(BASEDIR) $(HV_BOARD_XML) $(HV_SCENARIO_XML) $(HV_CONFIG_DIR)
@sh $(BASEDIR)/scripts/genconf.sh $(BASEDIR) $(HV_BOARD_XML) $(HV_SCENARIO_XML) $(HV_CONFIG_DIR) $(HV_UNIFIED_XML)
@touch $@
.PHONY: defconfig
@@ -253,7 +253,7 @@ showconfig:
diffconfig:
@rm -rf $(HV_CONFIG_A_DIR) $(HV_CONFIG_B_DIR)
@sh $(BASEDIR)/scripts/genconf.sh $(BASEDIR) $(BOARD_FILE) $(HV_SCENARIO_XML) $(HV_CONFIG_A_DIR)
@sh $(BASEDIR)/scripts/genconf.sh $(BASEDIR) $(BOARD_FILE) $(HV_SCENARIO_XML) $(HV_CONFIG_A_DIR) $(HV_UNIFIED_XML)
@cd $(HV_CONFIG_DIR) && find . -name '*.c' -or -name '*.h' -or -name '*.config' -or -name '*.asl' | while read f; do \
nf=$(HV_CONFIG_B_DIR)/$${f}; mkdir -p `dirname $${nf}` && cp $${f} $${nf}; \
done