Skip to content

Commit 81b238c

Browse files
committed
Exclude certain Bundler settings when composing bundle (#3277)
### Motivation Closes #2440, closes #3196 Certain Bundler settings are better used only when the user is in control, like deciding when to package gems or if Bundler should automatically install binstubs for all gems. This PR starts ignoring certain settings from the composed environment. ### Implementation Added a list of ignored settings that we reject before building the environment that we'll use to run bundle install/update. ### Automated Tests Added tests for both bundle bin and bundle package related settings.
1 parent 1918b6c commit 81b238c

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

lib/ruby_lsp/setup_bundler.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,10 +357,17 @@ def bundler_settings_as_env
357357
Bundler::Settings.new
358358
end
359359

360+
# List of Bundler settings that don't make sense for the composed bundle and are better controlled manually by the
361+
# user
362+
ignored_settings = ["bin", "cache_all", "cache_all_platforms"]
363+
360364
# Map all settings to their environment variable names with `key_for` and their values. For example, the if the
361365
# setting name `e` is `path` with a value of `vendor/bundle`, then it will return `"BUNDLE_PATH" =>
362366
# "vendor/bundle"`
363-
settings.all.to_h do |e|
367+
settings
368+
.all
369+
.reject { |setting| ignored_settings.include?(setting) }
370+
.to_h do |e|
364371
key = settings.key_for(e)
365372
value = Array(settings[e]).join(":").tr(" ", ":")
366373

test/setup_bundler_test.rb

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -897,6 +897,51 @@ def test_only_returns_environment_if_bundle_was_composed_ahead_of_time
897897
end
898898
end
899899

900+
def test_ignores_bundle_bin
901+
Dir.mktmpdir do |dir|
902+
Dir.chdir(dir) do
903+
File.write(File.join(dir, "Gemfile"), <<~GEMFILE)
904+
source "https://rubygems.org"
905+
gem "irb"
906+
GEMFILE
907+
908+
capture_subprocess_io do
909+
Bundler.with_unbundled_env do
910+
system("bundle", "config", "set", "--local", "bin", "bin")
911+
system("bundle", "install")
912+
913+
assert_path_exists(File.join(dir, "bin"))
914+
915+
env = RubyLsp::SetupBundler.new(dir, launcher: true).setup!
916+
refute_includes(env.keys, "BUNDLE_BIN")
917+
end
918+
end
919+
end
920+
end
921+
end
922+
923+
def test_ignores_bundle_package
924+
Dir.mktmpdir do |dir|
925+
Dir.chdir(dir) do
926+
File.write(File.join(dir, "Gemfile"), <<~GEMFILE)
927+
source "https://rubygems.org"
928+
gem "irb"
929+
GEMFILE
930+
931+
capture_subprocess_io do
932+
Bundler.with_unbundled_env do
933+
system("bundle", "install")
934+
system("bundle", "package")
935+
936+
env = RubyLsp::SetupBundler.new(dir, launcher: true).setup!
937+
refute_includes(env.keys, "BUNDLE_CACHE_ALL")
938+
refute_includes(env.keys, "BUNDLE_CACHE_ALL_PLATFORMS")
939+
end
940+
end
941+
end
942+
end
943+
end
944+
900945
private
901946

902947
def with_default_external_encoding(encoding, &block)

0 commit comments

Comments
 (0)