Repository navigation
Fix out-of-tree configure writing to read-only source tree - #24597
Open
prateekbhujel wants to merge 1 commit into
Open
prateekbhujel wants to merge 1 commit into
prateekbhujel wants to merge 1 commit into
Conversation
This comment was marked as spam.
This comment was marked as spam.
PHP_PATCH_CONFIG_HEADERS previously wrote its temporary file and patched configuration header template directly into $srcdir. During out-of-tree builds with a read-only source tree, redirecting to $srcdir/$1.tmp failed with a filesystem error that was ignored, leaving configure to exit with status 0 while config.status consumed the unpatched template. Ensure the target directory exists in the build tree, generate the patched header template in the build directory (which Autoconf's config.status checks before falling back to $srcdir), and fail with AC_MSG_ERROR if patching the template fails. Reported by Mukonda Kangwa on the PHP internals mailing list: https://externals.io/message/132904
prateekbhujel
force-pushed
the
fix/configure-readonly-srcdir
branch
from
October 23, 2026 11:17
4d52a71 to
c894ed4
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
As reported by Mukonda Kangwa on the PHP internals mailing list (https://externals.io/message/132904), running
configureout-of-tree against a read-only source tree attempts to writemain/php_config.h.in.tmpinto$srcdir, fails with a filesystem error, and still exits with status0.Specifically,
PHP_PATCH_CONFIG_HEADERSinbuild/php.m4previously executed:$SED -e 's/^#undef PACKAGE_[^ ]*/\/\* & \*\//g' < $srcdir/$1 \ > $srcdir/$1.tmp && mv $srcdir/$1.tmp $srcdir/$1This causes three problems during out-of-tree builds:
$srcdirby writing$srcdir/$1.tmpand overwriting$srcdir/$1.$srcdiris read-only, the redirection fails (Read-only file system/Permission denied), and becauseconfiguredoes not check the exit status of the pipeline,configurecontinues and exits0.$srcdir/main/php_config.h.infails on a fresh source tree or release tarball,config.statusfalls back to the unpatched$srcdir/main/php_config.h.inand emits#define PACKAGE_*macros intomain/php_config.h, defeating the purpose ofPHP_PATCH_CONFIG_HEADERS.Fix
Autoconf's
config.statusresolvesAC_CONFIG_HEADERSinput templates in the build tree first (test -f "$ac_f") before falling back to$srcdir/$ac_f.This change updates
PHP_PATCH_CONFIG_HEADERSinbuild/php.m4to:AS_MKDIR_P(["$(AS_DIRNAME(["$1"]))"])before writing, sinceAC_CONFIG_COMMANDS_PREhooks cannot assume the target subdirectory already exists."$srcdir/$1"and write"$1.tmp"->"$1"in the current build directory, leaving$srcdiruntouched during out-of-tree builds while preserving in-place behavior for in-tree builds ($srcdir = .).AC_MSG_ERROR([failed to patch $1])if generating or moving the patched header template fails.Verification
configureand./config.statusexecution.configurewith a read-only source tree (chmod -R a-was an unprivileged user):$srcdirremains unmodified,main/php_config.h.inandmain/php_config.hare generated in the build tree with/* #undef PACKAGE_* */, and rerunning./config.statuspreserves the patched output.configure: error: failed to patch ...with exit status1) when template generation fails.--disable-all --enable-cli --disable-cgi --disable-phpdbg --without-pear) andphpizeextension configuration (both in-tree and out-of-tree with a read-only extension source directory).