'USES=shebangfix' doesn't work with samba ports

From: Yasuhiro Kimura <yasu_at_FreeBSD.org>
Date: Wed, 01 Nov 2023 10:48:31 UTC
Hello,

In following bug report some patches are submitted that update samba
and its dependent ports to newer version.

Bug 270383 net/samba417: Add new port
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=270383

While testing them I noticed 'USES=shebangfix' doesn't work as is
expected with current samba ports.

For example there is following definition at line 100 and 101 of
net/samba416/Makefile.

----------------------------------------------------------------------
USES=                           compiler:c++11-lang iconv localbase:ldflags \
                                perl5 pkgconfig shebangfix waf gettext-runtime
----------------------------------------------------------------------

And SHEBANG_FILES is defined as following at line 559.

----------------------------------------------------------------------
SHEBANG_FILES=                  ${PATCH_WRKSRC}/source4/scripting/bin/* ${PATCH_WRKSRC}/selftest/*
----------------------------------------------------------------------

Since the value of PATCH_WRKSRC is same as that of WRKSRC by default,
shebang line of files under ${WRKSRC}/source4/scripting/bin/ and
${WRKSRC}/selftest/ should be fixed properly.

And source4/scripting/bin/gen_error_common.py is one of such files.

----------------------------------------------------------------------
yasu@rolling-vm-freebsd2[1251]% pwd
/usr/ports/net/samba416
yasu@rolling-vm-freebsd2[1252]% make extract
===>  Cleaning for samba416-4.16.11
===>  License GPLv3+ accepted by the user
===>   samba416-4.16.11 depends on file: /usr/local/sbin/pkg - found
===> Fetching all distfiles required by samba416-4.16.11 for building
===>  Extracting for samba416-4.16.11
=> SHA256 Checksum OK for samba-4.16.11.tar.gz.
yasu@rolling-vm-freebsd2[1253]% head -1 work/samba-4.16.11/source4/scripting/bin/gen_error_common.py
#!/usr/bin/env python3
----------------------------------------------------------------------

But it stays unchanged with `make patch`.

----------------------------------------------------------------------
yasu@rolling-vm-freebsd2[1263]% pwd
/usr/ports/net/samba416
yasu@rolling-vm-freebsd2[1264]% make extract
===>  License GPLv3+ accepted by the user
===>   samba416-4.16.11 depends on file: /usr/local/sbin/pkg - found
===> Fetching all distfiles required by samba416-4.16.11 for building
===>  Extracting for samba416-4.16.11
=> SHA256 Checksum OK for samba-4.16.11.tar.gz.
yasu@rolling-vm-freebsd2[1265]% head -1 work/samba-4.16.11/source4/scripting/bin/gen_error_common.py
#!/usr/bin/env python3
yasu@rolling-vm-freebsd2[1266]% make patch
===>  Patching for samba416-4.16.11
===>  Applying extra patch /usr/ports/net/samba416/files/0001-Compact-and-simplify-modules-build-and-config-genera.patch with -p1
===>  Applying extra patch /usr/ports/net/samba416/files/0002-Adjust-abi_gen.sh-script-to-run-under-FreeBSD-with-i.patch with -p1
===>  Applying extra patch /usr/ports/net/samba416/files/0003-Mask-CLang-prototype-warnings-in-kadm5-admin.h.patch with -p1
===>  Applying extra patch /usr/ports/net/samba416/files/0004-On-FreeBSD-date-1-has-different-semantics-than-on-Li.patch with -p1
===>  Applying extra patch /usr/ports/net/samba416/files/0005-Include-jemalloc-jemalloc.h-if-ENABLE_JEMALLOC-is-se.patch with -p1
===>  Applying extra patch /usr/ports/net/samba416/files/0006-Install-nss_-modules-into-PAMMODULESDIR-path.patch with -p1
===>  Applying extra patch /usr/ports/net/samba416/files/0007-Use-macro-value-as-a-default-backlog-size-for-the-li.patch with -p1
===>  Applying extra patch /usr/ports/net/samba416/files/0008-Brute-force-work-around-usage-of-Linux-specific-m-fl.patch with -p1
===>  Applying extra patch /usr/ports/net/samba416/files/0009-Make-sure-that-config-checks-fail-if-the-warning-is-.patch with -p1
===>  Applying extra patch /usr/ports/net/samba416/files/0010-Add-option-with-pkgconfigdir-to-specify-alternative-.patch with -p1
===>  Applying extra patch /usr/ports/net/samba416/files/0011-Use-provided-by-port-location-of-the-XML-catalog.patch with -p1
===>  Applying extra patch /usr/ports/net/samba416/files/0012-Create-shared-libraries-according-to-the-FreeBSD-spe.patch with -p1
===>  Applying extra patch /usr/ports/net/samba416/files/0013-Pass-additional-msg-parameter-to-CHECK_LIB-so-it-can.patch with -p1
===>  Applying extra patch /usr/ports/net/samba416/files/0014-Add-option-to-disable-CTDB-tests-failing-on-FreeBSD-.patch with -p1
===>  Applying extra patch /usr/ports/net/samba416/files/0015-Add-extra-debug-class-to-trck-down-DB-locking-code.patch with -p1
===>  Applying extra patch /usr/ports/net/samba416/files/0016-Make-ldb_schema_attribute_compare-a-stable-comparisi.patch with -p1
===>  Applying extra patch /usr/ports/net/samba416/files/0017-Use-arc4random-when-available-to-generate-random-tal.patch with -p1
===>  Applying extra patch /usr/ports/net/samba416/files/0018-Add-configuration-option-that-allows-to-choose-alter.patch with -p1
===>  Applying extra patch /usr/ports/net/samba416/files/0019-From-923bc7a1afeb0b920e60e14846987ae1d2d7dca4-Mon-Se.patch with -p1
===>  Applying extra patch /usr/ports/net/samba416/files/0020-FreeBSD-12-between-r336017-and-r342928-wrongfuly-ret.patch with -p1
===>  Applying extra patch /usr/ports/net/samba416/files/0021-Fix-casting-warnings-in-the-nfs_quota-debug-message.patch with -p1
===>  Applying extra patch /usr/ports/net/samba416/files/0022-Clean-up-UTMP-handling-code-and-add-FreeBSD-support..patch with -p1
===>  Applying extra patch /usr/ports/net/samba416/files/0023-Add-cmd_get_quota-test-function-into-vfstest-to-test.patch with -p1
===>  Applying extra patch /usr/ports/net/samba416/files/0024-Cherry-pick-ZFS-provisioning-code-by-iXsystems-Inc.patch with -p1
===>  Applying extra patch /usr/ports/net/samba416/files/0025-From-d9b748869a8f4018ebee302aae8246bf29f60309-Mon-Se.patch with -p1
===>  Applying extra patch /usr/ports/net/samba416/files/0026-vfs-add-a-compatibility-option-to-the-vfs_streams_xa.patch with -p1
===>  Applying extra patch /usr/ports/net/samba416/files/0027-Add-VFS-module-vfs_freebsd-that-implements-FreeBSD-s.patch with -p1
===>  Applying extra patch /usr/ports/net/samba416/files/0028-s3-lib-system-add-FreeBSD-proc_fd_pattern.patch with -p1
===>  Applying extra patch /usr/ports/net/samba416/files/0099-s3-modules-zfsacl-fix-get-set-ACL-on-FreeBSD-13.patch with -p1
===>  Applying extra patch /usr/ports/net/samba416/files/0099-s4-mitkdc-Add-support-for-MIT-Kerberos-1.20.patch with -p1
===>  Applying FreeBSD patches for samba416-4.16.11 from /usr/ports/net/samba416/files
yasu@rolling-vm-freebsd2[1067]% head -1 work/samba-4.16.11/source4/scripting/bin/gen_error_common.py
#!/usr/bin/env python3
----------------------------------------------------------------------

And it isn't the only one.

To investigate it I add some debug messages to fix-shebang target
defined in Mk/Uses/shebangfix.mk.

----------------------------------------------------------------------
yasu@rolling-vm-freebsd2[1269]% git diff
diff --git a/Mk/Uses/shebangfix.mk b/Mk/Uses/shebangfix.mk
index 20dba5279964..6a427b6a4262 100644
--- a/Mk/Uses/shebangfix.mk
+++ b/Mk/Uses/shebangfix.mk
@@ -85,6 +85,7 @@ _SHEBANG_REINPLACE_ARGS+=     -e "1s|^\#![[:space:]]*${old_cmd:C/\"//g}$$|\#!${${lan
 
 _USES_patch+=  210:fix-shebang
 fix-shebang:
+       @${ECHO_CMD} target fix-shebang start
 .  if defined(SHEBANG_REGEX)
        @cd ${WRKSRC}; \
                ${FIND} -E . -type f -iregex '${SHEBANG_REGEX}' \
@@ -97,10 +98,13 @@ fix-shebang:
                -exec ${SED} -i '' ${_SHEBANG_REINPLACE_ARGS} {} +
 .    endfor
 .  endif
+       @${ECHO_CMD} "SHEBANG_FILES=\"${SHEBANG_FILES}\""
 .  if defined(SHEBANG_FILES)
+       @${ECHO_CMD} fixing SHEBANG_FILES
        @cd ${WRKSRC}; \
                ${FIND} ${SHEBANG_FILES} -type f \
                -exec ${SED} -i '' ${_SHEBANG_REINPLACE_ARGS} {} +
 .  endif
+       @${ECHO_CMD} target fix-shebang end
 
 .endif
----------------------------------------------------------------------

With it `make -C /usr/ports/ftp/curl patch` works as following.

----------------------------------------------------------------------
yasu@rolling-vm-freebsd2[1271]% make -C /usr/ports/ftp/curl patch
===>  License MIT accepted by the user
===>   curl-8.4.0 depends on file: /usr/local/sbin/pkg - found
===> Fetching all distfiles required by curl-8.4.0 for building
===>  Extracting for curl-8.4.0
=> SHA256 Checksum OK for curl-8.4.0.tar.xz.
===>  Patching for curl-8.4.0
target fix-shebang start
SHEBANG_FILES="*/*.pl"
fixing SHEBANG_FILES
target fix-shebang end
===>  Applying FreeBSD patches for curl-8.4.0 from /usr/ports/ftp/curl/files
----------------------------------------------------------------------

