Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1345227 > unrolled thread

Re: [PATCH v3 6/7] create/adjust generated/autoksyms.h

Started byZev Weiss <zev@bewilderbeest.net>
First post2016-02-28 13:20 +0100
Last post2016-02-28 20:40 +0100
Articles 2 — 2 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: [PATCH v3 6/7] create/adjust generated/autoksyms.h Zev Weiss <zev@bewilderbeest.net> - 2016-02-28 13:20 +0100
    Re: [PATCH v3 6/7] create/adjust generated/autoksyms.h Nicolas Pitre <nicolas.pitre@linaro.org> - 2016-02-28 20:40 +0100

#1345227 — Re: [PATCH v3 6/7] create/adjust generated/autoksyms.h

FromZev Weiss <zev@bewilderbeest.net>
Date2016-02-28 13:20 +0100
SubjectRe: [PATCH v3 6/7] create/adjust generated/autoksyms.h
Message-ID<r78ul-29E-9@gated-at.bofh.it>
On Thu, Feb 18, 2016 at 15:07:02 -0500, Nicolas Pitre wrote:
>diff --git a/scripts/adjust_autoksyms.sh b/scripts/adjust_autoksyms.sh
>new file mode 100755
>index 0000000000..898a3ca1b2
>--- /dev/null
>+++ b/scripts/adjust_autoksyms.sh
>@@ -0,0 +1,97 @@
>+#!/bin/sh

Given the here-strings in this script, this should probably be /bin/bash 
or breakage will ensue on Debian and suchlike where /bin/sh != bash.  
However...

>+sed -ns -e '3s/ /\n/gp' "$MODVERDIR"/*.mod | sort -u |
>+while read sym; do
>+	if [ -n "$CONFIG_HAVE_UNDERSCORE_SYMBOL_PREFIX" ]; then
>+		sym=$(sed 's/^_//' <<< "$sym")

...this one could (shell-portably and more efficiently) be a parameter 
expansion (sym="${sym#_}").

>+
>+# Extract changes between old and new list and touch corresponding
>+# dependency files.
>+# Note: sort -m doesn't work well with underscore prefixed symbols so we
>+# use 'cat ... | sort' instead.
>+changed=0
>+while read sympath; do
>+	[ -z "$sympath" ] && continue
>+	depfile="include/config/ksym/${sympath}.h"
>+	mkdir -p "$(dirname "$depfile")"
>+	touch "$depfile"
>+	changed=$((changed + 1))
>+done <<< "$(
>+	cat "$cur_ksyms_file" "$new_ksyms_file" | sort | uniq -u |
>+	sed -n 's/^#define __KSYM_\(.*\) 1/\1/p' | tr "A-Z_" "a-z/"  )"

Nothing super-obvious springs to mind as a pure-sh equivalent for this 
one though, so assuming the script remains bash-specific, a process 
substitution like

  done < <(cat ...)

might slightly cleaner than the here-string + command substitution 
(doesn't need quoting, and just streams through a pipe rather than bash 
snarfing it all up into a string).

[toc] | [next] | [standalone]


#1345375

FromNicolas Pitre <nicolas.pitre@linaro.org>
Date2016-02-28 20:40 +0100
Message-ID<r7fm9-7nb-1@gated-at.bofh.it>
In reply to#1345227
On Sun, 28 Feb 2016, Zev Weiss wrote:

> On Thu, Feb 18, 2016 at 15:07:02 -0500, Nicolas Pitre wrote:
> >diff --git a/scripts/adjust_autoksyms.sh b/scripts/adjust_autoksyms.sh
> >new file mode 100755
> >index 0000000000..898a3ca1b2
> >--- /dev/null
> >+++ b/scripts/adjust_autoksyms.sh
> > @@ -0,0 +1,97 @@
> >+#!/bin/sh
> 
> Given the here-strings in this script, this should probably be /bin/bash or
> breakage will ensue on Debian and suchlike where /bin/sh != bash.  However...
> 
> >+sed -ns -e '3s/ /\n/gp' "$MODVERDIR"/*.mod | sort -u |
> >+while read sym; do
> >+	if [ -n "$CONFIG_HAVE_UNDERSCORE_SYMBOL_PREFIX" ]; then
> >+		sym=$(sed 's/^_//' <<< "$sym")
> 
> ...this one could (shell-portably and more efficiently) be a parameter
> expansion (sym="${sym#_}").

Indeed.

> >+
> >+# Extract changes between old and new list and touch corresponding
> >+# dependency files.
> >+# Note: sort -m doesn't work well with underscore prefixed symbols so we
> >+# use 'cat ... | sort' instead.
> >+changed=0
> >+while read sympath; do
> >+	[ -z "$sympath" ] && continue
> >+	depfile="include/config/ksym/${sympath}.h"
> >+	mkdir -p "$(dirname "$depfile")"
> >+	touch "$depfile"
> >+	changed=$((changed + 1))
> >+done <<< "$(
> >+	cat "$cur_ksyms_file" "$new_ksyms_file" | sort | uniq -u |
> >+	sed -n 's/^#define __KSYM_\(.*\) 1/\1/p' | tr "A-Z_" "a-z/"  )"
> 
> Nothing super-obvious springs to mind as a pure-sh equivalent for this one
> though, so assuming the script remains bash-specific, a process substitution
> like
> 
>  done < <(cat ...)
> 
> might slightly cleaner than the here-string + command substitution (doesn't
> need quoting, and just streams through a pipe rather than bash snarfing it all
> up into a string).

Right.  Still, I decided to make it compatible with a simpler shell. I 
applied the following changes and tested it with dash.

diff --git a/scripts/adjust_autoksyms.sh b/scripts/adjust_autoksyms.sh
index 898a3ca1b2..a145a24cd8 100755
--- a/scripts/adjust_autoksyms.sh
+++ b/scripts/adjust_autoksyms.sh
@@ -57,9 +57,7 @@ cat > "$new_ksyms_file" << EOT
 EOT
 sed -ns -e '3s/ /\n/gp' "$MODVERDIR"/*.mod | sort -u |
 while read sym; do
-	if [ -n "$CONFIG_HAVE_UNDERSCORE_SYMBOL_PREFIX" ]; then
-		sym=$(sed 's/^_//' <<< "$sym")
-	fi
+	[ -n "$CONFIG_HAVE_UNDERSCORE_SYMBOL_PREFIX" ] && sym="${sym#_}"
 	echo "#define __KSYM_${sym} 1"
 done >> "$new_ksyms_file"
 
@@ -72,16 +70,18 @@ fi
 # dependency files.
 # Note: sort -m doesn't work well with underscore prefixed symbols so we
 # use 'cat ... | sort' instead.
-changed=0
+changed=$(
+count=0
+cat "$cur_ksyms_file" "$new_ksyms_file" | sort | uniq -u |
+sed -n 's/^#define __KSYM_\(.*\) 1/\1/p' | tr "A-Z_" "a-z/" |
 while read sympath; do
 	[ -z "$sympath" ] && continue
 	depfile="include/config/ksym/${sympath}.h"
 	mkdir -p "$(dirname "$depfile")"
 	touch "$depfile"
-	changed=$((changed + 1))
-done <<< "$(
-	cat "$cur_ksyms_file" "$new_ksyms_file" | sort | uniq -u |
-	sed -n 's/^#define __KSYM_\(.*\) 1/\1/p' | tr "A-Z_" "a-z/"  )"
+	echo $((count += 1))
+done | tail -1 )
+changed=${changed:-0}
 
 if [ $changed -gt 0 ]; then
 	# Replace the old list with tne new one

Nicolas

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web