pkgsrc-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[pkgsrc/trunk]: pkgsrc/mk Improved license detection for the guess-license ta...



details:   https://anonhg.NetBSD.org/pkgsrc/rev/2c1cc57446bb
branches:  trunk
changeset: 373568:2c1cc57446bb
user:      rillig <rillig%pkgsrc.org@localhost>
date:      Fri Jan 05 07:54:39 2018 +0000

description:
Improved license detection for the guess-license target.

Before, the first file that looked like a license file was considered.
The others were completely ignored. This led to a wrong license for
cross/arm-none-eabi-gcc. To prevent these cases in the future, the license
is only guessed if there is exactly one file with a typical license name.

This approach is still naive, but at least a little more precise. Replacing
the guess-license with a determine-licenses is much more complicated
though, since each source code file may have its own license declared, and
handling all these special cases leads to very complex license expressions
(like "gnu-gpl-v3 for all files, except for special.c, which is apache-2.0
or mit). This is very hard to do correctly.

diffstat:

 mk/license.mk |  29 ++++++++++++++---------------
 1 files changed, 14 insertions(+), 15 deletions(-)

diffs (46 lines):

diff -r 1a599e4fe94c -r 2c1cc57446bb mk/license.mk
--- a/mk/license.mk     Fri Jan 05 03:16:10 2018 +0000
+++ b/mk/license.mk     Fri Jan 05 07:54:39 2018 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: license.mk,v 1.82 2018/01/03 00:41:37 rillig Exp $
+# $NetBSD: license.mk,v 1.83 2018/01/05 07:54:39 rillig Exp $
 #
 # This file handles everything about the LICENSE variable. It is
 # included automatically by bsd.pkg.mk.
@@ -248,23 +248,22 @@
        ${PHASE_MSG} "Guessing package license"; \
        type wdiff > /dev/null 2>&1 || ${FAIL_MSG} "To guess the license, textproc/wdiff must be installed."; \
        \
+       pkgfiles=`find ${WRKSRC} -type f -print | ${EGREP} '/COPYING|/LICEN[CS]E|/COPYRIGHT' | LC_ALL=C ${SORT}`; \
+       case $$pkgfiles in *'${.newline}'*) printf "The package has more than one license file:\n\n%s\n" "$$pkgfiles"; exit; esac; \
+       \
        { \
-       printf "%8s   %s\n" "Wdiff" "License"; \
        bestsize=1000000; \
        bestlicense=; \
-       for pkglicense in ${WRKSRC}/COPYING ${WRKSRC}/LICENSE ${WRKSRC}/COPYRIGHT; do \
-           for license in ${PKGSRCDIR}/licenses/*; do \
-             if [ -f "$$pkglicense" ] && [ -f "$$license" ]; then \
-               size=`{ wdiff -3 "$$pkglicense" "$$license" || true; } | wc -c`; \
-               if [ "$$size" -lt "$$bestsize" ]; then \
-                 printf "%8d   %s\n" "$$size" "$${license##*/}"; \
-                 bestsize="$$size"; \
-                 bestlicense="$$license"; \
-               fi \
-             fi \
-           done; \
-         if [ "$$bestlicense" ]; then \
-           break; \
+       pkglicense="$$pkgfiles"; \
+       ${PRINTF} "%8s   %s\n" "Wdiff" "License"; \
+       for license in ${PKGSRCDIR}/licenses/*; do \
+         if [ -f "$$pkglicense" ] && [ -f "$$license" ]; then \
+           size=`{ wdiff -3 "$$pkglicense" "$$license" || true; } | wc -c`; \
+           if [ "$$size" -lt "$$bestsize" ]; then \
+             ${PRINTF} "%8d   %s\n" "$$size" "$${license##*/}"; \
+             bestsize="$$size"; \
+             bestlicense="$$license"; \
+           fi \
          fi \
        done; \
        \



Home | Main Index | Thread Index | Old Index