Source-Changes-HG archive

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

[pkgsrc/trunk]: pkgsrc mk/check/check-portability: skip X.in if X is patched



details:   https://anonhg.NetBSD.org/pkgsrc/rev/cb137a4e5e90
branches:  trunk
changeset: 430843:cb137a4e5e90
user:      rillig <rillig%pkgsrc.org@localhost>
date:      Mon May 04 21:32:48 2020 +0000

description:
mk/check/check-portability: skip X.in if X is patched

A commonly occuring scenario is that a package patches the configure
script, but that the corresponding configure.in contains shell code that
is not portable.  In cases like these, configure.in is typically not used
during the build, therefore there is no need to check it for portability.

This also applies to all other combinations where a file is patched and
the corresponding file.in contains unportable shell code.

diffstat:

 mk/check/check-portability.mk                |    3 +-
 mk/check/check-portability.sh                |    9 +-
 mk/check/check-subr.awk                      |    4 +-
 regress/infra-unittests/check-portability.sh |  177 +++++++++++++++++++++++++++
 4 files changed, 189 insertions(+), 4 deletions(-)

diffs (244 lines):

diff -r fcaaa7ed0f97 -r cb137a4e5e90 mk/check/check-portability.mk
--- a/mk/check/check-portability.mk     Mon May 04 21:32:15 2020 +0000
+++ b/mk/check/check-portability.mk     Mon May 04 21:32:48 2020 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: check-portability.mk,v 1.14 2020/03/13 08:11:36 rillig Exp $
+# $NetBSD: check-portability.mk,v 1.15 2020/05/04 21:32:48 rillig Exp $
 #
 # This file contains some checks that are applied to the configure
 # scripts to check for certain constructs that are known to cause
@@ -43,4 +43,5 @@
        cd ${WRKSRC};                                                   \
        env     SKIP_FILTER=${CHECK_PORTABILITY_SKIP:@p@${p}) skip=yes;;@:Q} \
                PREFIX=${PREFIX}                                        \
+               PATCHDIR=${PATCHDIR}                                    \
                sh ${PKGSRCDIR}/mk/check/check-portability.sh
diff -r fcaaa7ed0f97 -r cb137a4e5e90 mk/check/check-portability.sh
--- a/mk/check/check-portability.sh     Mon May 04 21:32:15 2020 +0000
+++ b/mk/check/check-portability.sh     Mon May 04 21:32:48 2020 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: check-portability.sh,v 1.19 2020/03/13 08:11:36 rillig Exp $
+# $NetBSD: check-portability.sh,v 1.20 2020/05/04 21:32:48 rillig Exp $
 #
 # This program checks all files in the current directory and any
 # subdirectories for portability issues that are likely to result in
@@ -34,6 +34,8 @@
        fi
 }
 
