Skip to contentSkip to conversation

kbuild: some scripts/config improvements (try 2)

PATCH In review Michal Marek 3 participants 5 messages May 25, 2009 – Jun 14, 2009

lore
Share & tools
lore
#0 lore raw

cover kbuild: some scripts/config improvements (try 2)

Hi,

I simplified the awk script a bit, made it awk ... && mv and removed the --set option.

Michal Marek (3):
kbuild: handle non-existing options in scripts/config
kbuild: simplify argument loop in scripts/config
kbuild: add generic --set-str option to scripts/config

 scripts/config |   97 +++++++++++++++++++++++++++++--------------------------
 1 files changed, 51 insertions(+), 46 deletions(-)
#1 lore raw
Quoted 9 lines · Michal Marek

Hi,

I simplified the awk script a bit, made it awk ... && mv and removed the --set option.

Michal Marek (3):
kbuild: handle non-existing options in scripts/config
kbuild: simplify argument loop in scripts/config
kbuild: add generic --set-str option to scripts/config

Andi - do I have your ack on this serie?

Sam

#2 lore raw
Quoted 6 lines · Sam Ravnborg
Quoted 5 lines · Michal Marek

Hi,

I simplified the awk script a bit, made it awk ... && mv and removed the --set option.

Quoted 6 lines
Quoted 4 lines

Michal Marek (3):
kbuild: handle non-existing options in scripts/config
kbuild: simplify argument loop in scripts/config
kbuild: add generic --set-str option to scripts/config

Andi - do I have your ack on this serie?

Reluctantly -- most bits are ok, but the awk change seems quite overcomplicated and I don't like it particularly.

-Andi

Signature · 1 line
[email protected] -- Speaking for myself only.
#3 lore raw
Quoted 12 lines · Andi Kleen
Quoted 11 lines · Sam Ravnborg
Quoted 9 lines · Michal Marek

Hi,

I simplified the awk script a bit, made it awk ... && mv and removed the --set option.

Michal Marek (3):
kbuild: handle non-existing options in scripts/config
kbuild: simplify argument loop in scripts/config
kbuild: add generic --set-str option to scripts/config

Quoted 4 lines
Quoted 1 line

Andi - do I have your ack on this serie?

Reluctantly -- most bits are ok, but the awk change seems quite overcomplicated and I don't like it particularly.

What about this one? The other two patches apply apply at slightly different offsets.

Subject: [PATCH 1/3] kbuild: handle non-existing options in scripts/config

If an option does not exist in .config, set it at the end of the file.

---
 scripts/config |   36 ++++++++++++++++++------------------
 1 files changed, 18 insertions(+), 18 deletions(-)
scripts/config +18 -18
index db6084b..30825a5 100755
@@ -26,8 +26,6 @@ options:
 
 config doesn't check the validity of the .config file. This is done at next
  make time.
-The options need to be already in the file before they can be changed,
-but sometimes you can cheat with the --*-after options.
 EOL
 	exit 1
 }
@@ -45,8 +43,18 @@ checkarg() {
 	ARG="`echo $ARG | tr a-z A-Z`"
 }
 
-replace() {
-	sed -i -e "$@" $FN
+set_var() {
+	local name=$1 new=$2 before=$3
+
+	name_re="^($name=|# $name is not set)"
+	before_re="^($before=|# $before is not set)"
+	if test -n "$before" && grep -Eq "$before_re" "$FN"; then
+		sed -ri "/$before_re/a $new" "$FN"
+	elif grep -Eq "$name_re" "$FN"; then
+		sed -ri "s:$name_re.*:$new:" "$FN"
+	else
+		echo "$new" >>"$FN"
+	fi
 }
 
 if [ "$1" = "--file" ]; then
@@ -70,20 +78,19 @@ while [ "$1" != "" ] ; do
 	case "$CMD" in
 	--enable|-e)
 		checkarg "$1"
-		replace "s/# CONFIG_$ARG is not set/CONFIG_$ARG=y/"
+		set_var "CONFIG_$ARG" "CONFIG_$ARG=y"
 		shift
 		;;
 
 	--disable|-d)
 		checkarg "$1"
-		replace "s/CONFIG_$ARG=[my]/# CONFIG_$ARG is not set/"
+		set_var "CONFIG_$ARG" "# CONFIG_$ARG is not set"
 		shift
 		;;
 
 	--module|-m)
 		checkarg "$1"
-		replace "s/CONFIG_$ARG=y/CONFIG_$ARG=m/" \
-			-e "s/# CONFIG_$ARG is not set/CONFIG_$ARG=m/"
+		set_var "CONFIG_$ARG" "CONFIG_$ARG=m"
 		shift
 		;;
 
@@ -109,9 +116,7 @@ while [ "$1" != "" ] ; do
 		A=$ARG
 		checkarg "$2"
 		B=$ARG
-		replace "/CONFIG_$A=[my]/aCONFIG_$B=y" \
-			-e "/# CONFIG_$ARG is not set/a/CONFIG_$ARG=y" \
-			-e "s/# CONFIG_$ARG is not set/CONFIG_$ARG=y/"
+		set_var "CONFIG_$B" "CONFIG_$B=y" "CONFIG_$A"
 		shift
 		shift
 		;;
@@ -121,9 +126,7 @@ while [ "$1" != "" ] ; do
 		A=$ARG
 		checkarg "$2"
 		B=$ARG
-		replace "/CONFIG_$A=[my]/a# CONFIG_$B is not set" \
-		-e "/# CONFIG_$ARG is not set/a/# CONFIG_$ARG is not set" \
-		-e "s/CONFIG_$ARG=[my]/# CONFIG_$ARG is not set/"
+		set_var "CONFIG_$B" "# CONFIG_$B is not set" "CONFIG_$A"
 		shift
 		shift
 		;;
@@ -133,10 +136,7 @@ while [ "$1" != "" ] ; do
 		A=$ARG
 		checkarg "$2"
 		B=$ARG
-		replace "/CONFIG_$A=[my]/aCONFIG_$B=m" \
-			-e "/# CONFIG_$ARG is not set/a/CONFIG_$ARG=m" \
-			-e "s/CONFIG_$ARG=y/CONFIG_$ARG=m/" \
-			-e "s/# CONFIG_$ARG is not set/CONFIG_$ARG=m/"
+		set_var "CONFIG_$B" "CONFIG_$B=m" "CONFIG_$A"
 		shift
 		shift
 		;;
Signature · 1 line
1.6.3
#4 lore raw
Quoted 18 lines · Michal Marek
Quoted 12 lines · Andi Kleen
Quoted 11 lines · Sam Ravnborg
Quoted 9 lines · Michal Marek

Hi,

I simplified the awk script a bit, made it awk ... && mv and removed the --set option.

Michal Marek (3):
kbuild: handle non-existing options in scripts/config
kbuild: simplify argument loop in scripts/config
kbuild: add generic --set-str option to scripts/config

Quoted 4 lines
Quoted 1 line

Andi - do I have your ack on this serie?

Reluctantly -- most bits are ok, but the awk change seems quite overcomplicated and I don't like it particularly.

Quoted 8 lines

What about this one? The other two patches apply apply at slightly different offsets.

Subject: [PATCH 1/3] kbuild: handle non-existing options in scripts/config

If an option does not exist in .config, set it at the end of the file.

Looked readable - compared to the awk stuff.
I have applied all three patches.

Sam