Skip to contentSkip to conversation

scripts/config: allow "O=config-dir" option

PATCH Superseded Randy Dunlap 2 participants 3 messages Oct 31, 2021 – Nov 2, 2021 Kbuild

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 scripts/config: allow "O=config-dir" option

Support "O=config-dir" as the location of the .config file like (some) other kernel build (make) tools do.

Someone asked for this "feature" a few months ago but I don't recall who it was.

Also check for the existence of the config-dir/config-file and report if there is no such file instead of letting grep report that there is no such file.

Cc Masahiro Yamada <[email protected]>
Cc Nick Desaulniers <[email protected]>
Cc Andi Kleen <[email protected]>
---
 scripts/config |   44 +++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 39 insertions(+), 5 deletions(-)
scripts/config +39 -5
@@ -37,6 +37,7 @@ commands:
 
 options:
 	--file config-file   .config file to change (default .config)
+	O=config-dir         Specify the directory location of the config-file
 	--keep-case|-k       Keep next symbols' case (dont' upper-case it)
 
 $myname doesn't check the validity of the .config file. This is done at next
@@ -124,15 +125,48 @@ undef_var() {
 	txt_delete "^# $name is not set" "$FN"
 }
 
-if [ "$1" = "--file" ]; then
-	FN="$2"
-	if [ "$FN" = "" ] ; then
+DIR=
+FN=
+
+while [ "$DIR" = "" -o "$FN" = "" ]; do
+
+	if [ "$1" = "" ] ; then
 		usage
 	fi
-	shift 2
-else
+	if [ "$1" = "--file" ]; then
+		FN="$2"
+		if [ "$FN" = "" ] ; then
+			usage
+		fi
+		shift 2
+		continue
+	fi
+
+	optn=$1
+	optnlen=${#optn}
+	if [ $optnlen -gt 1 ] && [ ${optn:0:2} = "O=" ]; then
+		DIR=${optn:2}
+		shift
+		if [ "$DIR" = "" ]; then
+			usage
+		fi
+		continue
+	fi
+	break	# something other than --file or O=dir
+done
+
+if [ "$FN" = "" ]; then
 	FN=.config
 fi
+if [ "$DIR" != "" ]; then
+	DIR=$DIR"/"
+fi
+FN="$DIR""$FN"
+
+if [ ! -r $FN ]; then
+	echo "No such config file: $FN"
+	exit
+fi
 
 if [ "$1" = "" ] ; then
 	usage
Reviewed-by on v1 1/1
#1 lore raw
Quoted 30 lines · Randy Dunlap

Support "O=config-dir" as the location of the .config file like (some) other kernel build (make) tools do.

Someone asked for this "feature" a few months ago but I don't recall who it was.

Also check for the existence of the config-dir/config-file and report if there is no such file instead of letting grep report that there is no such file.

Cc Masahiro Yamada <[email protected]>
Cc Nick Desaulniers <[email protected]>
Cc Andi Kleen <[email protected]>
---
 scripts/config |   44 +++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 39 insertions(+), 5 deletions(-)
scripts/config +1 -0
@@ -37,6 +37,7 @@ commands:
 
 options:
 	--file config-file   .config file to change (default .config)
+	O=config-dir         Specify the directory location of the config-file
 	--keep-case|-k       Keep next symbols' case (dont' upper-case it)
 
 $myname doesn't check the validity of the .config file. This is done at next

scripts/config undef_var() { · line 131

Quoted 10 lines
scripts/config +4 -3
@@ -124,15 +125,48 @@ undef_var() {
 	txt_delete "^# $name is not set" "$FN"
 }
 
-if [ "$1" = "--file" ]; then
-	FN="$2"
-	if [ "$FN" = "" ] ; then
+DIR=
+FN=
+
+while [ "$DIR" = "" -o "$FN" = "" ]; do

shellcheck recommends to use [ .. ] || [ .. ] instead of [ .. -o .. ].

Quoted 25 lines
scripts/config +21 -2
+
+	if [ "$1" = "" ] ; then
 		usage
 	fi
-	shift 2
-else
+	if [ "$1" = "--file" ]; then
+		FN="$2"
+		if [ "$FN" = "" ] ; then
+			usage
+		fi
+		shift 2
+		continue
+	fi
+
+	optn=$1
+	optnlen=${#optn}
+	if [ $optnlen -gt 1 ] && [ ${optn:0:2} = "O=" ]; then
+		DIR=${optn:2}
+		shift
+		if [ "$DIR" = "" ]; then
+			usage
+		fi
+		continue
+	fi

scripts/config undef_var() { · line 164

Quoted 10 lines
scripts/config +8 -0
+	break	# something other than --file or O=dir
+done
+
+if [ "$FN" = "" ]; then
 	FN=.config
 fi
+if [ "$DIR" != "" ]; then
+	DIR=$DIR"/"
+fi
+FN="$DIR""$FN"

A bike shed colour thing: I'd prefer quotes around the complete right hand side, e.g. "${DIR}/${FN}".

scripts/config undef_var() { · line 166

Quoted 2 lines
scripts/config +2 -0
+
+if [ ! -r $FN ]; then
             ^^^

$FN needs quotes, otherwise it may lead to syntax errors, e.g. if FN contains spaces or other syntactical things.

I do like that feature!

With quotes round $FN:

Quoted 6 lines
scripts/config +3 -0
+	echo "No such config file: $FN"
+	exit
+fi
 
 if [ "$1" = "" ] ; then
 	usage
#2 lore raw
Quoted 21 lines · Nicolas Schier
Quoted 10 lines · Randy Dunlap

Support "O=config-dir" as the location of the .config file like (some) other kernel build (make) tools do.

Someone asked for this "feature" a few months ago but I don't recall who it was.

Also check for the existence of the config-dir/config-file and report if there is no such file instead of letting grep report that there is no such file.

Quoted 9 lines
Cc Masahiro Yamada <[email protected]>
Cc Nick Desaulniers <[email protected]>
Cc Andi Kleen <[email protected]>
---
  scripts/config |   44 +++++++++++++++++++++++++++++++++++++++-----
  1 file changed, 39 insertions(+), 5 deletions(-)
Quoted 4 lines

I do like that feature!

With quotes round $FN:

Thanks, I'll do those changes and resend it.

Signature · 1 line
~Randy