+patched_files=",$(awk 'BEGIN { ORS = "," } /^\+\+\+ / { print $2 }' "$PATCHDIR"/patch-*),"
+
 find ./* -type f -print 2>/dev/null \
 | sed 's,$,_,' \
 | {
@@ -44,6 +46,11 @@
 
                skip=no
                eval "case \"\$fname\" in $SKIP_FILTER *.orig) skip=yes;; esac"
+               case "$fname" in *.in)
+                       case ",$patched_files," in *,"${fname%.in}",*)
+                               skip=yes
+                       esac
+               esac
                [ $skip = no ] || continue
 
                skip_shebang_test=no
diff -r fcaaa7ed0f97 -r cb137a4e5e90 mk/check/check-subr.awk
--- a/mk/check/check-subr.awk   Mon May 04 21:32:15 2020 +0000
+++ b/mk/check/check-subr.awk   Mon May 04 21:32:48 2020 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: check-subr.awk,v 1.3 2006/12/31 13:35:10 rillig Exp $
+# $NetBSD: check-subr.awk,v 1.4 2020/05/04 21:32:48 rillig Exp $
 #
 # This file contains functions that are used by the various awk
 # programs that check things in pkgsrc. All these programs must be
@@ -7,7 +7,7 @@
 # CK_FNAME
 #      The name of the file that is checked. Since awk interprets
 #      command line arguments in a weird way, the input file must be
-#      passed via stdin.
+#      passed via the environment.
 #
 # CK_PROGNAME
 #      The program name to be used in diagnostic messages.
diff -r fcaaa7ed0f97 -r cb137a4e5e90 regress/infra-unittests/check-portability.sh
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/regress/infra-unittests/check-portability.sh      Mon May 04 21:32:48 2020 +0000
@@ -0,0 +1,177 @@
+#! /bin/sh
+# $NetBSD: check-portability.sh,v 1.1 2020/05/04 21:32:48 rillig Exp $
+#
+# Test cases for mk/check/check-portability.*.
+#
+
+set -eu
+
+. "./test.subr"
+
+# Runs the shell program for the given file.
+check_portability_sh() {
+       env     PATCHDIR='patches' \
+               PREFIX='/nonexistent' \
+               sh "$pkgsrcdir/mk/check/check-portability.sh" \
+               1>"$tmpdir/out" 2>&1 \
+       && exitcode=0 || exitcode=$?
+}
+
+# Runs the AWK program in standalone mode for the given file.
+check_portability_awk() {
+       env     CK_FNAME="$1" \
+               CK_PROGNAME='check-portability.awk' \
+               awk     -f "$pkgsrcdir/mk/check/check-subr.awk" \
+                       -f "$pkgsrcdir/mk/check/check-portability.awk" \
+                       "$1" \
+               1>"$tmpdir/out" 2>&1 \
+       && exitcode=0 || exitcode=$?
+}
+
+test_case_set_up() {
+       rm -rf "$tmpdir/work"
+       mkdir "$tmpdir/work"
+       cd "$tmpdir/work"
+}
+
+# TODO: remove the "work/" from the tests.
+# The $tmpdir must be a bit structured:
+# $tmpdir/pkgsrc       these files override the actual pkgsrc files
+# $tmpdir/work         current working directory
+
+
+if test_case_begin "test ... = ..."; then
+
+       create_file_lines 'work/file' \
+               'if [ "$var" = value ]; then' \
+               '  ...' \
+               'elif test "$var" = value ]; then' \
+               '  ...' \
+               'fi'
+
+       check_portability_awk 'file'
+
+       assert_that 'out' --file-is-empty
+       assert_that $exitcode --equals 0
+
+       test_case_end
+fi
+
+
+if test_case_begin 'test ... == ...'; then
+
+       create_file_lines 'work/file' \
+               'if [ "$var" == value ]; then' \
+               '  ...' \
+               'elif test "$var" == value ]; then' \
+               '  ...' \
+               'fi'
+
+       check_portability_awk 'file'
+
+       create_file 'expected' <<'EOF'
+ERROR: [check-portability.awk] => Found test ... == ...:
+ERROR: [check-portability.awk] file:1: if [ "$var" == value ]; then
+ERROR: [check-portability.awk] file:3: elif test "$var" == value ]; then
+
+Explanation:
+===========================================================================
+The "test" command, as well as the "[" command, are not required to know
+the "==" operator. Only a few implementations like bash and some
+versions of ksh support it.
+
+When you run "test foo == foo" on a platform that does not support the
+"==" operator, the result will be "false" instead of "true". This can
+lead to unexpected behavior.
+
+There are two ways to fix this error message. If the file that contains
+the "test ==" is needed for building the package, you should create a
+patch for it, replacing the "==" operator with "=". If the file is not
+needed, add its name to the CHECK_PORTABILITY_SKIP variable in the
+package Makefile.
+===========================================================================
+
+EOF
+       assert_that 'out' --file-equals 'expected'
+       assert_that $exitcode --equals 1
+
+       test_case_end
+fi
+
+
+if test_case_begin 'configure patched, configure.in bad'; then
+
+       create_file_lines 'work/patches/patch-aa' \
+               '+++ configure 2020-05-04'
+       create_file_lines 'work/configure' \
+               '#! /bin/sh' \
+               'good'
+       create_file_lines 'work/configure.in' \
+               'test a == b'
+
+       check_portability_sh
+
+       assert_that "out" --file-is-empty
+       assert_that $exitcode --equals 0
+
+       test_case_end
+fi
+
+
+if test_case_begin 'configure patched and still bad'; then
+
+       create_file_lines 'work/patches/patch-aa' \
+               '+++ configure 2020-05-04'
+       create_file_lines 'work/configure' \
+               '#! /bin/sh' \
+               'test a == b'
+
+       check_portability_sh
+
+       create_file 'expected' <<'EOF'
+ERROR: [check-portability.awk] => Found test ... == ...:
+ERROR: [check-portability.awk] configure:2: test a == b
+
+Explanation:
+===========================================================================
+The "test" command, as well as the "[" command, are not required to know
+the "==" operator. Only a few implementations like bash and some
+versions of ksh support it.
+
+When you run "test foo == foo" on a platform that does not support the
+"==" operator, the result will be "false" instead of "true". This can
+lead to unexpected behavior.
+
+There are two ways to fix this error message. If the file that contains
+the "test ==" is needed for building the package, you should create a
+patch for it, replacing the "==" operator with "=". If the file is not
+needed, add its name to the CHECK_PORTABILITY_SKIP variable in the
+package Makefile.
+===========================================================================
+
+EOF
+       assert_that 'out' --file-equals 'expected'
+       assert_that $exitcode --equals 1
+
+       test_case_end
+fi
+
+
+if test_case_begin 'special characters in filenames'; then
+
+       # Ensure that the filename matching does not treat special
+       # characters as shell commands.
+
+       create_file_lines 'work/patches/patch-aa' \
+               '+++ [[[[(`" 2020-05-04'
+       create_file_lines 'work/+++ [[[[(`"' \
+               '#! /bin/sh' \
+               'test a = b'
+
+       check_portability_sh
+
+       assert_that 'out' --file-is-empty
+       assert_that $exitcode --equals 0
+
+       test_case_end
+fi



Home | Main Index | Thread Index | Old Index