Skip to contentSkip to conversation

scripts: kconfig: merge_config: config files: add a trailing newline

PATCH Superseded Anders Roxell 2 participants 5 messages Aug 2, 2024 – Aug 6, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 scripts: kconfig: merge_config: config files: add a trailing newline

When merging files without trailing newlines a the end of the file, two config fragments end up at the same row if file1.config doens't have a trailing newline at the end of the file.

file1.config "CONFIG_1=y"
file2.config "CONFIG_2=y"
./scripts/kconfig/merge_config.sh -m .config file1.config file2.config

this will generate a .config lookingn like this.
cat .config
...
CONFIG_1=yCONFIG_2=y"

Making sure so we add a newline at the end of every config file that is passed into the script.

---
 scripts/kconfig/merge_config.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/kconfig/merge_config.sh +1 -1
index 902eb429b9db..ce1b77ee043b 100755
@@ -136,7 +136,7 @@ for ORIG_MERGE_FILE in $MERGE_LIST ; do
 		echo "The merge file '$ORIG_MERGE_FILE' does not exist.  Exit." >&2
 		exit 1
 	fi
-	cat $ORIG_MERGE_FILE > $MERGE_FILE
+	cat $ORIG_MERGE_FILE | sed -e '$a\' > $MERGE_FILE
 	CFG_LIST=$(sed -n -e "$SED_CONFIG_EXP1" -e "$SED_CONFIG_EXP2" $MERGE_FILE)
 
 	for CFG in $CFG_LIST ; do
Signature · 1 line
2.43.0
#1 lore raw
Quoted 27 lines · Anders Roxell

When merging files without trailing newlines a the end of the file, two config fragments end up at the same row if file1.config doens't have a trailing newline at the end of the file.

file1.config "CONFIG_1=y"
file2.config "CONFIG_2=y"
./scripts/kconfig/merge_config.sh -m .config file1.config file2.config

this will generate a .config lookingn like this.
cat .config
...
CONFIG_1=yCONFIG_2=y"

Making sure so we add a newline at the end of every config file that is passed into the script.

---
 scripts/kconfig/merge_config.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/kconfig/merge_config.sh +0 -0
index 902eb429b9db..ce1b77ee043b 100755

scripts/kconfig/merge_config.sh for ORIG_MERGE_FILE in $MERGE_LIST ; do · line 139

Quoted 5 lines
scripts/kconfig/merge_config.sh +1 -1
@@ -136,7 +136,7 @@ for ORIG_MERGE_FILE in $MERGE_LIST ; do
                echo "The merge file '$ORIG_MERGE_FILE' does not exist.  Exit." >&2
                exit 1
        fi
-       cat $ORIG_MERGE_FILE > $MERGE_FILE
+       cat $ORIG_MERGE_FILE | sed -e '$a\' > $MERGE_FILE

Is the pipe necessary? This seems to be equivalent to:

sed -e '$a\' $ORIG_MERGE_FILE > $MERGE_FILE

This issue also happens if $INITFILE lacks a newline at the end.

I think the right place to insert a line is there:

# In case the previous file lacks a new line at the end echo >> $TMP_FILE
cat $MERGE_FILE >> $TMP_FILE

I am fine with always inserting a line between files.

Signature · 2 lines
Best Regards
Masahiro Yamada
#2 lore raw
Quoted 51 lines · Masahiro Yamada
Quoted 27 lines · Anders Roxell

When merging files without trailing newlines a the end of the file, two config fragments end up at the same row if file1.config doens't have a trailing newline at the end of the file.

file1.config "CONFIG_1=y"
file2.config "CONFIG_2=y"
./scripts/kconfig/merge_config.sh -m .config file1.config file2.config

this will generate a .config lookingn like this.
cat .config
...
CONFIG_1=yCONFIG_2=y"

Making sure so we add a newline at the end of every config file that is passed into the script.

---
 scripts/kconfig/merge_config.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/kconfig/merge_config.sh +0 -0
index 902eb429b9db..ce1b77ee043b 100755

scripts/kconfig/merge_config.sh for ORIG_MERGE_FILE in $MERGE_LIST ; do · line 139

Quoted 5 lines
scripts/kconfig/merge_config.sh +1 -1
@@ -136,7 +136,7 @@ for ORIG_MERGE_FILE in $MERGE_LIST ; do
                echo "The merge file '$ORIG_MERGE_FILE' does not exist.  Exit." >&2
                exit 1
        fi
-       cat $ORIG_MERGE_FILE > $MERGE_FILE
+       cat $ORIG_MERGE_FILE | sed -e '$a\' > $MERGE_FILE

Is the pipe necessary? This seems to be equivalent to:

sed -e '$a\' $ORIG_MERGE_FILE > $MERGE_FILE

This issue also happens if $INITFILE lacks a newline at the end.

I think the right place to insert a line is there:

Quoted 6 lines

# In case the previous file lacks a new line at the end echo >> $TMP_FILE
cat $MERGE_FILE >> $TMP_FILE

I am fine with always inserting a line between files.

Thank you Masahiro for your review.
Sending a v2 shortly.

Cheers,
Anders

#3 lore raw

PATCH v2 1/1 scripts: kconfig: merge_config: config files: add a trailing newline

In reply to Anders Roxell

When merging files without trailing newlines at the end of the file, two config fragments end up at the same row if file1.config doens't have a trailing newline at the end of the file.

file1.config "CONFIG_1=y"
file2.config "CONFIG_2=y"
./scripts/kconfig/merge_config.sh -m .config file1.config file2.config

This will generate a .config looking like this.
cat .config
...
CONFIG_1=yCONFIG_2=y"

Making sure so we add a newline at the end of every config file that is passed into the script.

---
 scripts/kconfig/merge_config.sh | 2 ++
 1 file changed, 2 insertions(+)
scripts/kconfig/merge_config.sh +2 -0
index 902eb429b9db..0b7952471c18 100755
@@ -167,6 +167,8 @@ for ORIG_MERGE_FILE in $MERGE_LIST ; do
 			sed -i "/$CFG[ =]/d" $MERGE_FILE
 		fi
 	done
+	# In case the previous file lacks a new line at the end
+	echo >> $TMP_FILE
 	cat $MERGE_FILE >> $TMP_FILE
 done
 
Signature · 1 line
2.43.0
#4 lore raw
Quoted 14 lines · Anders Roxell

When merging files without trailing newlines at the end of the file, two config fragments end up at the same row if file1.config doens't have a trailing newline at the end of the file.

file1.config "CONFIG_1=y"
file2.config "CONFIG_2=y"
./scripts/kconfig/merge_config.sh -m .config file1.config file2.config

This will generate a .config looking like this.
cat .config
...
CONFIG_1=yCONFIG_2=y"

Quoted 5 lines

Making sure so we add a newline at the end of every config file that is passed into the script.

---

Applied to linux-kbuild/fixes.
Thanks.

Quoted 19 lines
 scripts/kconfig/merge_config.sh | 2 ++
 1 file changed, 2 insertions(+)
scripts/kconfig/merge_config.sh +2 -1
index 902eb429b9db..0b7952471c18 100755
@@ -167,6 +167,8 @@ for ORIG_MERGE_FILE in $MERGE_LIST ; do
                        sed -i "/$CFG[ =]/d" $MERGE_FILE
                fi
        done
+       # In case the previous file lacks a new line at the end
+       echo >> $TMP_FILE
        cat $MERGE_FILE >> $TMP_FILE
 done
 
--

2.43.0

Signature · 2 lines
Best Regards
Masahiro Yamada