Skip to contentSkip to conversation

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

PATCH In review Randy Dunlap 3 participants 3 messages Nov 2, 2021 – Nov 11, 2021 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH v2 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.

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.

---
v2:
- use 'shellcheck' and other recommendations from Nicolas
- move one comment from the commit description to under the "---" line

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

 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" = "" ] || [ "$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
#1 lore raw
Quoted 8 lines · Randy Dunlap

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

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 7 lines

---

Why don't you use --file path/to/output/dir/.config ?

Quoted 74 lines

v2:
- use 'shellcheck' and other recommendations from Nicolas
- move one comment from the commit description to under the "---" line

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

 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" = "" ] || [ "$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
Signature · 2 lines
Best Regards
Masahiro Yamada
#2 lore raw

Hi Masahiro,

Quoted 17 lines · On Fri, Nov 05, 2021 at 12:41:59AM +0900 Masahiro Yamada wrote:
Quoted 8 lines · Randy Dunlap

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

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 7 lines

---

Quoted 1 line

Why don't you use --file path/to/output/dir/.config ?

I did not ask for the patch, but it matches some typical situations I experience at work. Building kernels out-of-source w/ 'O=' but modifying .config with the '--file' option does not feel "natural". And 'O=' in scripts/config allows reusing make arguments (readline/bash's ESC-n ESC-.).

Having the 'O=' argument, it might allow fixing the '--refresh' option to support out-of-source builds.

Thus, no really great points from me.

Kind regards,
Nicolas

Quoted 80 lines
Quoted 74 lines

v2:
- use 'shellcheck' and other recommendations from Nicolas
- move one comment from the commit description to under the "---" line

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

 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" = "" ] || [ "$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
Signature · 2 lines
Best Regards
Masahiro Yamada
Signature · 3 lines
epost|xmpp: [email protected]          irc://oftc.net/nsc
↳ gpg: 18ed 52db e34f 860e e9fb  c82b 7d97 0932 55a0 ce7f
     -- frykten for herren er opphav til kunnskap --