acrn-hypervisor/hypervisor/scripts/genconf.sh

91 lines
2.7 KiB
Bash
Raw Normal View History

#!/bin/sh
# Copyright (C) 2021 Intel Corporation.
# SPDX-License-Identifier: BSD-3-Clause
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')
Makefile: create and apply patches to generated sources In order to enable changing the generated C configuration files manually, this patch introduces the target `diffconfig` to the build system. After generating the configuration files, a developer can manually modify these sources (which are placed under build/configs) and invoke `make diffconfig` to generate a patch that shows the made differences. Such patches can be registered to a build by invoking the `applydiffconfig` target. The build system will always apply them whenever the configuration files are regenerated. A typical workflow to create a patch is as follows. # The pre_build target relies on generated configuration files hypervisor$ make BOARD=xxx SCENARIO=yyy pre_build (manually edit files under build/configs/boards and build/configs/scenarios) hypervisor$ make diffconfig # Patch generated to build/config.patch hypervisor$ cp build/config.patch /path/to/patch The following steps apply apply the patch to another build. hypervisor$ make BOARD=xxx SCENARIO=yyy defconfig hypervisor$ make applydiffconfig PATCH=/path/to/patch-file-or-directory hypervisor$ make After any patch is registered for a build, the configuration files will be automatically regenerated the next time `make` is invoked. To show a list of registered patches for generated configuration files, invoke `make applydiffconfig` without specifying `PATCH`. v2: * Add target `applydiffconfig` which accepts a PATCH variable to register an arbitrary patch file or a directory containing patch file(s) for a build. `.config_patches` is no longer used. Tracked-On: #5644 Signed-off-by: Junjie Mao <junjie.mao@intel.com>
2021-01-06 12:10:12 +08:00
apply_patch () {
echo "Applying patch ${1}:"
patch -p1 < ${1}
if [ $? -ne 0 ]; then
echo "Applying patch ${1} failed."
exit 1
fi
}
tool_dir=${base_dir}/../misc/config_tools
Makefile: create and apply patches to generated sources In order to enable changing the generated C configuration files manually, this patch introduces the target `diffconfig` to the build system. After generating the configuration files, a developer can manually modify these sources (which are placed under build/configs) and invoke `make diffconfig` to generate a patch that shows the made differences. Such patches can be registered to a build by invoking the `applydiffconfig` target. The build system will always apply them whenever the configuration files are regenerated. A typical workflow to create a patch is as follows. # The pre_build target relies on generated configuration files hypervisor$ make BOARD=xxx SCENARIO=yyy pre_build (manually edit files under build/configs/boards and build/configs/scenarios) hypervisor$ make diffconfig # Patch generated to build/config.patch hypervisor$ cp build/config.patch /path/to/patch The following steps apply apply the patch to another build. hypervisor$ make BOARD=xxx SCENARIO=yyy defconfig hypervisor$ make applydiffconfig PATCH=/path/to/patch-file-or-directory hypervisor$ make After any patch is registered for a build, the configuration files will be automatically regenerated the next time `make` is invoked. To show a list of registered patches for generated configuration files, invoke `make applydiffconfig` without specifying `PATCH`. v2: * Add target `applydiffconfig` which accepts a PATCH variable to register an arbitrary patch file or a directory containing patch file(s) for a build. `.config_patches` is no longer used. Tracked-On: #5644 Signed-off-by: Junjie Mao <junjie.mao@intel.com>
2021-01-06 12:10:12 +08:00
diffconfig_list=${out}/.diffconfig
python3 ${tool_dir}/board_config/board_cfg_gen.py --board ${board_xml} --scenario ${scenario_xml} --out ${out} &&
python3 ${tool_dir}/scenario_config/scenario_cfg_gen.py --board ${board_xml} --scenario ${scenario_xml} --out ${out}
if [ $? -ne 0 ]; then
exit $?
fi
Makefile: create and apply patches to generated sources In order to enable changing the generated C configuration files manually, this patch introduces the target `diffconfig` to the build system. After generating the configuration files, a developer can manually modify these sources (which are placed under build/configs) and invoke `make diffconfig` to generate a patch that shows the made differences. Such patches can be registered to a build by invoking the `applydiffconfig` target. The build system will always apply them whenever the configuration files are regenerated. A typical workflow to create a patch is as follows. # The pre_build target relies on generated configuration files hypervisor$ make BOARD=xxx SCENARIO=yyy pre_build (manually edit files under build/configs/boards and build/configs/scenarios) hypervisor$ make diffconfig # Patch generated to build/config.patch hypervisor$ cp build/config.patch /path/to/patch The following steps apply apply the patch to another build. hypervisor$ make BOARD=xxx SCENARIO=yyy defconfig hypervisor$ make applydiffconfig PATCH=/path/to/patch-file-or-directory hypervisor$ make After any patch is registered for a build, the configuration files will be automatically regenerated the next time `make` is invoked. To show a list of registered patches for generated configuration files, invoke `make applydiffconfig` without specifying `PATCH`. v2: * Add target `applydiffconfig` which accepts a PATCH variable to register an arbitrary patch file or a directory containing patch file(s) for a build. `.config_patches` is no longer used. Tracked-On: #5644 Signed-off-by: Junjie Mao <junjie.mao@intel.com>
2021-01-06 12:10:12 +08:00
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 successfully."
}
transform_board() {
echo "Generating ${1}:"
xsltproc -o ${out}/boards/${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}/boards/${1}
echo "${1} was generated using xsltproc successfully."
}
transform vm_configurations.c
transform vm_configurations.h
transform pt_intx.c
transform ivshmem_cfg.h
transform misc_cfg.h
transform pci_dev.c
transform_board board_info.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 readability."
echo "Please install clang-format and format the generated files if those need to be included and reviewed."
fi
Makefile: create and apply patches to generated sources In order to enable changing the generated C configuration files manually, this patch introduces the target `diffconfig` to the build system. After generating the configuration files, a developer can manually modify these sources (which are placed under build/configs) and invoke `make diffconfig` to generate a patch that shows the made differences. Such patches can be registered to a build by invoking the `applydiffconfig` target. The build system will always apply them whenever the configuration files are regenerated. A typical workflow to create a patch is as follows. # The pre_build target relies on generated configuration files hypervisor$ make BOARD=xxx SCENARIO=yyy pre_build (manually edit files under build/configs/boards and build/configs/scenarios) hypervisor$ make diffconfig # Patch generated to build/config.patch hypervisor$ cp build/config.patch /path/to/patch The following steps apply apply the patch to another build. hypervisor$ make BOARD=xxx SCENARIO=yyy defconfig hypervisor$ make applydiffconfig PATCH=/path/to/patch-file-or-directory hypervisor$ make After any patch is registered for a build, the configuration files will be automatically regenerated the next time `make` is invoked. To show a list of registered patches for generated configuration files, invoke `make applydiffconfig` without specifying `PATCH`. v2: * Add target `applydiffconfig` which accepts a PATCH variable to register an arbitrary patch file or a directory containing patch file(s) for a build. `.config_patches` is no longer used. Tracked-On: #5644 Signed-off-by: Junjie Mao <junjie.mao@intel.com>
2021-01-06 12:10:12 +08:00
if [ -f ${diffconfig_list} ]; then
cd ${out} &&
cat ${diffconfig_list} | while read line; do
if [ -f ${line} ]; then
apply_patch ${line}
elif [ -d ${line} ]; then
find ${line} -maxdepth 1 -name '*.patch' | while read f; do
apply_patch ${f}
done
else
echo "${line}: No such file or directory"
exit 1
fi
done
fi