From 3670f664d488c4917fa9e1252269373f7fbc5335 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Wed, 8 May 2019 12:03:24 +0200 Subject: [PATCH] Preserve environment when shelling out to `gem build` --- lib/bundler/gem_helper.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/bundler/gem_helper.rb b/lib/bundler/gem_helper.rb index 33f1d515922..1b899d3f5e7 100644 --- a/lib/bundler/gem_helper.rb +++ b/lib/bundler/gem_helper.rb @@ -76,7 +76,7 @@ def install def build_gem file_name = nil gem = ENV["BUNDLE_GEM"] ? ENV["BUNDLE_GEM"] : "gem" - sh(%W[#{gem} build -V #{spec_path}]) do + sh(%W[#{gem} build -V #{spec_path}], "RUBYOPT" => "-I#{File.expand_path("..", __dir__)}") do file_name = File.basename(built_gem_path) SharedHelpers.filesystem_access(File.join(base, "pkg")) {|p| FileUtils.mkdir_p(p) } FileUtils.mv(built_gem_path, "pkg") @@ -180,8 +180,8 @@ def name gemspec.name end - def sh(cmd, &block) - out, status = sh_with_status(cmd, &block) + def sh(cmd, env = {}, &block) + out, status = sh_with_status(cmd, env, &block) unless status.success? cmd = cmd.shelljoin if cmd.respond_to?(:shelljoin) raise(out.empty? ? "Running `#{cmd}` failed. Run this command directly for more detailed output." : out) @@ -189,10 +189,10 @@ def sh(cmd, &block) out end - def sh_with_status(cmd, &block) + def sh_with_status(cmd, env = {}, &block) Bundler.ui.debug(cmd) SharedHelpers.chdir(base) do - outbuf = IO.popen(cmd, :err => [:child, :out], &:read) + outbuf = IO.popen(env, cmd, :err => [:child, :out], &:read) status = $? block.call(outbuf) if status.success? && block [outbuf, status]