Skip to content

Commit

Permalink
Fix debug platform inclusion for Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
vinistock committed Dec 13, 2024
1 parent c9040d7 commit 6015989
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
14 changes: 12 additions & 2 deletions lib/ruby_lsp/setup_bundler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,13 @@ def write_custom_gemfile
end

unless @dependencies["debug"]
parts << 'gem "debug", require: false, group: :development, platforms: :mri'
# The `mri` platform excludes Windows. We want to install the debug gem only on MRI for any operating system,
# but that constraint doesn't yet exist in Bundler. On Windows, we are manually checking if the engine is MRI
parts << if Gem.win_platform?
'gem "debug", require: false, group: :development, install_if: -> { RUBY_ENGINE == "ruby" }'
else
'gem "debug", require: false, group: :development, platforms: :mri'
end
end

if @rails_app && !@dependencies["ruby-lsp-rails"]
Expand Down Expand Up @@ -238,9 +244,13 @@ def run_bundle_install(bundle_gemfile = @gemfile)
sig { params(env: T::Hash[String, String]).returns(T::Hash[String, String]) }
def run_bundle_install_directly(env)
RubyVM::YJIT.enable if defined?(RubyVM::YJIT.enable)

# The ENV can only be merged after checking if an update is required because we depend on the original value of
# ENV["BUNDLE_GEMFILE"], which gets overridden after the merge
should_update = should_bundle_update?
T.unsafe(ENV).merge!(env)

unless should_bundle_update?
unless should_update
Bundler::CLI::Install.new({}).run
correct_relative_remote_paths if @custom_lockfile.exist?
return env
Expand Down
33 changes: 33 additions & 0 deletions test/setup_bundler_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -823,6 +823,39 @@ def test_is_resilient_to_gemfile_changes_in_the_middle_of_setup
end
end

def test_composed_bundle_includes_debug
Dir.mktmpdir do |dir|
Dir.chdir(dir) do
File.write(File.join(dir, "Gemfile"), <<~GEMFILE)
source "https://rubygems.org"
GEMFILE

env = T.let({}, T::Hash[String, T.untyped])

Bundler.with_unbundled_env do
env = ENV.to_hash

capture_subprocess_io do
system("bundle install")
assert_path_exists("Gemfile.lock")

new_env = RubyLsp::SetupBundler.new(dir, launcher: true).setup!
env["BUNDLE_GEMFILE"] = new_env["BUNDLE_GEMFILE"]
env["BUNDLE_PATH"] = new_env["BUNDLE_PATH"] if new_env["BUNDLE_PATH"]
end
end

Bundler.with_unbundled_env do
_stdout, stderr = capture_subprocess_io do
system(env, "bundle exec ruby -e 'require \"debug\"'")
end

assert_empty(stderr)
end
end
end
end

private

def with_default_external_encoding(encoding, &block)
Expand Down

0 comments on commit 6015989

Please sign in to comment.