All of 4 messages are displayed as is expected.

On the other hand `make -C /usr/ports/net/samba416 patch` works as
following.

----------------------------------------------------------------------
yasu@rolling-vm-freebsd2[1275]% make -C /usr/ports/net/samba416 patch
===>  License GPLv3+ accepted by the user
===>   samba416-4.16.11 depends on file: /usr/local/sbin/pkg - found
===> Fetching all distfiles required by samba416-4.16.11 for building
===>  Extracting for samba416-4.16.11
=> SHA256 Checksum OK for samba-4.16.11.tar.gz.
===>  Patching for samba416-4.16.11
target fix-shebang start
SHEBANG_FILES="/usr/ports/net/samba416/work/samba-4.16.11/source4/scripting/bin/* /usr/ports/net/samba416/work/samba-4.16.11/selftest/*"
target fix-shebang end
===>  Applying extra patch /usr/ports/net/samba416/files/0001-Compact-and-simplify-modules-build-and-config-genera.patch with -p1
===>  Applying extra patch /usr/ports/net/samba416/files/0002-Adjust-abi_gen.sh-script-to-run-under-FreeBSD-with-i.patch with -p1
===>  Applying extra patch /usr/ports/net/samba416/files/0003-Mask-CLang-prototype-warnings-in-kadm5-admin.h.patch with -p1
===>  Applying extra patch /usr/ports/net/samba416/files/0004-On-FreeBSD-date-1-has-different-semantics-than-on-Li.patch with -p1
===>  Applying extra patch /usr/ports/net/samba416/files/0005-Include-jemalloc-jemalloc.h-if-ENABLE_JEMALLOC-is-se.patch with -p1
===>  Applying extra patch /usr/ports/net/samba416/files/0006-Install-nss_-modules-into-PAMMODULESDIR-path.patch with -p1
===>  Applying extra patch /usr/ports/net/samba416/files/0007-Use-macro-value-as-a-default-backlog-size-for-the-li.patch with -p1
===>  Applying extra patch /usr/ports/net/samba416/files/0008-Brute-force-work-around-usage-of-Linux-specific-m-fl.patch with -p1
===>  Applying extra patch /usr/ports/net/samba416/files/0009-Make-sure-that-config-checks-fail-if-the-warning-is-.patch with -p1
===>  Applying extra patch /usr/ports/net/samba416/files/0010-Add-option-with-pkgconfigdir-to-specify-alternative-.patch with -p1
===>  Applying extra patch /usr/ports/net/samba416/files/0011-Use-provided-by-port-location-of-the-XML-catalog.patch with -p1
===>  Applying extra patch /usr/ports/net/samba416/files/0012-Create-shared-libraries-according-to-the-FreeBSD-spe.patch with -p1
===>  Applying extra patch /usr/ports/net/samba416/files/0013-Pass-additional-msg-parameter-to-CHECK_LIB-so-it-can.patch with -p1
===>  Applying extra patch /usr/ports/net/samba416/files/0014-Add-option-to-disable-CTDB-tests-failing-on-FreeBSD-.patch with -p1
===>  Applying extra patch /usr/ports/net/samba416/files/0015-Add-extra-debug-class-to-trck-down-DB-locking-code.patch with -p1
===>  Applying extra patch /usr/ports/net/samba416/files/0016-Make-ldb_schema_attribute_compare-a-stable-comparisi.patch with -p1
===>  Applying extra patch /usr/ports/net/samba416/files/0017-Use-arc4random-when-available-to-generate-random-tal.patch with -p1
===>  Applying extra patch /usr/ports/net/samba416/files/0018-Add-configuration-option-that-allows-to-choose-alter.patch with -p1
===>  Applying extra patch /usr/ports/net/samba416/files/0019-From-923bc7a1afeb0b920e60e14846987ae1d2d7dca4-Mon-Se.patch with -p1
===>  Applying extra patch /usr/ports/net/samba416/files/0020-FreeBSD-12-between-r336017-and-r342928-wrongfuly-ret.patch with -p1
===>  Applying extra patch /usr/ports/net/samba416/files/0021-Fix-casting-warnings-in-the-nfs_quota-debug-message.patch with -p1
===>  Applying extra patch /usr/ports/net/samba416/files/0022-Clean-up-UTMP-handling-code-and-add-FreeBSD-support..patch with -p1
===>  Applying extra patch /usr/ports/net/samba416/files/0023-Add-cmd_get_quota-test-function-into-vfstest-to-test.patch with -p1
===>  Applying extra patch /usr/ports/net/samba416/files/0024-Cherry-pick-ZFS-provisioning-code-by-iXsystems-Inc.patch with -p1
===>  Applying extra patch /usr/ports/net/samba416/files/0025-From-d9b748869a8f4018ebee302aae8246bf29f60309-Mon-Se.patch with -p1
===>  Applying extra patch /usr/ports/net/samba416/files/0026-vfs-add-a-compatibility-option-to-the-vfs_streams_xa.patch with -p1
===>  Applying extra patch /usr/ports/net/samba416/files/0027-Add-VFS-module-vfs_freebsd-that-implements-FreeBSD-s.patch with -p1
===>  Applying extra patch /usr/ports/net/samba416/files/0028-s3-lib-system-add-FreeBSD-proc_fd_pattern.patch with -p1
===>  Applying extra patch /usr/ports/net/samba416/files/0099-s3-modules-zfsacl-fix-get-set-ACL-on-FreeBSD-13.patch with -p1
===>  Applying extra patch /usr/ports/net/samba416/files/0099-s4-mitkdc-Add-support-for-MIT-Kerberos-1.20.patch with -p1
===>  Applying FreeBSD patches for samba416-4.16.11 from /usr/ports/net/samba416/files
----------------------------------------------------------------------

As you can see, 3rd message isn't displayed. It means SHEBANG_FILES
isn't defined. But it obviously conflicts with the output of 2nd
message.

Same issue also happens with net/samba413.

Can someone explain what is happening?

Regards.

---
Yasuhiro Kimura