tools: Add way to get current defconfig name on runtime

This commit aims to provide a way to get the current applied defconfig on runtime by providing CONFIG_BASE_DEFCONFIG that is updated when the configure and build scripts are run.
This commit is contained in:
Lucas Saavedra Vaz
2023-06-01 18:43:48 -03:00
committed by Alan Carvalho de Assis
parent 766e0a3b05
commit 6a220a08ba
5 changed files with 81 additions and 1 deletions
+9
View File
@@ -244,6 +244,15 @@ config APPS_DIR
example, to include makefile fragments (e.g., .config or Make.defs) example, to include makefile fragments (e.g., .config or Make.defs)
or to set up include file paths. or to set up include file paths.
config BASE_DEFCONFIG
string "Base Configuration"
default ""
---help---
This will be automatically be updated by the configuration
script. This is the base configuration file that was used to create the
current configuration. It is useful for getting the current configuration
on runtime.
config BUILD_LOADABLE config BUILD_LOADABLE
bool bool
option modules option modules
+9
View File
@@ -248,6 +248,13 @@ tools/mkconfig$(HOSTEXEEXT):
$(Q) $(MAKE) -C tools -f Makefile.host mkconfig$(HOSTEXEEXT) $(Q) $(MAKE) -C tools -f Makefile.host mkconfig$(HOSTEXEEXT)
include/nuttx/config.h: $(TOPDIR)/.config tools/mkconfig$(HOSTEXEEXT) include/nuttx/config.h: $(TOPDIR)/.config tools/mkconfig$(HOSTEXEEXT)
$(Q) grep -v "CONFIG_BASE_DEFCONFIG" "$(TOPDIR)/.config" > "$(TOPDIR)/.config.tmp"
$(Q) if ! cmp -s "$(TOPDIR)/.config.tmp" "$(TOPDIR)/.config.orig" ; then \
sed -i.bak "/CONFIG_BASE_DEFCONFIG/s/\"$$/-dirty\"/" "$(TOPDIR)/.config"; \
else \
sed -i.bak "s/-dirty//g" "$(TOPDIR)/.config"; \
fi
$(Q) rm -f "$(TOPDIR)/.config.tmp" "$(TOPDIR)/.config.bak"
$(Q) tools/mkconfig $(TOPDIR) > $@.tmp $(Q) tools/mkconfig $(TOPDIR) > $@.tmp
$(Q) $(call TESTANDREPLACEFILE, $@.tmp, $@) $(Q) $(call TESTANDREPLACEFILE, $@.tmp, $@)
@@ -685,6 +692,7 @@ gconfig: apps_preconfig
savedefconfig: apps_preconfig savedefconfig: apps_preconfig
$(Q) ${KCONFIG_ENV} ${KCONFIG_SAVEDEFCONFIG} $(Q) ${KCONFIG_ENV} ${KCONFIG_SAVEDEFCONFIG}
$(Q) $(call kconfig_tweak_disable,defconfig.tmp,CONFIG_APPS_DIR) $(Q) $(call kconfig_tweak_disable,defconfig.tmp,CONFIG_APPS_DIR)
$(Q) $(call kconfig_tweak_disable,defconfig.tmp,CONFIG_BASE_DEFCONFIG)
$(Q) grep "CONFIG_ARCH=" .config >> defconfig.tmp $(Q) grep "CONFIG_ARCH=" .config >> defconfig.tmp
$(Q) grep "^CONFIG_ARCH_CHIP_" .config >> defconfig.tmp; true $(Q) grep "^CONFIG_ARCH_CHIP_" .config >> defconfig.tmp; true
$(Q) grep "CONFIG_ARCH_CHIP=" .config >> defconfig.tmp; true $(Q) grep "CONFIG_ARCH_CHIP=" .config >> defconfig.tmp; true
@@ -763,6 +771,7 @@ endif
$(call DELFILE, defconfig) $(call DELFILE, defconfig)
$(call DELFILE, .config) $(call DELFILE, .config)
$(call DELFILE, .config.old) $(call DELFILE, .config.old)
$(call DELFILE, .config.orig)
$(call DELFILE, .gdbinit) $(call DELFILE, .gdbinit)
# Application housekeeping targets. The APPDIR variable refers to the user # Application housekeeping targets. The APPDIR variable refers to the user
+11
View File
@@ -235,6 +235,15 @@ tools\mkconfig$(HOSTEXEEXT):
$(Q) $(MAKE) -C tools -f Makefile.host mkconfig$(HOSTEXEEXT) $(Q) $(MAKE) -C tools -f Makefile.host mkconfig$(HOSTEXEEXT)
include\nuttx\config.h: $(TOPDIR)\.config tools\mkconfig$(HOSTEXEEXT) include\nuttx\config.h: $(TOPDIR)\.config tools\mkconfig$(HOSTEXEEXT)
$(Q) grep -v "CONFIG_BASE_DEFCONFIG" "$(TOPDIR)\.config" > "$(TOPDIR)\.config.tmp"
# In-place edit can mess up permissions on Windows
$(Q) if ! cmp -s "$(TOPDIR)\.config.tmp" "$(TOPDIR)\.config.orig" ; then \
sed "/CONFIG_BASE_DEFCONFIG/s/\"$$/-dirty\"/" "$(TOPDIR)\.config" > "$(TOPDIR)\.config-temp"; \
else \
sed "s/-dirty//g" "$(TOPDIR)\.config" > "$(TOPDIR)\.config-temp"; \
fi
$(Q) mv -f "$(TOPDIR)\.config-temp" "$(TOPDIR)\.config"
$(Q) rm -f "$(TOPDIR)\.config.tmp"
$(Q) tools\mkconfig$(HOSTEXEEXT) $(TOPDIR) > include\nuttx\config.h $(Q) tools\mkconfig$(HOSTEXEEXT) $(TOPDIR) > include\nuttx\config.h
# Targets used to create dependencies # Targets used to create dependencies
@@ -606,6 +615,7 @@ nconfig:
savedefconfig: apps_preconfig savedefconfig: apps_preconfig
$(Q) ${KCONFIG_ENV} kconfig-conf --savedefconfig defconfig.tmp Kconfig $(Q) ${KCONFIG_ENV} kconfig-conf --savedefconfig defconfig.tmp Kconfig
$(Q) kconfig-tweak --file defconfig.tmp -u CONFIG_APPS_DIR $(Q) kconfig-tweak --file defconfig.tmp -u CONFIG_APPS_DIR
$(Q) kconfig-tweak --file defconfig.tmp -u CONFIG_BASE_DEFCONFIG
$(Q) grep "CONFIG_ARCH=" .config >> defconfig.tmp $(Q) grep "CONFIG_ARCH=" .config >> defconfig.tmp
-$(Q) grep "^CONFIG_ARCH_CHIP_" .config >> defconfig.tmp -$(Q) grep "^CONFIG_ARCH_CHIP_" .config >> defconfig.tmp
-$(Q) grep "CONFIG_ARCH_CHIP=" .config >> defconfig.tmp -$(Q) grep "CONFIG_ARCH_CHIP=" .config >> defconfig.tmp
@@ -684,6 +694,7 @@ endif
$(call DELFILE, defconfig) $(call DELFILE, defconfig)
$(call DELFILE, .config) $(call DELFILE, .config)
$(call DELFILE, .config.old) $(call DELFILE, .config.old)
$(call DELFILE, .config.orig)
# Application housekeeping targets. The APPDIR variable refers to the user # Application housekeeping targets. The APPDIR variable refers to the user
# application directory. A sample apps\ directory is included with NuttX, # application directory. A sample apps\ directory is included with NuttX,
+41 -1
View File
@@ -104,6 +104,7 @@ static void disable_feature(const char *destconfig, const char *varname);
static void set_host(const char *destconfig); static void set_host(const char *destconfig);
static void configure(void); static void configure(void);
static void refresh(void); static void refresh(void);
static void save_original_config(void);
/**************************************************************************** /****************************************************************************
* Private Data * Private Data
@@ -1503,6 +1504,7 @@ static void configure(void)
{ {
FILE *stream; FILE *stream;
char *appdir = strdup(g_appdir); char *appdir = strdup(g_appdir);
char *boardcfg = strdup(g_boarddir);
/* One complexity is if we are using Windows paths, but the /* One complexity is if we are using Windows paths, but the
* configuration needs POSIX paths (or vice versa). * configuration needs POSIX paths (or vice versa).
@@ -1555,13 +1557,17 @@ static void configure(void)
if (!stream) if (!stream)
{ {
fprintf(stderr, fprintf(stderr,
"ERROR: Failed to open %s for append mode mode: %s\n", "ERROR: Failed to open %s for append mode: %s\n",
destconfig, strerror(errno)); destconfig, strerror(errno));
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
fprintf(stream, "\n# Application configuration\n\n"); fprintf(stream, "\n# Application configuration\n\n");
fprintf(stream, "CONFIG_APPS_DIR=\"%s\"\n", appdir); fprintf(stream, "CONFIG_APPS_DIR=\"%s\"\n", appdir);
substitute(boardcfg, '\\', '/');
fprintf(stream, "CONFIG_BASE_DEFCONFIG=\"%s\"\n", boardcfg);
fclose(stream); fclose(stream);
free(appdir); free(appdir);
} }
@@ -1590,6 +1596,37 @@ static void refresh(void)
} }
} }
static void save_original_config(void)
{
snprintf(g_buffer, BUFFER_SIZE, "%s%c.config", g_topdir, g_delim);
char *source_config = strdup(g_buffer);
snprintf(g_buffer, BUFFER_SIZE, "%s%c.config.orig", g_topdir, g_delim);
char *dest_config = strdup(g_buffer);
FILE *src_file = fopen(source_config, "r");
FILE *dest_file = fopen(dest_config, "w");
if (src_file == NULL || dest_file == NULL)
{
fprintf(stderr, "ERROR: Failed to open files\n");
exit(EXIT_FAILURE);
}
debug("save_original_config: Copying from %s to %s\n",
source_config, dest_config);
while (fgets(g_buffer, BUFFER_SIZE, src_file) != NULL)
{
if (strstr(g_buffer, "CONFIG_BASE_DEFCONFIG") == NULL)
{
fputs(g_buffer, dest_file);
}
}
fclose(src_file);
fclose(dest_file);
}
/**************************************************************************** /****************************************************************************
* Public Functions * Public Functions
****************************************************************************/ ****************************************************************************/
@@ -1621,5 +1658,8 @@ int main(int argc, char **argv, char **envp)
debug("main: Refresh configuration\n"); debug("main: Refresh configuration\n");
refresh(); refresh();
debug("main: Save original configuration\n");
save_original_config();
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
+11
View File
@@ -176,6 +176,7 @@ fi
src_config=${configpath}/defconfig src_config=${configpath}/defconfig
dest_config="${TOPDIR}/.config" dest_config="${TOPDIR}/.config"
original_config="${TOPDIR}/.config.orig"
backup_config="${TOPDIR}/defconfig" backup_config="${TOPDIR}/defconfig"
if [ ! -r ${src_config} ]; then if [ ! -r ${src_config} ]; then
@@ -303,7 +304,17 @@ if [ "X${defappdir}" = "Xy" ]; then
fi fi
fi fi
# Update the CONFIG_BASE_DEFCONFIG setting
posboardconfig=`echo "${boardconfig}" | sed -e 's/\\\\/\\//g'`
echo "CONFIG_BASE_DEFCONFIG=\"$posboardconfig\"" >> "${dest_config}"
# The saved defconfig files are all in compressed format and must be # The saved defconfig files are all in compressed format and must be
# reconstitued before they can be used. # reconstitued before they can be used.
${TOPDIR}/tools/sethost.sh $host $* ${TOPDIR}/tools/sethost.sh $host $*
# Save the original configuration file without CONFIG_BASE_DEFCONFIG
# for later comparison
grep -v "CONFIG_BASE_DEFCONFIG" "${dest_config}" > "${original_config}"