Skip to content

Commit 4172caa

Browse files
hsbtclaude
andcommitted
Support no_build_extension and no_install_plugin settings in Bundler
Extend the --no-build-extension and --no-install-plugin support to Bundler's installation paths. RubyGemsGemInstaller#install now respects these options, and the settings are propagated from Bundler::Settings through Source::RubyGems to the installer. Path::Installer also respects no_build_extension for git/path sources. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 4a95bd2 commit 4172caa

5 files changed

Lines changed: 64 additions & 4 deletions

File tree

bundler/lib/bundler/rubygems_gem_installer.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,19 @@ def install
2727
extract_files
2828
end
2929

30-
build_extensions if spec.extensions.any?
30+
if options[:build_extension] == false
31+
warn_skipped_extensions
32+
elsif spec.extensions.any?
33+
build_extensions
34+
end
3135
write_build_info_file
3236
run_post_build_hooks
3337

3438
SharedHelpers.filesystem_access(bin_dir, :write) do
3539
generate_bin
3640
end
3741

38-
generate_plugins
42+
generate_plugins unless options[:install_plugin] == false
3943

4044
write_spec
4145

bundler/lib/bundler/settings.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ class Settings
3030
init_gems_rb
3131
inline
3232
lockfile_checksums
33+
no_build_extension
3334
no_install
35+
no_install_plugin
3436
no_prune
3537
path.system
3638
plugins

bundler/lib/bundler/source/path/installer.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def initialize(spec, options = {})
2424
def post_install
2525
run_hooks(:pre_install)
2626

27-
unless @disable_extensions
27+
unless @disable_extensions || Bundler.settings[:no_build_extension]
2828
build_extensions
2929
run_hooks(:post_build)
3030
end

bundler/lib/bundler/source/rubygems.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,9 @@ def rubygems_gem_installer(spec, options)
533533
wrappers: true,
534534
env_shebang: true,
535535
build_args: options[:build_args],
536-
bundler_extension_cache_path: extension_cache_path(spec)
536+
bundler_extension_cache_path: extension_cache_path(spec),
537+
build_extension: Bundler.settings[:no_build_extension] ? false : nil,
538+
install_plugin: Bundler.settings[:no_install_plugin] ? false : nil
537539
)
538540
@gem_installers_mutex.synchronize { @gem_installers[spec.name] ||= installer }
539541
end
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# frozen_string_literal: true
2+
3+
RSpec.describe "bundle install with --no-build-extension" do
4+
before do
5+
build_repo2 do
6+
build_gem "with_extension" do |s|
7+
s.extensions << "Rakefile"
8+
s.write "Rakefile", <<-RUBY
9+
task :default do
10+
path = File.expand_path("lib", __dir__)
11+
FileUtils.mkdir_p(path)
12+
File.open("\#{path}/with_extension.rb", "w") do |f|
13+
f.puts "WITH_EXTENSION = 'YES'"
14+
end
15+
end
16+
RUBY
17+
end
18+
end
19+
end
20+
21+
it "skips building native extensions when no_build_extension is set" do
22+
bundle_config "no_build_extension true"
23+
24+
gemfile <<-G
25+
source "https://gem.repo2"
26+
gem "with_extension"
27+
gem "rake"
28+
G
29+
30+
bundle :install
31+
32+
build_complete = default_bundle_path("extensions").join(
33+
Gem::Platform.local.to_s,
34+
Gem.extension_api_version.to_s,
35+
"with_extension-1.0",
36+
"gem.build_complete"
37+
)
38+
expect(build_complete).not_to exist
39+
end
40+
41+
it "builds native extensions by default" do
42+
gemfile <<-G
43+
source "https://gem.repo2"
44+
gem "with_extension"
45+
gem "rake"
46+
G
47+
48+
bundle :install
49+
50+
expect(out).to include("Installing with_extension 1.0 with native extensions")
51+
end
52+
end

0 commit comments

Comments
 (0)