This is an automated email from the ASF dual-hosted git repository.
acassis pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new 6a220a08ba tools: Add way to get current defconfig name on runtime
6a220a08ba is described below
commit 6a220a08ba86f39d7be9b8d903ccd295ef916b16
Author: Lucas Saavedra Vaz <[email protected]>
AuthorDate: Thu Jun 1 18:43:48 2023 -0300
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.
---
Kconfig | 9 +++++++++
tools/Unix.mk | 9 +++++++++
tools/Win.mk | 11 +++++++++++
tools/configure.c | 42 +++++++++++++++++++++++++++++++++++++++++-
tools/configure.sh | 11 +++++++++++
5 files changed, 81 insertions(+), 1 deletion(-)
diff --git a/Kconfig b/Kconfig
index b7a1ac4e6d..3641b60b93 100644
--- a/Kconfig
+++ b/Kconfig
@@ -244,6 +244,15 @@ config APPS_DIR
example, to include makefile fragments (e.g., .config or
Make.defs)
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
bool
option modules
diff --git a/tools/Unix.mk b/tools/Unix.mk
index fbef72124a..879ec7b865 100644
--- a/tools/Unix.mk
+++ b/tools/Unix.mk
@@ -248,6 +248,13 @@ tools/mkconfig$(HOSTEXEEXT):
$(Q) $(MAKE) -C tools -f Makefile.host 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) > [email protected]
$(Q) $(call TESTANDREPLACEFILE, [email protected], $@)
@@ -685,6 +692,7 @@ gconfig: apps_preconfig
savedefconfig: apps_preconfig
$(Q) ${KCONFIG_ENV} ${KCONFIG_SAVEDEFCONFIG}
$(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_CHIP_" .config >> defconfig.tmp; true
$(Q) grep "CONFIG_ARCH_CHIP=" .config >> defconfig.tmp; true
@@ -763,6 +771,7 @@ endif
$(call DELFILE, defconfig)
$(call DELFILE, .config)
$(call DELFILE, .config.old)
+ $(call DELFILE, .config.orig)
$(call DELFILE, .gdbinit)
# Application housekeeping targets. The APPDIR variable refers to the user
diff --git a/tools/Win.mk b/tools/Win.mk
index 6a400278c5..55e68b767d 100644
--- a/tools/Win.mk
+++ b/tools/Win.mk
@@ -235,6 +235,15 @@ tools\mkconfig$(HOSTEXEEXT):
$(Q) $(MAKE) -C tools -f Makefile.host 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
# Targets used to create dependencies
@@ -606,6 +615,7 @@ nconfig:
savedefconfig: apps_preconfig
$(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_BASE_DEFCONFIG
$(Q) grep "CONFIG_ARCH=" .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, .config)
$(call DELFILE, .config.old)
+ $(call DELFILE, .config.orig)
# Application housekeeping targets. The APPDIR variable refers to the user
# application directory. A sample apps\ directory is included with NuttX,
diff --git a/tools/configure.c b/tools/configure.c
index ccdb096eae..958fbf04b5 100644
--- a/tools/configure.c
+++ b/tools/configure.c
@@ -104,6 +104,7 @@ static void disable_feature(const char *destconfig, const
char *varname);
static void set_host(const char *destconfig);
static void configure(void);
static void refresh(void);
+static void save_original_config(void);
/****************************************************************************
* Private Data
@@ -1503,6 +1504,7 @@ static void configure(void)
{
FILE *stream;
char *appdir = strdup(g_appdir);
+ char *boardcfg = strdup(g_boarddir);
/* One complexity is if we are using Windows paths, but the
* configuration needs POSIX paths (or vice versa).
@@ -1555,13 +1557,17 @@ static void configure(void)
if (!stream)
{
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));
exit(EXIT_FAILURE);
}
fprintf(stream, "\n# Application configuration\n\n");
fprintf(stream, "CONFIG_APPS_DIR=\"%s\"\n", appdir);
+
+ substitute(boardcfg, '\\', '/');
+ fprintf(stream, "CONFIG_BASE_DEFCONFIG=\"%s\"\n", boardcfg);
+
fclose(stream);
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
****************************************************************************/
@@ -1621,5 +1658,8 @@ int main(int argc, char **argv, char **envp)
debug("main: Refresh configuration\n");
refresh();
+
+ debug("main: Save original configuration\n");
+ save_original_config();
return EXIT_SUCCESS;
}
diff --git a/tools/configure.sh b/tools/configure.sh
index 5551eebcd0..04344a28b1 100755
--- a/tools/configure.sh
+++ b/tools/configure.sh
@@ -176,6 +176,7 @@ fi
src_config=${configpath}/defconfig
dest_config="${TOPDIR}/.config"
+original_config="${TOPDIR}/.config.orig"
backup_config="${TOPDIR}/defconfig"
if [ ! -r ${src_config} ]; then
@@ -303,7 +304,17 @@ if [ "X${defappdir}" = "Xy" ]; then
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
# reconstitued before they can be used.
${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}"