Skip to content

autoconf_hdr: Rewrite template directives as config.status does - #279

Merged
abrisco merged 3 commits into
periareon:mainfrom
sallustfire:fix/hdr-define-rewrite
Nov 22, 2026
Merged

abrisco merged 3 commits into
periareon:mainfrom
sallustfire:fix/hdr-define-rewrite

Conversation

@sallustfire

Copy link
Copy Markdown
Contributor

Thanks again for taking a few PRs. I've got another failure against my jemalloc fidelity oracle.

autoconf_hdr only rewrites #undef NAME lines, but config.status rewrites both #define NAME and #undef NAME whenever configure defines NAME. Templates that ship a default as a #define line render differently from configure's output. jemalloc 5.4.0 is one:

#undef JEMALLOC_INFALLIBLE_NEW
#ifndef JEMALLOC_INFALLIBLE_NEW
#  define JEMALLOC_INFALLIBLE_NEW 0
#endif

configure turns the fallback into # define JEMALLOC_INFALLIBLE_NEW 1, while we left 0. TeX Live's WEB2CVERSION line in the integration overlay works around the same gap. I believe this makes @texlive//texk/web2c:c_auto_in_substituted unnecessary.

The #undef matcher also diverges:

  • It skipped #undef NAME /* comment */, leaving a macro undefined even though the checks define it.
  • It matched an #undef in the middle of a line, e.g. inside a comment.

The first commit adds the tests. They mostly use GNU autoconf itself as the oracle, with goldens only where GNU has no equivalent (inlines, subst and all modes). It also tightens the conformance tester to compare raw lines plus the final newline, since splitlines() hid both. The second commit adds one line-anchored matcher that mirrors config.status's rule for both directives.

Notes:

  • Config headers now always end with a newline, as config.status's do.
  • Output is written in binary mode, so it ends in LF on every platform.
  • Templates are still read in text mode, so CRLF checkouts on Windows keep working. Waiting to see this verified on the Windows CI. If the CRLF edge test fails there, it can be excluded on Windows.
  • Known divergence left alone: trailing whitespace on lines we don't rewrite is still stripped, while GNU keeps it.

config.status rewrites both `#define NAME` and `#undef NAME` lines that
start a line, when configure defines NAME, and ends every line of a
header with a newline. autoconf_hdr rewrites only `#undef` lines, skips
one followed by a comment, matches one in the middle of a line, and
keeps a template's missing final newline.

Compare against GNU autoconf for these, and against goldens for inlined
content and the subst and all modes. The conformance tester compared
`splitlines()`, which hides carriage returns and the final newline;
compare the raw lines and whether the file ends with a newline instead.

A directive line a substitution writes should be kept, even over a
result. The generator test's helper passed temporaries to
SourceGenerator, which keeps references to them; name them instead.
Match `#define` and `#undef` lines the way config.status does: at the
start of a line, with the name followed by a blank, `(` or the end of
the line. A directive for a name with a definition becomes that
definition, keeping the whitespace around the `#`. Otherwise an `#undef`
is commented out and a `#define` is kept.

A directive line a substitution writes is kept as written. config.status
has no substitutions, and overlays use them to pin a define over a
result (`#undef NL_LANGINFO_MTSAFE` to `#define NL_LANGINFO_MTSAFE 1` in
wget, wget2, grep and grub on macOS), as the converter's `define:`
decisions do.

End every line of a config header with a newline, and write headers in
binary mode so they end in LF on every platform. Templates are still
read in text mode, so a CRLF checkout on Windows keeps working.

@abrisco abrisco left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@abrisco
abrisco enabled auto-merge (squash) November 22, 2026 20:34
@abrisco
abrisco merged commit 997a744 into periareon:main Nov 22, 2026
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants