Skip to content

Commit 3ea1190

Browse files
Add --gemfile option not to rely on BUNDLE_GEMFILE environment variable
The env var `BUNDLE_GEMFILE` was used to specify the Gemfile path by bundler. However, bundler somehow discards the env var when nested `bundle exec`. This commit adds `--gemfile` option to specify the Gemfile path explicitly without relying on the env var propagation.
1 parent 2496599 commit 3ea1190

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

lib/ruby_wasm/cli.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ def build(args)
5454
profile: "full",
5555
stdlib: true,
5656
disable_gems: false,
57+
gemfile: nil,
5758
patches: [],
5859
}
5960
OptionParser
@@ -115,6 +116,10 @@ def build(args)
115116
options[:format] = format
116117
end
117118

119+
opts.on("--gemfile GEMFILE", "Gemfile") do |gemfile|
120+
options[:gemfile] = gemfile
121+
end
122+
118123
opts.on("--print-ruby-cache-key", "Print Ruby cache key") do
119124
options[:print_ruby_cache_key] = true
120125
end
@@ -279,7 +284,10 @@ def self.bundled_patches_path
279284
def derive_packager(options)
280285
__skip__ =
281286
if defined?(Bundler) && !options[:disable_gems]
282-
definition = Bundler.definition
287+
if options[:gemfile]
288+
Bundler::SharedHelpers.set_env "BUNDLE_GEMFILE", options[:gemfile]
289+
end
290+
definition = Bundler.definition(true) # unlock=true to re-evaluate "BUNDLE_GEMFILE"
283291
end
284292
RubyWasm::Packager.new(root, build_config(options), definition)
285293
end

rakelib/packaging.rake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ namespace :npm do
5252
"RUBY_WASM_ROOT" => base_dir
5353
}
5454
if gemfile_path = pkg[:gemfile]
55-
env["BUNDLE_GEMFILE"] = File.join(base_dir, gemfile_path)
55+
build_command.push "--gemfile", gemfile_path
5656
else
5757
# Explicitly disable rubygems integration since Bundler finds
5858
# Gemfile in the repo root directory.

sig/ruby_wasm/cli.rbs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ module RubyWasm
1515
profile: String,
1616
stdlib: bool,
1717
disable_gems: bool,
18+
gemfile: String?,
1819
patches: Array[String],
1920
format: String,
2021
}

0 commit comments

Comments
 (0)