Repository navigation
Fix gem build failure hiding its cause (#2117) - #2128
Mikola Lysenko (mikolalysenko) merged 4 commits into
Conversation
Refs #2117. Assisted-by: Claude Code:claude-fable-5-2 Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011f9aeP49dwo2SCWb55mzyj
Two unit tests for the build-output filter and one end-to-end test with the stand-in Ruby, which now can fail a build the way a gem's extconf.rb does when a library is missing. All three fail on main: the error ends in mkmf's list of configuration options, points at an mkmf.log in the removed stage, names a compiler as the remedy and is printed twice. Refs #2117. Assisted-by: Claude Code:claude-fable-5-2 Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011f9aeP49dwo2SCWb55mzyj
When agent apply rebuilds a gem's native extension and the build fails, the error carried the last 20 lines of the build's stderr. For a failed extconf.rb those are mkmf's list of configuration options, so the lines naming the cause (a missing libpq-fe.h for a precompiled pg) were cut off. The tail also pointed at an mkmf.log in the stage, which is removed before the error is printed. The diagnostic now drops mkmf's option list and its mkmf.log pointer before taking the tail, which grows to 30 lines. The remedy of a precompiled gem says that the rebuild needs what `gem install <name> --platform ruby` needs, and the in-place one no longer assumes the compiler is what is missing. On the human path a failed gem refusal was printed twice, as the package's Error line and as a Warning with the same text. The warning is now kept for the JSON envelope only. A failed in-place build also no longer advises that `bundle install --redownload` reverts a patch it did not leave applied. Fixes #2117. Refs #2106. Assisted-by: Claude Code:claude-fable-5-2 Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011f9aeP49dwo2SCWb55mzyj
From the review of this branch: - The remedy of a precompiled gem's failed rebuild names the source gem by its name and version instead of a name derived from the installed directory. - Both remedies no longer promise build output that names what is missing: a build that timed out or could not start has none. - A failed in-place build keeps the `bundle install --redownload` advisory when an earlier run left a file of the record patched, which this run does not put back. - CLI_CONTRACT.md says for every native-extension refusal that it is printed once on the human path. Refs #2117. Assisted-by: Claude Code:claude-fable-5-2 Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011f9aeP49dwo2SCWb55mzyj
|
bugbot run Generated by Claude Code |
PR SummaryMedium Risk Overview
On the human CLI path, Reviewed by Cursor Bugbot for commit f545e89. Configure here. |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit f545e89. Configure here.
LLM Description written by Claude Code:claude-fable-5-2
Fixes #2117
Refs #2106 (only the remedy wording of a failed in-place build changes; argon2 still cannot be rebuilt in place, see Follow-ups)
Summary
When agent
applyrebuilds a gem's native extension and the build fails, the error now shows why. Nothing about when a build runs or what it writes changes: this PR only changes the text of a failure that already left the installed gem untouched.Before, for a precompiled
pg 1.6.2on a machine withoutlibpq-dev: 17 lines of mkmf configuration options, a pointer to anmkmf.logthat had been deleted, "Install a compiler toolchain and the Ruby headers", all printed twice.After (same machine, same record):
Root cause
stderr_tail(crates/socket-patch-core/src/patch/gem_ext.rs) kept the last 20 non-empty lines of the build's stderr. RubyGems ends the output of a failedextconf.rbwith mkmf's "Provided configuration options" list (27 lines for pg) and a pointer to the build'smkmf.log, so the tail was that list, and the lines naming the cause were cut off. The log is in the stage directory, which is removed before the error is printed. The two callers put a fixed "Install a compiler toolchain and the Ruby headers" in front of that tail. The CLI then printed a failed gem refusal as the package'sError:line and again as aWarning:with the same text, because the refusal is also carried as a coded warning for the JSON envelope.What changed
stderr_taildrops mkmf's option list (the heading and the tab-indented lines under it) and RubyGems'mkmf.logpointer with its path line, then takes the last 30 lines instead of 20. Tab-indented lines elsewhere (a Ruby backtrace,makeoutput) are kept.applyon the human path no longer prints aWarning:that repeats a failed package'sError:line (restates_a_failureincommands/apply.rs). This holds for both refusal codes,native_extension_build_failedandnative_extensions_unsupported.--jsonoutput is unchanged: the package's error and thewarnings[]entry are both still there.bundle install --redownloadwill revert these patches" for a gem it put back unpatched. It still does when an earlier run left a file of the record patched.docs/ecosystems.mdsays that a precompiled gem's rebuild is the first time the gem's own build libraries are needed.CLI_CONTRACT.mddescribes the tail and the single print.Evidence
pg 1.6.2, Ruby 3.3.6, Bundler 4.0.18, nolibpq-dev) onorigin/main89c482dmkmf.logpath, printed twicevendor/has the same sha256 as before the runcargo test -p socket-patch-core --libgem_exttests rerun after it: 62 passed)cargo test -p socket-patch-cli --libe2e_gem_native_ext_build -- --include-ignored(real Ruby 3.3.6 and gcc)in_process_gem_apply,in_process_gem_multi_platform,e2e_redirect_gem_build,e2e_vendor_gem_build,e2e_redirect_gem_stale_install, all with--include-ignoredcargo clippy --locked --workspace --all-features -- -D warnings(CI's command)Tests for #2117, all red on
origin/main(the first commit adds them alone):gem_ext::tests::stderr_tail_keeps_the_cause_of_a_failed_extconfandstderr_tail_keeps_indented_lines_outside_the_option_list: the filter.e2e_gem_native_ext_build::a_failed_extconf_shows_its_cause_once: the stand-in Ruby fails a build the way a missing library does, for a precompiled gem and for a source-built one. It asserts the cause is shown, the option list and the log pointer are not, the remedy text, one print and noWarning:on the human path, the codedwarnings[]entry under--json, and an unchangedvendor/tree.e2e_gem_native_ext_build::a_failed_build_keeps_the_advisory_of_a_file_patched_beforeandapply::tests::only_the_coded_copy_of_a_failed_result_restates_it: the two edges the review raised.Review
/code-review highran on the diff and gave five findings. Three are fixed in the last commit (the gem's name and version taken from the source gem id, remedy wording that held only when there was build output, the advisory dropped when an earlier run left a file patched). Two are not:mkmf.loginstead of dropping the pointer. Not done here. The issue allows either, and reading a file whose path the gem's build printed into an error message is a design choice a maintainer should make. mkmf's own "Check the mkmf.log file for more details" line stays in the output, so a failure whose only detail is in that log (a link error during ahave_librarycheck) still does not show it. Listed under Follow-ups.RunWarningor a second list throughApplyOutcome, for the same behavior. If the two strings ever drift apart, the e2e test above fails.Follow-ups
applycan never rebuild argon2, the gem the docs name as rebuilt from its installed tree: its one-shotextconf.rbfails onMakefile.real, and the remedy says to install a compiler #2106: argon2's one-shotextconf.rbstill fails an in-place rebuild. The message now ends with "otherwise usesocket-patch scan --mode hosted" instead of telling the user to install a compiler, and that is all this PR does for it.mkmf.log(above).cargo clippy -p socket-patch-core --all-targets --all-features -- -D warningsfails onorigin/mainwith 44 errors in test code this PR does not touch (jvm_jar.rs,maven_reactor.rs,bun_binary.rsand others), and the CLI crate with errors intests/prebuilt_common/mod.rs. CI's clippy job does not pass--all-targets. None of the errors is in a file this PR changes.https://claude.ai/code/session_011f9aeP49dwo2SCWb55mzyj
Generated by Claude Code