From 57e5be632d4e40314cd8d1a67973ee1e58d3dfb8 Mon Sep 17 00:00:00 2001 From: Alexey Neyman Date: Sun, 20 Jan 2019 16:42:12 -0800 Subject: [PATCH] Basic framework for checking config file version Signed-off-by: Alexey Neyman --- config/global.in | 39 +++++++++++++++++++++++++++++++--- ct-ng.in | 30 +++++++++++++++------------ samples/samples.mk | 45 +++++++++++++++++++++++++--------------- scripts/version-check.sh | 38 +++++++++++++++++++++++++++++++++ 4 files changed, 119 insertions(+), 33 deletions(-) create mode 100644 scripts/version-check.sh diff --git a/config/global.in b/config/global.in index 0dff199c..a19667b7 100644 --- a/config/global.in +++ b/config/global.in @@ -1,14 +1,47 @@ # Overall toolchain configuration: paths, jobs, etc... -config CT_VERSION +config VERSION string option env="CT_VERSION" +# Config version checking framework. If CONFIG_VERSION is unset in the current .config +# or defconfig, it is loaded as 0 (possibly triggering a user prompt during 'ct-ng oldconfig'). +# If the value of CONFIG_VERSION is older than CONFIG_VERSION_CURRENT, we'll advice the user +# to run the configuration through an upgrade. If it is newer, we'll error out - I have no +# crystal orb to perform the downgrade. + +# Hack to make kconfig save/load the value for CONFIG_VERSION. Set to empty value (for +# normal operations like 'ct-ng menuconfig'); 'load' for creating a configuration from a (potentially) +# old file, i.e. 'ct-ng ' or 'ct-ng oldconfig'; 'save' for saving the current configuration, +# i.e. 'ct-ng saveconfig' or 'ct-ng savedefconfig'. +config VCHECK + string + option env="CT_VCHECK" + +config CONFIG_VERSION_CURRENT + string + default -1 if VCHECK = "save" + default 1 + +config CONFIG_VERSION + string + prompt "** make it changeable **" if VCHECK = "load" || VCHECK = "save" + default 0 if VCHECK = "load" || VCHECK = "save" + default CONFIG_VERSION_CURRENT + +if VCHECK = "warning" +comment "*************************************************************************" +comment "Loaded configuration was generated by a previous version of crosstool-NG." +comment "Saving it will mark the configuration as up-to-date without verifying it." +comment "It is recommended to run \"ct-ng upgradeconfig\" before making any " +comment "changes to the configuration. " +comment "*************************************************************************" +endif + # Allow unconditional usage of tristates config MODULES - bool + def_bool y option modules - default y menu "Paths and misc options" diff --git a/ct-ng.in b/ct-ng.in index 0b5e517e..fddc4645 100644 --- a/ct-ng.in +++ b/ct-ng.in @@ -1,4 +1,5 @@ #!@MAKE@ -rf +# vim: set filetype=make : # Makefile for crosstool-NG. # Copyright 2006 Yann E. MORIN @@ -32,6 +33,10 @@ endif # This is crosstool-NG version string export CT_VERSION:=@PACKAGE_VERSION@ +# Export with an empty value: this masks the version detection variable in +# user-visible configurators, and suppresses a warning from kconfig. +export CT_VCHECK= + # Download agents used by scripts.mk CT_WGET := @wget@ CT_CURL := @curl@ @@ -93,10 +98,9 @@ FORCE: # Top file of crosstool-NG configuration export KCONFIG_TOP = $(CT_LIB_DIR)/config/config.in -# We need CONF for savedefconfig in scripts/saveSample.sh -export CONF := $(CT_LIBEXEC_DIR)/conf -MCONF := $(CT_LIBEXEC_DIR)/mconf -NCONF := $(CT_LIBEXEC_DIR)/nconf +CONF := $(CT_LIBEXEC_DIR)/conf +CONF-menuconfig := $(CT_LIBEXEC_DIR)/mconf +CONF-nconfig := $(CT_LIBEXEC_DIR)/nconf # Used by conf/mconf/nconf to find the .in files # TBD needed? We do supply the defconfig name explicitly below @@ -107,26 +111,26 @@ export srctree=$(CT_LIB_DIR) check-config: @[ ! -e .config -o -f .config ] || { echo ".config is not a regular file:"; ls -dl .config; exit 1; } >&2 -menuconfig: check-config +menuconfig nconfig: check-config @$(CT_ECHO) " CONF $@" - $(SILENT)$(MCONF) $(KCONFIG_TOP) - -nconfig: check-config - @$(CT_ECHO) " CONF $@" - $(SILENT)$(NCONF) $(KCONFIG_TOP) + $(SILENT)if [ ! -f .config ] || CT_VCHECK=strict $(bash) $(CT_LIB_DIR)/scripts/version-check.sh .config; then \ + $(CONF-$@) $(KCONFIG_TOP); \ + else \ + CT_VCHECK=warning $(CONF-$@) $(KCONFIG_TOP); \ + fi oldconfig: .config check-config @$(CT_ECHO) " CONF $@" - $(SILENT)$(sed) -i -r -f $(CT_LIB_DIR)/scripts/upgrade.sed $< + @$(bash) $(CT_LIB_DIR)/scripts/version-check.sh .config $(SILENT)$(CONF) --silent$@ $(KCONFIG_TOP) savedefconfig: .config check-config @$(CT_ECHO) ' GEN $@' - $(SILENT)$(CONF) --savedefconfig=$${DEFCONFIG-defconfig} $(KCONFIG_TOP) + $(SILENT)CT_VCHECK=save $(CONF) --savedefconfig=$${DEFCONFIG-defconfig} $(KCONFIG_TOP) defconfig: check-config @$(CT_ECHO) ' CONF $@' - $(SILENT)$(CONF) --defconfig=$${DEFCONFIG-defconfig} $(KCONFIG_TOP) + $(SILENT)CT_VCHECK=save $(CONF) --defconfig=$${DEFCONFIG-defconfig} $(KCONFIG_TOP) # Always be silent, the stdout an be >.config extractconfig: diff --git a/samples/samples.mk b/samples/samples.mk index 13f8779c..63058009 100644 --- a/samples/samples.mk +++ b/samples/samples.mk @@ -19,13 +19,14 @@ CT_UPDATE_SAMPLES := no # This part deals with the samples help entries help-config:: - @echo ' show-config - show a brief overview of current configuration' + @echo ' show-config - Show a brief overview of current configuration' @echo ' saveconfig - Save current config as a preconfigured target' + @echo ' upgradeconfig - Upgrade config file to current crosstool-NG' help-samples:: - @echo ' list-samples - prints the list of all samples (for scripting)' - @echo ' show- - show a brief overview of (list with list-samples)' - @echo ' - preconfigure crosstool-NG with (list with list-samples)' + @echo ' list-samples - Prints the list of all samples (for scripting)' + @echo ' show- - Show a brief overview of (list with list-samples)' + @echo ' - Preconfigure crosstool-NG with (list with list-samples)' @echo ' build-all[.#] - Build *all* samples (list with list-samples) and install in' @echo ' $${CT_PREFIX} (set to ~/x-tools by default)' @@ -34,7 +35,7 @@ help-distrib:: @echo ' update-samples - Regenerate sample configurations using the current Kconfig' help-env:: - @echo ' CT_PREFIX=dir - install samples in dir (see action "build-all", above).' + @echo ' CT_PREFIX=dir - Install samples in dir (see action "build-all", above).' # ---------------------------------------------------------- # This part deals with printing samples information @@ -43,6 +44,7 @@ help-env:: PHONY += show-config show-config: .config @cp .config .config.sample + @$(bash) $(CT_LIB_DIR)/scripts/version-check.sh .config @$(bash) $(CT_LIB_DIR)/scripts/show-config.sh -v current @rm -f .config.sample @@ -50,8 +52,10 @@ show-config: .config PHONY += $(patsubst %,show-%,$(CT_SAMPLES)) $(patsubst %,show-%,$(CT_SAMPLES)): show-%: @KCONFIG_CONFIG=$$(pwd)/.config.sample \ - $(CONF) --defconfig=$(call sample_dir,$*)/crosstool.config \ + CT_VCHECK=load \ + $(CONF) --defconfig=$(call sample_dir,$*)/crosstool.config \ $(KCONFIG_TOP) >/dev/null + @$(bash) $(CT_LIB_DIR)/scripts/version-check.sh .config.sample @$(bash) $(CT_LIB_DIR)/scripts/show-config.sh -v $* @rm -f .config.sample @@ -74,8 +78,10 @@ list-samples-pre: FORCE PHONY += $(patsubst %,list-%,$(CT_SAMPLES)) $(patsubst %,list-%,$(CT_SAMPLES)): list-%: @KCONFIG_CONFIG=$$(pwd)/.config.sample \ + CT_VCHECK=load \ $(CONF) --defconfig=$(call sample_dir,$*)/crosstool.config \ $(KCONFIG_TOP) >/dev/null + @$(bash) $(CT_LIB_DIR)/scripts/version-check.sh .config.sample @$(bash) $(CT_LIB_DIR)/scripts/show-config.sh $* @rm -f .config.sample @@ -88,19 +94,20 @@ list-samples-short: FORCE # Check one sample PHONY += $(patsubst %,check-%,$(CT_SAMPLES)) $(patsubst %,check-%,$(CT_SAMPLES)): check-%: - @export KCONFIG_CONFIG=$$(pwd)/.config.sample; \ + @eset -e; xport KCONFIG_CONFIG=$$(pwd)/.config.sample; \ CT_NG_SAMPLE=$(call sample_dir,$*)/crosstool.config; \ - $(CONF) -s --defconfig=$${CT_NG_SAMPLE} $(KCONFIG_TOP) &>/dev/null; \ - $(CONF) -s --savedefconfig=$$(pwd)/.defconfig $(KCONFIG_TOP) &>/dev/null; \ + CT_VCHECK=load $(CONF) -s --defconfig=$${CT_NG_SAMPLE} $(KCONFIG_TOP) &>/dev/null; \ + CT_UPGRADECONFIG=yes $(bash) $(CT_LIB_DIR)/scripts/version-check.sh .config.sample; \ + CT_VCHECK=save $(CONF) -s --savedefconfig=$$(pwd)/.defconfig $(KCONFIG_TOP) &>/dev/null; \ old_sha1=$$( sha1sum "$${CT_NG_SAMPLE}" |cut -d ' ' -f 1 ); \ new_sha1=$$( sha1sum .defconfig |cut -d ' ' -f 1 ); \ if [ $${old_sha1} != $${new_sha1} ]; then \ - if [ $(CT_UPDATE_SAMPLES) = yes ]; then \ - echo "Updating $*"; \ - mv .defconfig "$${CT_NG_SAMPLE}"; \ + if [ $(CT_UPDATE_SAMPLES) = yes ]; then \ + echo "Updating $*"; \ + mv .defconfig "$${CT_NG_SAMPLE}"; \ else \ - echo "$* needs update:"; \ - diff -d -U 0 "$${CT_NG_SAMPLE}" .defconfig |tail -n +4; \ + echo "$* needs update:"; \ + diff -d -U 0 "$${CT_NG_SAMPLE}" .defconfig |tail -n +4; \ fi; \ fi @rm -f .config.sample* .defconfig @@ -120,7 +127,10 @@ samples: # Save a sample saveconfig: .config samples - $(SILENT)$(bash) $(CT_LIB_DIR)/scripts/saveSample.sh + $(SILENT)CT_VCHECK=save CONF=$(CONF) $(bash) $(CT_LIB_DIR)/scripts/saveSample.sh + +upgradeconfig: .config + $(SILENT)CT_UPGRADECONFIG=yes $(bash) $(CT_LIB_DIR)/scripts/version-check.sh .config # The 'sample_dir' function prints the directory in which the sample is, # searching first in local samples, then in global samples @@ -132,7 +142,8 @@ endef PHONY += $(CT_SAMPLES) $(CT_SAMPLES): check-config @$(CT_ECHO) " CONF $@" - $(SILENT)$(CONF) --defconfig=$(call sample_dir,$@)/crosstool.config $(KCONFIG_TOP) + $(SILENT)CT_VCHECK=load $(CONF) --defconfig=$(call sample_dir,$@)/crosstool.config $(KCONFIG_TOP) + @CT_VCHECK=strict $(bash) $(CT_LIB_DIR)/scripts/version-check.sh .config @echo @echo '***********************************************************' @echo @@ -169,7 +180,7 @@ target_triplet = $(if $(findstring $(__comma),$(1)),$(word 2,$(subst $(__comma), # $1: sample name (target tuple, or host/target tuples separated by a comma) define build_sample @$(CT_ECHO) ' CONF $(1)' - $(SILENT)$(CONF) -s --defconfig=$(call sample_dir,$(1))/crosstool.config $(KCONFIG_TOP) + $(SILENT)CT_VCHECK=load $(CONF) -s --defconfig=$(call sample_dir,$(1))/crosstool.config $(KCONFIG_TOP) $(SILENT)[ -n "$(CT_PREFIX)" ] && $(sed) -i -r -e 's:^(CT_PREFIX=).*$$:\1"$(CT_PREFIX)":;' .config || : $(SILENT)$(sed) -i -r -e 's:^.*(CT_LOG_(WARN|INFO|EXTRA|DEBUG|ALL)).*$$:# \1 is not set:;' .config $(SILENT)$(sed) -i -r -e 's:^.*(CT_LOG_ERROR).*$$:\1=y:;' .config diff --git a/scripts/version-check.sh b/scripts/version-check.sh new file mode 100644 index 00000000..c4a2bd07 --- /dev/null +++ b/scripts/version-check.sh @@ -0,0 +1,38 @@ +# This script checks the version of the configuration file and either +# alerts the user about the need to run the upgrade, or attempts to +# perform such an upgrade. + +CFGFILE="${1}" + +. "${CT_LIB_DIR}/scripts/functions" +. "${CFGFILE}" +if [ "${CT_CONFIG_VERSION_CURRENT}" == "${CT_CONFIG_VERSION}" ]; then + # Nothing to do + exit 0 +fi + +if [ -z "${CT_UPGRADECONFIG}" ]; then + if [ "${CT_CONFIG_VERSION}" != "0" ]; then + oldversion="is version ${CT_CONFIG_VERSION}" + else + oldversion="has no version" + fi + cat 2>&1 <&2 +exit 1