[PATCH 3/9] Add has-spdx-header.sh script

Dodji Seketeli dodji@redhat.com
Mon Jul 13 11:09:27 GMT 2020


Jonathan Wakely <jwakely@redhat.com> writes:

> Do I really need to reply to all 9 patches and sign off on them?

Well, I guess you could have just responded to the cover letter with a
blanket signoff, but I am glad you haven't, since you've caught lots of
issues in your review and I am grateful for that.  Thanks a lot.


[...]


>>+main()
>>+{
>>+    header=$(head --lines=5 $file | grep "SPDX-License-Identifier:")
>>+    if test "x$header" != x; then
>>+	license=$(echo "$header" | sed -r "s/^.*(SPDX-License-Identifier:)[ 	]*([^*/]+).*$/\2/")
>>+    fi
>
> The separate grep seems unnecessary.
>
> license=$(head --lines=5 $file | sed -n -E "s/^.*(SPDX-License-Identifier:)[ 	]*([^*/]+).*$/\2/p")
>
> The -E option is the POSIX version of -r.
>
> The -n option and the 'p' suffix means only the matching line will be
> printed.

You are right.  Fixed.

[...]

>>+
>>+    if test "x$license" = x; then
>>+	emit_output_no_license
>>+    else
>>+	emit_output_with_license "$license"
>>+    fi
>>+}
>>+
>>+while test $# -ge 1
>>+do
>>+    case "$1" in
>>+	-h|--help)
>>+	    display_usage
>>+	    exit 1
>
> Shouldn't it exit with status 0 when asked to print the usage?

Done.

>
>>+	    ;;
>>+
>>+	-f|--file)
>>+	    if test x$2 = x; then
>>+		display_usage
>
> Should usage be printed to stderr when exiting with an error?

Done.

[...]

Here is the updated version of this patch.  It'll be part of the v2 of
the series that I'll be sending out shortly.

Thanks!


>From d6822cba1036405e52a4eb6e53394bc46d6a4987 Mon Sep 17 00:00:00 2001
From: Dodji Seketeli <dodji@redhat.com>
Date: Wed, 27 May 2020 18:40:17 +0200
Subject: [PATCH 3/9] Add has-spdx-header.sh script

Add a script to detect if a file has a SPDX header and what the
advertised license is.

	   * relicensing-scripts/has-spdx-header.sh: New script.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
Signed-off-by: Matthias Maennich <maennich@google.com>
---
 relicensing-scripts/has-spdx-header.sh | 105 +++++++++++++++++++++++++++++++++
 1 file changed, 105 insertions(+)
 create mode 100755 relicensing-scripts/has-spdx-header.sh

diff --git a/relicensing-scripts/has-spdx-header.sh b/relicensing-scripts/has-spdx-header.sh
new file mode 100755
index 0000000..d4b7e08
--- /dev/null
+++ b/relicensing-scripts/has-spdx-header.sh
@@ -0,0 +1,105 @@
+#!/bin/sh
+# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+# Author: Dodji Seketeli <dodji@redhat.com>
+
+file=
+prog=$0
+display_file_name=
+be_quiet=
+show_no_spdx=
+
+display_usage()
+{
+    echo "$prog: [options] file"
+    echo "  where options can be:"
+    echo "   -h|--help		display this help"
+    echo "   -f|--file		prefix output with file name"
+    echo "   -q|--quiet		emit no output if no license was found"
+    echo "   --show-no-spdx	show file name if it has no spdx header"
+}
+
+emit_output_no_license()
+{
+    if test x$show_no_spdx != x; then
+	echo $display_file_name
+    elif test x$be_quiet = x; then
+	if test "x$display_file_name" = x; then
+	    echo "NO-LICENSE"
+	else
+	    echo "$display_file_name: NO-LICENSE"
+	fi
+    fi
+
+    exit 1
+}
+
+emit_output_with_license()
+{
+    license=$1
+    if test x$show_no_spdx != x; then
+	:
+    elif test "x$display_file_name" = x; then
+	echo "$license"
+    else
+	echo "$display_file_name: $license"
+    fi
+    exit 0
+}
+
+main()
+{
+    license=$(head --lines=5 $file | sed -n -E "s/^.*(SPDX-License-Identifier:)[ 	]*([^*/]+).*$/\2/p")
+
+    if test "x$license" = x; then
+	emit_output_no_license
+    else
+	emit_output_with_license "$license"
+    fi
+}
+
+while test $# -ge 1
+do
+    case "$1" in
+	-h|--help)
+	    display_usage
+	    exit 0
+	    ;;
+
+	-f|--file)
+	    if test x$2 = x; then
+		>&2 display_usage
+		exit 1
+	    fi
+	    display_file_name=$2
+	    shift
+	    ;;
+
+	-q|--quiet)
+	    be_quiet=yes
+	    shift
+	    ;;
+
+	--show-no-spdx)
+	    if test x$2 = x; then
+		>&2 display_usage
+		exit 1
+	    fi
+	    show_no_spdx=yes
+	    display_file_name=$2
+	    shift
+	    ;;
+
+	*)
+	    break
+	    ;;
+    esac
+done
+
+if test $# -lt 1; then
+    >&2 display_usage
+    exit 1
+fi
+
+file=$1
+
+main
-- 
1.8.3.1


-- 
		Dodji



More information about the Libabigail mailing list