Received: by mail.netbsd.org (Postfix, from userid 605) id CF4D284D45; Mon, 18 May 2020 06:06:35 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by mail.netbsd.org (Postfix) with ESMTP id 561EC84D36 for ; Mon, 18 May 2020 06:06:35 +0000 (UTC) X-Virus-Scanned: amavisd-new at netbsd.org Received: from mail.netbsd.org ([127.0.0.1]) by localhost (mail.netbsd.org [127.0.0.1]) (amavisd-new, port 10025) with ESMTP id U8nacSO0R6ri for ; Mon, 18 May 2020 06:06:34 +0000 (UTC) Received: from cvs.NetBSD.org (ivanova.netbsd.org [199.233.217.197]) by mail.netbsd.org (Postfix) with ESMTP id 819F584CE7 for ; Mon, 18 May 2020 06:06:34 +0000 (UTC) Received: by cvs.NetBSD.org (Postfix, from userid 500) id 75126FB27; Mon, 18 May 2020 06:06:34 +0000 (UTC) Content-Transfer-Encoding: 7bit Content-Type: multipart/mixed; boundary="_----------=_1589781994253330" MIME-Version: 1.0 Date: Mon, 18 May 2020 06:06:34 +0000 From: "Roland Illig" Subject: CVS commit: pkgsrc To: pkgsrc-changes@NetBSD.org Reply-To: rillig@netbsd.org X-Mailer: log_accum Message-Id: <20200518060634.75126FB27@cvs.NetBSD.org> Sender: pkgsrc-changes-owner@NetBSD.org List-Id: pkgsrc-changes.NetBSD.org Precedence: bulk List-Unsubscribe: This is a multi-part message in MIME format. --_----------=_1589781994253330 Content-Disposition: inline Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII" Module Name: pkgsrc Committed By: rillig Date: Mon May 18 06:06:34 UTC 2020 Modified Files: pkgsrc/mk/configure: replace-interpreter.mk Added Files: pkgsrc/regress/infra-unittests: replace-interpreter.sh Log Message: mk/configure/replace-interpreter.mk: silently skip broken symlinks Like directories, they probably come from shell globs. Seen in misc/byobu. To generate a diff of this commit: cvs rdiff -u -r1.19 -r1.20 pkgsrc/mk/configure/replace-interpreter.mk cvs rdiff -u -r0 -r1.1 pkgsrc/regress/infra-unittests/replace-interpreter.sh Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. --_----------=_1589781994253330 Content-Disposition: inline Content-Length: 5057 Content-Transfer-Encoding: binary Content-Type: text/x-diff; charset=us-ascii Modified files: Index: pkgsrc/mk/configure/replace-interpreter.mk diff -u pkgsrc/mk/configure/replace-interpreter.mk:1.19 pkgsrc/mk/configure/replace-interpreter.mk:1.20 --- pkgsrc/mk/configure/replace-interpreter.mk:1.19 Tue Mar 24 04:40:34 2020 +++ pkgsrc/mk/configure/replace-interpreter.mk Mon May 18 06:06:34 2020 @@ -1,4 +1,4 @@ -# $NetBSD: replace-interpreter.mk,v 1.19 2020/03/24 04:40:34 rillig Exp $ +# $NetBSD: replace-interpreter.mk,v 1.20 2020/05/18 06:06:34 rillig Exp $ # This file provides common templates for replacing #! interpreters # in script files. @@ -31,7 +31,7 @@ # variable, all identifiers starting with "sys-" are reserved for the # pkgsrc infrastructure. All others may be used freely. # -# Keywords: replace_interpreter interpreter interp hashbang #! +# Keywords: replace_interpreter interpreter interp hashbang #! shebang # Keywords: awk bash csh ksh perl sh ###################################################################### @@ -111,7 +111,7 @@ replace-interpreter: ${RUN} set -u; \ cd ${WRKSRC}; \ for f in ${REPLACE_FILES.${_lang_}}; do \ - if [ -f "$${f}" ]; then \ + if [ -f "$$f" ]; then \ ${SED} -e '1s|^#![[:space:]]*${REPLACE.optional-env-space}${REPLACE.${_lang_}.old}|#!${REPLACE.${_lang_}.new}|' \ < "$${f}" > "$${f}.new"; \ if [ -x "$${f}" ]; then \ @@ -123,8 +123,8 @@ replace-interpreter: else \ ${MV} -f "$${f}.new" "$${f}"; \ fi; \ - elif [ -d "$$f" ]; then \ - ${SHCOMMENT} "Ignore it, most probably comes from shell globs"; \ + elif [ -d "$$f" ] || [ -h "$$f" ]; then \ + : 'Ignore it, most probably comes from shell globs'; \ else \ ${WARNING_MSG} "[replace-interpreter] Skipping non-existent file \"$$f\"."; \ fi; \ Added files: Index: pkgsrc/regress/infra-unittests/replace-interpreter.sh diff -u /dev/null pkgsrc/regress/infra-unittests/replace-interpreter.sh:1.1 --- /dev/null Mon May 18 06:06:34 2020 +++ pkgsrc/regress/infra-unittests/replace-interpreter.sh Mon May 18 06:06:34 2020 @@ -0,0 +1,119 @@ +#! /bin/sh +# $NetBSD: replace-interpreter.sh,v 1.1 2020/05/18 06:06:34 rillig Exp $ +# +# Tests for mk/configure/replace-interpreter.mk. +# + +set -eu + +. './test.subr' + +test_case_set_up() { + create_file 'setup.mk' <<-EOF + # The tools that are used by replace-interpreter.mk + CHMOD= chmod + CMP= cmp + MV= mv + SED= sed + RM= rm + + # Commands that are specific to pkgsrc + RUN= @set -e; + STEP_MSG= echo '=>' + INFO_MSG= echo 'info:' + WARNING_MSG= echo 'warning:' + + # Dummy interpreters + PERL5= $tmpdir/bin/perl5 + + WRKDIR= $tmpdir/wrkdir + WRKSRC= . + EOF +} + + +if test_case_begin 'regular file'; then + + create_file 'test.mk' <<-EOF + REPLACE_PERL+= perl-program + + .include "setup.mk" + .include "mk/configure/replace-interpreter.mk" + EOF + + create_file_lines 'perl-program' \ + '#! /any/path/perl' + + run_bmake 'test.mk' 'replace-interpreter' 1> "$tmpdir/output" 2>&1 \ + && exitcode=0 || exitcode=$? + + assert_that "$tmpdir/output" --file-is-lines \ + '=> Replacing Perl interpreter in perl-program.' + assert_that 'perl-program' --file-is-lines \ + "#!$tmpdir/bin/perl5" + + test_case_end +fi + + +if test_case_begin 'valid symlink'; then + + # Valid symlinks are followed, even though they might point + # anywhere, even outside WRKSRC. + # This has "forever" been the behavior. + # It may make sense to change this, but that requires testing + # to see whether any packages rely on this behavior. + + # Ouch, this replaces the symlink with a regular file, + # which is probably unexpected to the upstream author. + + create_file 'test.mk' <<-EOF + REPLACE_PERL+= perl-symlink + + .include "setup.mk" + .include "mk/configure/replace-interpreter.mk" + EOF + create_file_lines 'perl-program' \ + '#! /any/path/perl' + ln -s 'perl-program' 'perl-symlink' + + run_bmake 'test.mk' 'replace-interpreter' 1> "$tmpdir/output" 2>&1 \ + && exitcode=0 || exitcode=$? + + assert_that "$tmpdir/output" --file-is-lines \ + '=> Replacing Perl interpreter in perl-symlink.' + # This should most probably still be a symlink. + [ -f 'perl-symlink' ] || assert_fail 'still a symlink\n' + # This file should be left unmodified since it is not mentioned + # in REPLACE_PERL. + assert_that 'perl-program' --file-is-lines \ + "#! /any/path/perl" + assert_that 'perl-symlink' --file-is-lines \ + "#!$tmpdir/bin/perl5" + + test_case_end +fi + + +if test_case_begin 'broken symlink'; then + + # Broken symlinks are skipped silently, just like directories. + + create_file 'test.mk' <<-EOF + REPLACE_PERL+= perl-symlink + + .include "setup.mk" + .include "mk/configure/replace-interpreter.mk" + EOF + + ln -s 'does-not-exist' 'perl-symlink' + + run_bmake 'test.mk' 'replace-interpreter' 1> "$tmpdir/output" 2>&1 \ + && exitcode=0 || exitcode=$? + + assert_that "$tmpdir/output" --file-is-lines \ + '=> Replacing Perl interpreter in perl-symlink.' + [ -h 'perl-symlink' ] || assert_fail 'not a symlink anymore' + + test_case_end +fi --_----------=_1589781994253330--