Re: [PATCH] AS_INIT: don't encode full path

Luke Mewburn <[email protected]>
Newsgroups gmane.comp.sysutils.autoconf.patches
Message-ID <[email protected]>
On 20-07-04 13:00, Zack Weinberg wrote:
  | On Fri, Jul 3, 2020 at 8:42 PM Luke Mewburn <[email protected]> wrote:
  | >
  | > Fix AS_INIT to use the basename of __file__ instead of the full path.
  | > Allows for reproducible builds.
  | 
  | I like the idea here, but I think the patch isn't quite ready yet.
  | Most importantly, please write a test for the testsuite to ensure that
  | this doesn't get broken accidentally in the future.  Second, there
  | should be a comment in m4sh.m4 explaining that we are taking the
  | basename of __file__ so that the path to the source directory is not
  | embedded in the output file.  Third, a small tweak for your regular
  | expression: it should be "^.*/\([^/]*\)$" instead of "^.*/\(.*)".  The
  | latter relies too much on the particular greediness behavior of M4's
  | regexp implementation.

Hi Zack,

I've updated the patch to address your comments:
1) Added a testsuite.
2) Added the comment.
3) Improved the regex. (Thanks for the heads up about M4 greedy regex.)

I've attached the revised patch.

Hopefully this still trivial enough to not need a copyright assignment,
since I cribbed most of the new tests from elsewhere in m4sh.at and local.at.
If an assignment is required let me know; happy to provide it.

regards,
Luke.
0001-AS_INIT-basename-__file__.patch (text/plain, 1.9 KB)
From 918f141758cbfab1f8f3cf0d67d420f070e34a4d Mon Sep 17 00:00:00 2001
From: Luke Mewburn <[email protected]>
Date: Sun, 5 Jul 2020 12:58:46 +1000
Subject: [PATCH] AS_INIT: basename __file__

Fix AS_INIT to encode the basename of __file__
instead of the full path to the source directory.
Allows for reproducible builds.
---
 lib/m4sugar/m4sh.m4 |    4 +++-
 tests/m4sh.at       |   19 +++++++++++++++++++
 2 files changed, 22 insertions(+), 1 deletions(-)

diff --git a/lib/m4sugar/m4sh.m4 b/lib/m4sugar/m4sh.m4
index af28685..7ef43f6 100644
--- a/lib/m4sugar/m4sh.m4
+++ b/lib/m4sugar/m4sh.m4
@@ -2139,9 +2139,11 @@ m4_provide([AS_INIT])
 m4_pattern_forbid([^_?AS_])
 
 # Bangshe and minimal initialization.
+# Ensure HEADER-COMMENT contains the basename of __file__ so that the
+# path to the source directory is not embedded in the output file.
 m4_divert_text([BINSH], [@%:@! /bin/sh])
 m4_divert_text([HEADER-COMMENT],
-	       [@%:@ Generated from __file__ by m4_PACKAGE_STRING.])
+	       [@%:@ Generated from m4_bpatsubst(__file__,[^.*/\([^/]*\)$],[[\1]]) by m4_PACKAGE_STRING.])
 m4_divert_text([M4SH-SANITIZE], [_AS_SHELL_SANITIZE])
 m4_divert_text([M4SH-INIT-FN], [m4_text_box([M4sh Shell Functions.])])
 
diff --git a/tests/m4sh.at b/tests/m4sh.at
index 9fd8455..a18277a 100644
--- a/tests/m4sh.at
+++ b/tests/m4sh.at
@@ -1868,6 +1868,25 @@ cleanup 1
 AT_CLEANUP
 
 
+## -------------------------- ##
+## AS_INIT basename __file__. ##
+## -------------------------- ##
+
+AT_SETUP([AS@&t@_INIT basename __@&t@file__])
+AT_KEYWORDS([m4sh])
+
+AT_CHECK([mkdir sub || exit 77])
+AT_DATA_M4SH([sub/script.as], [[dnl
+AS_INIT
+]])
+AT_CHECK_AUTOM4TE([--language=m4sh sub/script.as -o script])
+AT_CHECK([grep '^# Generated from' script], [0], [dnl
+# Generated from script.as by ]m4_PACKAGE_STRING[.
+])
+
+AT_CLEANUP
+
+
 ## ------------------- ##
 ## AS_INIT_GENERATED.  ##
 ## ------------------- ##
-- 
1.7.1
signature.asc (application/pgp-signature, 198 B)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.14 (GNU/Linux)

iEYEARECAAYFAl8BU3IACgkQpBhtmn8zJHIQLgCgo+qHYB4KWDh8eGIt3b9A+wmr
O+IAoMpp/2+AS9e6fUFEN61sITFVts/k
=gPEp
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.