Skip to content

Preserve native extensions during implicit clean - #9800

Merged
hsbt merged 1 commit into
ruby:masterfrom
sjh9714:codex/20260824-9795-preserve-native-extensions
Aug 24, 2026
Merged

Preserve native extensions during implicit clean#9800
hsbt merged 1 commit into
ruby:masterfrom
sjh9714:codex/20260824-9795-preserve-native-extensions

Conversation

@sjh9714

@sjh9714 sjh9714 commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

What was the end-user or developer problem that led to this PR?

Fixes #9795.

When a native gem is already activated from the system gem path, an implicit
clean after bundle install can use that system installation's extension path
for the project-local stub. It then treats the still-required extension under
BUNDLE_PATH as stale and removes it silently.

What is your fix for the problem, implemented in this PR?

Reload a stub's own gemspec when Gem::StubSpecification#to_spec returns an
activated specification from a different installation. This keeps the local
specification and extension paths together when implicit clean computes its
stale directories.

The regression test activates the system copy of a native gem, installs the
same version into BUNDLE_PATH, and changes an unrelated locked gem while
BUNDLE_CLEAN=true. It verifies that cleanup removes the obsolete gem but
preserves the required local native extension.

Make sure the following tasks are checked

Testing

  • bin/rspec spec/commands/install_spec.rb:2065
  • bin/rspec spec/bundler/stub_specification_spec.rb spec/commands/install_spec.rb
  • bin/rake rubocop
  • PATH="/tmp/oss-rspec-bin:$PATH" bin/rake spec:all (3 existing non-TTY color expectation failures; the same examples fail on the recorded upstream commit)

@hsbt hsbt left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

👍

@hsbt
hsbt enabled auto-merge August 24, 2026 02:25
@hsbt
hsbt merged commit 73e8b7e into ruby:master Aug 24, 2026
121 of 123 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Native extensions removed when using BUNDLE_CLEAN=true and removal happens (works fine for bundle clean)

2 participants