diff mbox

[U-Boot,v2,2/4] kconfig: fix whitespace handling bug of savedefconfig

Message ID 1409776894-30441-3-git-send-email-yamada.m@jp.panasonic.com
State Accepted
Delegated to: Tom Rini
Headers show

Commit Message

Masahiro Yamada Sept. 3, 2014, 8:41 p.m. UTC
Commit 3ff291f371fa9858426774f3732924bacb61ed1c
(kconfig: convert Kconfig helper script into a shell script)
introduced another regression.

Shell usually handles whitespaces as separators,
so "make saveconfig" outputs

  # CONFIG_FOO is not set

into:

  #
  CONFIG_FOO
  is
  not
  set

Whitespaces should not be treated as separators here.

Signed-off-by: Masahiro Yamada <yamada.m@jp.panasonic.com>
---

Changes in v2:
  - Resend as a series
  - Change the commit subject

 scripts/multiconfig.sh | 37 +++++++++++++++++++++++++++++--------
 1 file changed, 29 insertions(+), 8 deletions(-)

Comments

Simon Glass Sept. 3, 2014, 11:49 p.m. UTC | #1
Hi Masahiro,

On 3 September 2014 14:41, Masahiro Yamada <yamada.m@jp.panasonic.com> wrote:
> Commit 3ff291f371fa9858426774f3732924bacb61ed1c
> (kconfig: convert Kconfig helper script into a shell script)
> introduced another regression.
>
> Shell usually handles whitespaces as separators,
> so "make saveconfig" outputs
>
>   # CONFIG_FOO is not set
>
> into:
>
>   #
>   CONFIG_FOO
>   is
>   not
>   set
>
> Whitespaces should not be treated as separators here.

Oh dear...python is so much better at dealing with parameters and strings.

>
> Signed-off-by: Masahiro Yamada <yamada.m@jp.panasonic.com>

Acked-by: Simon Glass <sjg@chromium.org>

Regards,
Simon
Masahiro Yamada Sept. 4, 2014, 1:10 p.m. UTC | #2
Hi Simon,

2014-09-04 8:49 GMT+09:00 Simon Glass <sjg@chromium.org>:
> Hi Masahiro,
>
> On 3 September 2014 14:41, Masahiro Yamada <yamada.m@jp.panasonic.com> wrote:
>> Commit 3ff291f371fa9858426774f3732924bacb61ed1c
>> (kconfig: convert Kconfig helper script into a shell script)
>> introduced another regression.
>>
>> Shell usually handles whitespaces as separators,
>> so "make saveconfig" outputs
>>
>>   # CONFIG_FOO is not set
>>
>> into:
>>
>>   #
>>   CONFIG_FOO
>>   is
>>   not
>>   set
>>
>> Whitespaces should not be treated as separators here.
>
> Oh dear...python is so much better at dealing with parameters and strings.
>

Shell script is much more difficult than Python (and Perl)
for text processing.

This is really unfortunate...
Tom Rini Sept. 17, 2014, 12:45 a.m. UTC | #3
On Thu, Sep 04, 2014 at 05:41:32AM +0900, Masahiro Yamada wrote:

> Commit 3ff291f371fa9858426774f3732924bacb61ed1c
> (kconfig: convert Kconfig helper script into a shell script)
> introduced another regression.
> 
> Shell usually handles whitespaces as separators,
> so "make saveconfig" outputs
> 
>   # CONFIG_FOO is not set
> 
> into:
> 
>   #
>   CONFIG_FOO
>   is
>   not
>   set
> 
> Whitespaces should not be treated as separators here.
> 
> Signed-off-by: Masahiro Yamada <yamada.m@jp.panasonic.com>
> Acked-by: Simon Glass <sjg@chromium.org>

Applied to u-boot/master, thanks!
diff mbox

Patch

diff --git a/scripts/multiconfig.sh b/scripts/multiconfig.sh
index 785f563..7606193 100644
--- a/scripts/multiconfig.sh
+++ b/scripts/multiconfig.sh
@@ -170,7 +170,7 @@  do_savedefconfig () {
 	# backslashes as an escape character
 	while read -r line
 	do
-		output_lines="$output_lines $line"
+		output_lines="$output_lines%$line"
 	done < defconfig
 
 	for img in $subimages
@@ -185,43 +185,64 @@  do_savedefconfig () {
 			tmp=
 			match=
 
+			# "# CONFIG_FOO is not set" should not be divided.
+			# Use "%" as a separator, instead of a whitespace.
+			# "%" is unlikely to appear in defconfig context.
+			save_IFS=$IFS
+			IFS=%
 			# coalesce common lines together
 			for i in $output_lines
 			do
 				case "$i" in
 				"[+A-Z]*:$line")
-					tmp="$tmp $unmatched"
+					tmp="$tmp%$unmatched"
 					i=$(echo "$i" | \
 					    sed -e "s/^\([^:]\)*/\1$symbol/")
-					tmp="$tmp $i"
+					tmp="$tmp%$i"
 					match=1
 					;;
 				"$line")
-					tmp="$tmp $unmatched"
-					tmp="$tmp +$symbol:$i"
+					tmp="$tmp%$unmatched"
+					tmp="$tmp%+$symbol:$i"
 					match=1
 					;;
 				*)
-					tmp="$tmp $i"
+					tmp="$tmp%$i"
 					;;
 				esac
 			done
 
+			# Restore the default separator for the outer for loop.
+			IFS=$save_IFS
+
 			if [ "$match" ]; then
 				output_lines="$tmp"
 				unmatched=
 			else
-				unmatched="$unmatched $symbol:$line"
+				unmatched="$unmatched%$symbol:$line"
 			fi
 		done < defconfig
 	done
 
 	rm -f defconfig
 	touch defconfig
+
+	save_IFS=$IFS
+	IFS=%
+
 	for line in $output_lines
 	do
-		echo $line >> defconfig
+		case "$line" in
+		"")
+			# do not output blank lines
+			;;
+		*)
+			echo $line >> defconfig
+			;;
+		esac
 	done
+
+	IFS=$save_IFS
 }
 
 # Usage: