<div dir="ltr"><div dir="ltr">I think I'm ok on all three of these patches but some </div><div dir="ltr">comments on the shell script. I can see where this is a</div><div dir="ltr">tedious but important check. And it can be improved easily.<br><div><br></div><div>Since this smells like something Chris would poke me f</div><div>or and call a "Joel script" :)</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Sep 17, 2020 at 4:33 AM Christian Mauderer <<a href="mailto:christian.mauderer@embedded-brains.de">christian.mauderer@embedded-brains.de</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Update #4082<br>
---<br>
find_licenses_and_unused.sh | 121 ++++++++++++++++++++++++++++++++++++<br>
1 file changed, 121 insertions(+)<br>
create mode 100755 find_licenses_and_unused.sh<br>
<br>
diff --git a/find_licenses_and_unused.sh b/find_licenses_and_unused.sh<br>
new file mode 100755<br>
index 00000000..ee15f652<br>
--- /dev/null<br>
+++ b/find_licenses_and_unused.sh<br>
@@ -0,0 +1,121 @@<br>
+#!/bin/bash<br>
+<br>
+#<br>
+# Copyright (c) 2018 embedded brains GmbH. All rights reserved.<br>
+#<br>
+# embedded brains GmbH<br>
+# Dornierstr. 4<br>
+# 82178 Puchheim<br>
+# Germany<br>
+# <<a href="mailto:rtems@embedded-brains.de" target="_blank">rtems@embedded-brains.de</a>><br>
+#<br>
+# Redistribution and use in source and binary forms, with or without<br>
+# modification, are permitted provided that the following conditions<br>
+# are met:<br>
+# 1. Redistributions of source code must retain the above copyright<br>
+# notice, this list of conditions and the following disclaimer.<br>
+# 2. Redistributions in binary form must reproduce the above copyright<br>
+# notice, this list of conditions and the following disclaimer in the<br>
+# documentation and/or other materials provided with the distribution.<br>
+#<br>
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND<br>
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE<br>
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE<br>
+# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE<br>
+# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL<br>
+# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS<br>
+# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)<br>
+# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT<br>
+# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY<br>
+# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF<br>
+# SUCH DAMAGE.<br>
+#<br>
+<br>
+# exit on wrong command and undefined variable<br>
+set -e<br>
+set -u<br>
+set -o pipefail<br>
+<br>
+SCRIPTNAME=$0<br>
+TARGET="freebsd/"<br>
+SOURCE="freebsd-org/"<br>
+LIST="libbsd.py"<br>
+FORCE=0<br>
+<br>
+printhelp () {<br>
+ echo ""<br>
+ echo "Call: ${SCRIPTNAME} <options>"<br>
+ echo "1. Find LICENSE files for each file in \"${TARGET}\" if the"<br>
+ echo " license file is not in ${LIST}."<br>
+ echo "2. Find all files in \"${TARGET}\" that are not in \"${LIST}\"."<br>
+ echo " Note: This function currently prints a lot of generated files too."<br></blockquote><div><br></div><div>If they are generated, isn't there a source to generated file pattern that can be</div><div>taken advantage of to eliminate them from the output ahead of the dirname in</div><div>checkfile. Get the basename, switch on a set of known generated output </div><div>names, verify there is the correct input file, and then continue so it does not</div><div>show up in the output.</div><div><br></div><div>Reducing the noisy output seems important and straightforward. You know</div><div>how to do it by hand so there should be a few patterns.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+ echo "Reccomended usage:"<br></blockquote><div><br></div><div>Spelling.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+ echo "./${SCRIPTNAME} | sort | uniq"<br></blockquote><div><br></div><div>Just add this to the find line that drives everything. And why not sort -u?</div><div><br></div><div>If you want it to be an option, just put those in a second function and</div><div>pipe through that.</div><div><br></div><div>maybe_sort()</div><div>{</div><div> if [ ${do_sort} = "yes" ] l then</div><div> sort -u</div><div> else</div><div> cat</div><div> fi</div><div>}</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+ echo ""<br>
+ echo "The following parameters are optional:"<br>
+ echo " -h Print this help and exit the script."<br>
+ echo " -f Force printing all license files."<br>
+ echo " -v Be more verbose. Can be used multiple times."<br>
+ exit 0<br>
+}<br>
+<br>
+while getopts "hfv" OPTION<br>
+do<br>
+ case ${OPTION} in<br>
+ h) printhelp ;;<br>
+ f) FORCE=1 ;;<br>
+ \?) echo "Unknown option \"-${OPTARG}\"."<br>
+ exit 1 ;;<br>
+ :) echo "Option \"-${OPTARG}\" needs an argument."; exit 1 ;;<br>
+ esac<br>
+done<br>
+shift $((${OPTIND} - 1))<br>
+<br>
+checkfile () {<br>
+ local FILE="$1"<br>
+ local FILE_WITHOUT_PATH=${FILE#"$TARGET"}<br>
+ local LICENSE=""<br>
+<br>
+ grep "${FILE_WITHOUT_PATH}" "${LIST}" > /dev/null || \<br>
+ echo "File not in ${LIST}: ${FILE_WITHOUT_PATH}"<br>
+<br>
+ local DIR="${SOURCE}`dirname ${FILE_WITHOUT_PATH}`"<br>
+ while [ "$DIR" != "." ]<br>
+ do<br>
+ local MAYBELICENSE="${DIR}/LICENSE*"<br>
+ if [ -e ${MAYBELICENSE} ]<br>
+ then<br>
+ LICENSE=`ls ${MAYBELICENSE}`<br>
+ break<br>
+ fi<br>
+ local MAYBELICENSE="${DIR}/COPY*"<br>
+ if [ -e ${MAYBELICENSE} ]<br>
+ then<br>
+ LICENSE=`ls ${MAYBELICENSE}`<br>
+ break<br>
+ fi<br>
+ DIR="`dirname ${DIR}`"<br>
+ done<br>
+<br>
+ if [ "${LICENSE}" != "" ]<br>
+ then<br>
+ local LICENSE_WITHOUT_PATH=${LICENSE#"$SOURCE"}<br>
+ if grep "${LICENSE_WITHOUT_PATH}" "${LIST}" > /dev/null<br>
+ then<br>
+ if [ ${FORCE} -ne 0 ]<br>
+ then<br>
+ echo "License file found: ${LICENSE}"<br>
+ fi<br>
+ else<br>
+ echo "New license file found: ${LICENSE}"<br>
+ fi<br>
+ fi<br>
+}<br>
+<br>
+export -f checkfile<br>
+export TARGET<br>
+export SOURCE<br>
+export LIST<br>
+export FORCE<br>
+<br>
+find ${TARGET} -name "*\.[ch]" -exec bash -c 'checkfile "$0"' {} \;<br>
-- <br>
2.26.2<br>
<br>
_______________________________________________<br>
devel mailing list<br>
<a href="mailto:devel@rtems.org" target="_blank">devel@rtems.org</a><br>
<a href="http://lists.rtems.org/mailman/listinfo/devel" rel="noreferrer" target="_blank">http://lists.rtems.org/mailman/listinfo/devel</a><br>
</blockquote></div></div>