acrn-hypervisor/scripts/kconfig/silentoldconfig.py
Junjie Mao 064a31067f tools: vmcfg: use defconfig instead of default values in Kconfig
The current vmcfg uses the default values in Kconfig when a previous .config
does not exist. This leads to additional complexity to silentoldconfig.py which
has different logic depending on the environment variable 'BOARD'. This also
blocks the effort to make the top-level Makefile recognize BOARD because any
environment variable set in the top-level Makefile cascades to the other
Makefiles, leading the work around above to fail.

This patch introduces a generic defconfig for vmcfg and simplifies
silentoldconfig.py to always fail when neither .config nor the specified
defconfig exists.

Tracked-On: #1995
Signed-off-by: Junjie Mao <junjie.mao@intel.com>
Signed-off-by: Tw <wei.tan@intel.com>
Reviewed-by: Binbin Wu <binbin.wu@intel.com>
Reviewed-by: Yin Fengwei <fengwei.yin@intel.com>
2018-12-12 13:23:28 +08:00

112 lines
4.0 KiB
Python

# Copyright (C) 2018 Intel Corporation.
# SPDX-License-Identifier: BSD-3-Clause
# This script
#
# 1. takes a Kconfig and a .config and an optional list of symbol-value pairs,
# 2. checks whether the specified symbols have the specified values in the
# given .config, and
# 3. reconstruct .config with the given list of symbol-value pairs if there
# is any disagreement.
import sys, os
# Kconfiglib: Copyright (c) 2011-2018, Ulf Magnusson
# SPDX-License-Identifier: ISC
# Refer to scripts/kconfig/LICENSE.kconfiglib for the permission notice.
import kconfiglib
def usage():
sys.stdout.write("%s: <Kconfig file> <.config file> [<symbol1>=<value1> ...]\n" % sys.argv[0])
def main():
if len(sys.argv) < 3:
usage()
sys.exit(1)
kconfig_path = sys.argv[1]
if not os.path.isfile(kconfig_path):
sys.stderr.write("Cannot find file %s\n" % kconfig_path)
sys.exit(1)
kconfig = kconfiglib.Kconfig(kconfig_path)
# Parse the configs specified on cmdline
cmdline_conf = {}
for sym_val in sys.argv[3:]:
if sym_val.find("=") == -1:
continue
sym_name, val = sym_val.split("=")[:2]
if sym_name in kconfig.syms.keys() and val:
cmdline_conf[sym_name] = val
# Determine the base config.
#
# If either
#
# 1. no .config exists, or
# 2. the BOARD in the existing .config is different from the BOARD
# specified in the environment variable
#
# the defconfig will be used as the base config. Otherwise the existing
# .config is used as the base.
#
# If .config does not exist, it is required that Kconfig specifies an
# existing defconfig, otherwise this script will refuse to generate a
# .config.
config_path = sys.argv[2]
defconfig_path = kconfig.defconfig_filename
if defconfig_path and os.path.isfile(defconfig_path):
kdefconfig = kconfiglib.Kconfig(kconfig_path)
kdefconfig.load_config(defconfig_path)
else:
kdefconfig = None
need_update = False
if os.path.isfile(config_path):
kconfig.load_config(config_path)
# The BOARD given by the environment variable may be different from what
# is specified in the corresponding defconfig. So compare the value of
# CONFIG_BOARD directly. This is applicable only when CONFIG_BOARD
# exists in the Kconfig.
if kdefconfig and 'BOARD' in kconfig.syms and \
kconfig.syms['BOARD'].str_value != kdefconfig.syms['BOARD'].str_value:
kconfig = kdefconfig
sys.stdout.write("Overwrite with default configuration based on %s.\n" % defconfig_path)
need_update = True
else:
# base on a default configuration
if kdefconfig:
kconfig = kdefconfig
sys.stdout.write("Default configuration based on %s.\n" % defconfig_path)
need_update = True
else:
# report an error if no known defconfig exists
sys.stderr.write(".config does not exist and no defconfig available.\n")
sys.exit(1)
# Update the old .config with those specified on cmdline
#
# Note: the user shall be careful what configuration symbols to overwrite by
# silentoldconfig. After changing a symbol value, the invisible symbols are
# updated accordingly because they always use the default value, while
# visible symbols keep their original value in the old .config. This may
# lead to invalid .config for a specific platform.
#
# Currently it is recommended to use the following update only for
# RELEASE. For PLATFORM reinvoke defconfig is preferred.
for sym_name, val in cmdline_conf.items():
sym = kconfig.syms[sym_name]
if sym.str_value and sym.str_value != val:
kconfig.syms[sym_name].set_value(val)
need_update = True
if need_update:
kconfig.write_config(config_path)
sys.stdout.write("Configuration written to %s.\n" % config_path)
if __name__ == "__main__":
main()