Skip to contentSkip to conversation

ld-version: use /usr/bin/env awk for shebank

PATCH In review Dominique Martinet 5 participants 10 messages Dec 1, 2020 – Dec 10, 2020 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 ld-version: use /usr/bin/env awk for shebank

/usr/bin/awk is not garanteed to exist (and doesn't on e.g. nixos), using /usr/bin/env to have it look in PATH is more robust

---
I've been carrying these two patchs for local kernel development on nixos for a while, I don't think it'd break anything for anyone so might as well submit these -- please consider it :)

 scripts/ld-version.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/ld-version.sh +1 -1
index f2be0ff9a738..05476b8f8925 100755
@@ -1,4 +1,4 @@
-#!/usr/bin/awk -f
+#!/usr/bin/env -S awk -f
 # SPDX-License-Identifier: GPL-2.0
 # extract linker version number from stdin and turn into single number
 	{
Signature · 1 line
2.28.0
#1 lore raw

PATCH 2/2 kbuild: don't hardcode depmod path

depmod is not guaranteed to be in /sbin, just let make look for it in the path like all the other invoked programs

---
 Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Makefile +1 -1
index 9e7fd6a065a7..d7bd114836a9 100644
@@ -452,7 +452,7 @@ LEX		= flex
 YACC		= bison
 AWK		= awk
 INSTALLKERNEL  := installkernel
-DEPMOD		= /sbin/depmod
+DEPMOD		= depmod
 PERL		= perl
 PYTHON		= python
 PYTHON3		= python3
Signature · 1 line
2.28.0
#2 lore raw
In reply to Dominique Martinet
Quoted 6 lines · Dominique Martinet

/usr/bin/awk is not garanteed to exist (and doesn't on e.g. nixos), using /usr/bin/env to have it look in PATH is more robust

---

Both applied to linux-kbuild. Thanks.

Quoted 20 lines

I've been carrying these two patchs for local kernel development on nixos for a while, I don't think it'd break anything for anyone so might as well submit these -- please consider it :)

 scripts/ld-version.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/ld-version.sh +1 -2
index f2be0ff9a738..05476b8f8925 100755
@@ -1,4 +1,4 @@
-#!/usr/bin/awk -f
+#!/usr/bin/env -S awk -f
 # SPDX-License-Identifier: GPL-2.0
 # extract linker version number from stdin and turn into single number
        {
--

2.28.0

Signature · 2 lines
Best Regards
Masahiro Yamada
#3 lore raw
In reply to Dominique Martinet

Hi Dominique,

Quoted 3 lines · Dominique Martinet

/usr/bin/awk is not garanteed to exist (and doesn't on e.g. nixos), using /usr/bin/env to have it look in PATH is more robust

This patch breaks the compilation on Ubuntu 16.04 and 18.04 in fact:

make[1]: Entering directory '/data1/Projects/LinuxKernel/linux-out'

  GEN     Makefile
  HOSTCC  scripts/basic/fixdep
  HOSTCC  scripts/kconfig/conf.o
  HOSTCC  scripts/kconfig/confdata.o
  HOSTCC  scripts/kconfig/expr.o
  LEX     scripts/kconfig/lexer.lex.c
  YACC    scripts/kconfig/parser.tab.[ch]
  HOSTCC  scripts/kconfig/lexer.lex.o
  HOSTCC  scripts/kconfig/parser.tab.o
  HOSTCC  scripts/kconfig/preprocess.o
  HOSTCC  scripts/kconfig/symbol.o
  HOSTCC  scripts/kconfig/util.o
  HOSTLD  scripts/kconfig/conf

*** Default configuration is based on 'defconfig'
/usr/bin/env: invalid option -- 'S'
Try '/usr/bin/env --help' for more information.
init/Kconfig:39: syntax error
init/Kconfig:38: invalid statement /data1/Projects/LinuxKernel/linux-mte/scripts/kconfig/Makefile:80: recipe for target 'defconfig' failed
make[2]: *** [defconfig] Error 1 /data1/Projects/LinuxKernel/linux-mte/Makefile:602: recipe for target 'defconfig' failed
make[1]: *** [defconfig] Error 2
make[1]: Leaving directory '/data1/Projects/LinuxKernel/linux-out' Makefile:185: recipe for target '__sub-make' failed
make: *** [__sub-make] Error 2

The problem seems to be that the minimum version of env that supports '-S' is 8.30.

Reverting the patch fixes the issue.

Thanks!

Quoted 20 lines

---
I've been carrying these two patchs for local kernel development on nixos for a while, I don't think it'd break anything for anyone so might as well submit these -- please consider it :)

 scripts/ld-version.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/ld-version.sh +1 -1
index f2be0ff9a738..05476b8f8925 100755
@@ -1,4 +1,4 @@
-#!/usr/bin/awk -f
+#!/usr/bin/env -S awk -f
 # SPDX-License-Identifier: GPL-2.0
 # extract linker version number from stdin and turn into single number
 	{
Signature · 2 lines
Regards,
Vincenzo
#4 lore raw

Vincenzo Frascino wrote on Wed, Dec 09, 2020:

Quoted 5 lines · Dominique Martinet
Quoted 2 lines

/usr/bin/awk is not garanteed to exist (and doesn't on e.g. nixos), using /usr/bin/env to have it look in PATH is more robust

This patch breaks the compilation on Ubuntu 16.04 and 18.04 in fact:

Thanks for the report, I was told the same by Krzysztof Kozlowski (added to Ccs) earlier today, I don't have any "old" machines like this around so didn't notice when I checked unfortunately :(

I've suggested either just reverting this (I'll keep my local workaround) or going through /bin/sh which is always safe like the following patch -- leaving this to maintainers.

Thanks!
-----
From d53ef3b4c55aa2ea5f9ae887b3e1ace368f30f66 Mon Sep 17 00:00:00 2001
From: Dominique Martinet <[email protected]>
Date: Wed, 15 Jul 2020 16:00:13 +0200
Subject: [PATCH] ld-version: use /bin/sh then awk for shebank

/usr/bin/awk is not garanteed to exist (and doesn't on e.g. nixos), using /bin/sh and invoking awk to have it look in PATH is more robust.

scripts/ld-version.sh +3 -3
index f2be0ff9a738..02dbad7b5613 100755
@@ -1,11 +1,11 @@
-#!/usr/bin/awk -f
+#!/bin/sh
 # SPDX-License-Identifier: GPL-2.0
 # extract linker version number from stdin and turn into single number
-       {
+awk '{
        gsub(".*\\)", "");
        gsub(".*version ", "");
        gsub("-.*", "");
        split($1,a, ".");
        print a[1]*100000000 + a[2]*1000000 + a[3]*10000;
        exit
-       }
+}'
#9 lore raw
In reply to Dominique Martinet
Quoted 18 lines · Dominique Martinet

/usr/bin/awk is not garanteed to exist (and doesn't on e.g. nixos), using /usr/bin/env to have it look in PATH is more robust

---
I've been carrying these two patchs for local kernel development on nixos for a while, I don't think it'd break anything for anyone so might as well submit these -- please consider it :)

 scripts/ld-version.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/ld-version.sh +0 -0
index f2be0ff9a738..05476b8f8925 100755

scripts/ld-version.sh line 1

Quoted 2 lines
scripts/ld-version.sh +1 -1
@@ -1,4 +1,4 @@
-#!/usr/bin/awk -f
+#!/usr/bin/env -S awk -f

This patch results in:

/usr/bin/env: invalid option -- 'S'
Try '/usr/bin/env --help' for more information. init/Kconfig:39: syntax error
init/Kconfig:38: invalid statement scripts/kconfig/Makefile:80: recipe for target 'defconfig' failed

when using:

env (GNU coreutils) 8.28

or any other version of "env" which doesn't support "-S".

Guenter

#5 lore raw
In reply to Dominique Martinet

From: Dominique Martinet

Quoted 27 lines

Sent: 09 December 2020 17:43

I've suggested either just reverting this (I'll keep my local workaround) or going through /bin/sh which is always safe like the following patch -- leaving this to maintainers.

Thanks!
-----
From d53ef3b4c55aa2ea5f9ae887b3e1ace368f30f66 Mon Sep 17 00:00:00 2001
From: Dominique Martinet <[email protected]>
Date: Wed, 15 Jul 2020 16:00:13 +0200
Subject: [PATCH] ld-version: use /bin/sh then awk for shebank

/usr/bin/awk is not garanteed to exist (and doesn't on e.g. nixos), using /bin/sh and invoking awk to have it look in PATH is more robust.

scripts/ld-version.sh +1 -1
index f2be0ff9a738..02dbad7b5613 100755
@@ -1,11 +1,11 @@
-#!/usr/bin/awk -f
+#!/bin/sh
 # SPDX-License-Identifier: GPL-2.0
 # extract linker version number from stdin and turn into single number

scripts/ld-version.sh line 11

Quoted 10 lines
scripts/ld-version.sh +2 -2
-       {
+awk '{
        gsub(".*\\)", "");
        gsub(".*version ", "");
        gsub("-.*", "");
        split($1,a, ".");
        print a[1]*100000000 + a[2]*1000000 + a[3]*10000;
        exit
-       }
+}'

Why bother with awk?
I think you can do it all in a shell function.
Something like:

	read line
	line=${line##*)}
	line=${line##*version }
	IFS='.-'
	set $line
	echo $(($1*100000000 + $2*1000000 + $3*10000))

That will work on any recent shell.

David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)

#6 lore raw

Hi Dominique and Dave,

Quoted 42 lines · David Laight

From: Dominique Martinet

Quoted 27 lines

Sent: 09 December 2020 17:43

I've suggested either just reverting this (I'll keep my local workaround) or going through /bin/sh which is always safe like the following patch -- leaving this to maintainers.

Thanks!
-----
From d53ef3b4c55aa2ea5f9ae887b3e1ace368f30f66 Mon Sep 17 00:00:00 2001
From: Dominique Martinet <[email protected]>
Date: Wed, 15 Jul 2020 16:00:13 +0200
Subject: [PATCH] ld-version: use /bin/sh then awk for shebank

/usr/bin/awk is not garanteed to exist (and doesn't on e.g. nixos), using /bin/sh and invoking awk to have it look in PATH is more robust.

scripts/ld-version.sh +1 -1
index f2be0ff9a738..02dbad7b5613 100755
@@ -1,11 +1,11 @@
-#!/usr/bin/awk -f
+#!/bin/sh
 # SPDX-License-Identifier: GPL-2.0
 # extract linker version number from stdin and turn into single number

scripts/ld-version.sh line 11

Quoted 10 lines
scripts/ld-version.sh +2 -2
-       {
+awk '{
        gsub(".*\\)", "");
        gsub(".*version ", "");
        gsub("-.*", "");
        split($1,a, ".");
        print a[1]*100000000 + a[2]*1000000 + a[3]*10000;
        exit
-       }
+}'

Why bother with awk?
I think you can do it all in a shell function.
Something like:

Quoted 9 lines
	read line
	line=${line##*)}
	line=${line##*version }
	IFS='.-'
	set $line
	echo $(($1*100000000 + $2*1000000 + $3*10000))

That will work on any recent shell.

I would suggest to revert the patch for now since we are close to the merge window and then maybe in -rc1 start discussing a better solution.

What do you think?

Quoted 6 lines

David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)

Signature · 2 lines
Regards,
Vincenzo
#7 lore raw

Vincenzo Frascino wrote on Thu, Dec 10, 2020:

Quoted 2 lines · David Laight
Quoted 1 line

Why bother with awk?

I wanted to keep the patch minimal, I'm not opposed to rewriting but that always potentially has more impact (although as you say, this script is simple enough)

Quoted 10 lines
Quoted 10 lines

I think you can do it all in a shell function.
Something like:

	read line
	line=${line##*)}
	line=${line##*version }
	IFS='.-'
	set $line
	echo $(($1*100000000 + $2*1000000 + $3*10000))

That will work on any recent shell.

Works for me.

Quoted 2 lines

I would suggest to revert the patch for now since we are close to the merge window and then maybe in -rc1 start discussing a better solution.

As far as I can see the patch is only in -next, as said earlier I'm in favor of just dropping the patch until a decision is taken for the next merge window (or the one after that); there's no hurry for me and nothing to revert.

Signature · 1 line
Dominique
#8 lore raw

From: 'Dominique Martinet'

Quoted 19 lines

Sent: 10 December 2020 12:22

Vincenzo Frascino wrote on Thu, Dec 10, 2020:

Quoted 2 lines · David Laight
Quoted 1 line

Why bother with awk?

I wanted to keep the patch minimal, I'm not opposed to rewriting but that always potentially has more impact (although as you say, this script is simple enough)

Quoted 9 lines
Quoted 9 lines

I think you can do it all in a shell function.
Something like:

	read line
	line=${line##*)}
	line=${line##*version }
	IFS='.-'
	set $line
	echo $(($1*100000000 + $2*1000000 + $3*10000))
Quoted 3 lines
Quoted 1 line
Quoted 1 line

That will work on any recent shell.

Works for me.

That was a very quick rewrite of what I think the awk script did. However I think the version is in the last space-separated word. So you can do (untested):

	read line
	set line
	shift $(($#-1))
	OIFS="$IFS"
	IFS='.-'
	set $1
	IFS="$OIFS"
	echo $(($1*100000000 + $2*1000000 + $3*10000))

Now, if you want a version that will work with a real bourne shell (that doesn't support $((expr)) or $(x##b} it gets more interesting.

Yes, but for now, revert first.
It might even be that the whole file isn't needed.
If it only used from a Makefile it can be gone with gmake commands.

David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)