Skip to content

Commit 64e82e8

Browse files
committed
Fix setting of GEM_HOME
In 1.3.0 we started to launch the Spring server process via a Process.spawn, rather than a fork (ae175de). This brought to light some problems with how we were handling the GEM_HOME environment variable. In < 1.3 it was set to an empty string. In 1.3.0 it was set to nil. The bug was reported in #352 and #383. After switching to Process.spawn, having no value in GEM_HOME in the server process meant that Bundler was unable to find bundled git repositories. In actual fact, we do not need to set the gem home in the binstub. We only need to set the gem path, so that the install of spring which is in the bundle can be found. And we don't really need to mutate the ENV hash either. This makes the binstub clearer and simpler. We then set the GEM_PATH and GEM_HOME as we need them for the env when we spawn the server process.
1 parent 6d96c08 commit 64e82e8

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

lib/spring/client/binstub.rb

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,15 @@ class Binstub < Command
2929
SPRING = <<'CODE'
3030
#!/usr/bin/env ruby
3131
32-
# This file loads spring without using Bundler, in order to be fast
33-
# It gets overwritten when you run the `spring binstub` command
32+
# This file loads spring without using Bundler, in order to be fast.
33+
# It gets overwritten when you run the `spring binstub` command.
3434
3535
unless defined?(Spring)
3636
require "rubygems"
3737
require "bundler"
3838
3939
if match = Bundler.default_lockfile.read.match(/^GEM$.*?^ (?: )*spring \((.*?)\)$.*?^$/m)
40-
ENV["GEM_PATH"] = ([Bundler.bundle_path.to_s] + Gem.path).join(File::PATH_SEPARATOR)
41-
ENV["GEM_HOME"] = nil
42-
Gem.paths = ENV
43-
40+
Gem.paths = { "GEM_PATH" => Bundler.bundle_path.to_s }
4441
gem "spring", match[1]
4542
require "spring/binstub"
4643
end

lib/spring/client/run.rb

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
require "rbconfig"
22
require "socket"
3+
require "bundler"
34

45
module Spring
56
module Client
@@ -64,10 +65,8 @@ def run
6465
def boot_server
6566
env.socket_path.unlink if env.socket_path.exist?
6667

67-
# The GEM_HOME handling is to work around a problem with spring binstubs
68-
# generated prior to 1.3.0.
6968
pid = Process.spawn(
70-
ENV["GEM_HOME"] == "" ? { "GEM_HOME" => nil } : {},
69+
gem_env,
7170
"ruby",
7271
"-r", "spring/server",
7372
"-e", "Spring::Server.boot"
@@ -80,6 +79,16 @@ def boot_server
8079
end
8180
end
8281

82+
def gem_env
83+
bundle = Bundler.bundle_path.to_s
84+
paths = ENV["GEM_PATH"].to_s.split(File::PATH_SEPARATOR)
85+
86+
{
87+
"GEM_PATH" => [bundle, *paths].join(File::PATH_SEPARATOR),
88+
"GEM_HOME" => bundle
89+
}
90+
end
91+
8392
def stop_server
8493
server.close
8594
@server = nil

0 commit comments

Comments
 (0)