diff mbox series

[RFC] scripts/setlocalversion: avoid keeping double-quotes in UBOOTRELEASE

Message ID 20201027103006.27772-1-rasmus.villemoes@prevas.dk
State RFC
Headers show
Series [RFC] scripts/setlocalversion: avoid keeping double-quotes in UBOOTRELEASE | expand

Commit Message

Rasmus Villemoes Oct. 27, 2020, 10:30 a.m. UTC
CONFIG_LOCALVERSION is a string Kconfig item, so auto.conf always
contains a line of the form


(usually with nothing between the quotes). Since 81630a3b (scripts:
setlocalversion: safely extract variables from auto.conf using awk),
those quotes are no longer automatically stripped as part of the
shell sourcing auto.conf, so they get included in the value of the
shell variable CONFIG_LOCALVERSION, which in turn then bleeds to the
output and to include/config/uboot.release, which contains


They are still present in the value of the UBOOTRELEASE make
variable. When that variable is used to generate
version_autogenerated.h, we end up running the command

  echo \#define PLAIN_VERSION \"2020.10"foo"-00879-gae4fdd7b04\"

via the shell, and thus the quotes do finally get stripped via the
shell's rule for concatenating words (in essence, the evaluation by a
shell has been postponed till that point). However, UBOOTRELEASE is
also used in a few other places, e.g.

  -n "U-Boot $(UBOOTRELEASE) for $(BOARD) board"

so that expands to

  -n "U-Boot 2020.10"foo"-00879-gae4fdd7b04 for $(BOARD) board"

which (still) works, but mostly by chance.

To avoid those quotes from appearing in uboot.release and causing
confusion when one tries to debug things, and to get closer to how
Linux' setlocalversion works, while still avoiding evaluating the
lines that may contain $() constructs, grep for the few lines we're
interested in and eval those.

Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>

This is not really meant for applying, hence RFC. I hope to be able to
get U-Boot's and linux' copies completely in sync (since the last sync
a few weeks ago, 548b8b51 has landed in linux), so if this is ok in
principle, I'll try submitting the similar patch on the linux side,
and if that's accepted, we can do another sync after that.

 scripts/setlocalversion | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
diff mbox series


diff --git a/scripts/setlocalversion b/scripts/setlocalversion
index c1c0435267..8484bea07f 100755
--- a/scripts/setlocalversion
+++ b/scripts/setlocalversion
@@ -151,10 +151,9 @@  fi
 if test -e include/config/auto.conf; then
 	# We are interested only in CONFIG_LOCALVERSION and
-	# CONFIG_LOCALVERSION_AUTO, so extract these in a safe
-	# way (i.e. w/o sourcing auto.conf)
-	CONFIG_LOCALVERSION=`cat include/config/auto.conf | awk -F '=' '/^CONFIG_LOCALVERSION=/ {print $2}'`
-	CONFIG_LOCALVERSION_AUTO=`cat include/config/auto.conf | awk -F '=' '/^CONFIG_LOCALVERSION_AUTO=/ {print $2}'`
+	# CONFIG_LOCALVERSION_AUTO, so avoid other lines that may have
+	# odd side effects when evaluated.
+	eval "$(grep -E '^CONFIG_LOCALVERSION(_AUTO)?=' include/config/auto.conf)"
 	echo "Error: kernelrelease not valid - run 'make prepare' to update it" >&2
 	exit 1