@@ -89,10 +89,14 @@ def self.setup_gem_environment!(setup_path: true)
89
89
90
90
# Match where our bundler gems are.
91
91
gem_home = "#{ RUBY_BUNDLE_VENDOR_DIRECTORY } /#{ RbConfig ::CONFIG [ "ruby_version" ] } "
92
+ homebrew_cache = ENV . fetch ( "HOMEBREW_CACHE" , nil )
93
+ gem_cache = "#{ homebrew_cache } /gem-spec-cache" if homebrew_cache
94
+
92
95
Gem . paths = {
93
- "GEM_HOME" => gem_home ,
94
- "GEM_PATH" => gem_home ,
95
- }
96
+ "GEM_HOME" => gem_home ,
97
+ "GEM_PATH" => gem_home ,
98
+ "GEM_SPEC_CACHE" => gem_cache ,
99
+ } . compact
96
100
97
101
# Set TMPDIR so Xcode's `make` doesn't fall back to `/var/tmp/`,
98
102
# which may be not user-writable.
@@ -110,6 +114,7 @@ def self.setup_gem_environment!(setup_path: true)
110
114
# We don't do this unless requested as some formulae may invoke system Ruby instead of ours.
111
115
ENV [ "GEM_HOME" ] = gem_home
112
116
ENV [ "GEM_PATH" ] = gem_home
117
+ ENV [ "GEM_SPEC_CACHE" ] = gem_cache if gem_cache
113
118
end
114
119
115
120
def self . install_gem! ( name , version : nil , setup_gem_environment : true )
@@ -222,6 +227,7 @@ def self.install_bundler_gems!(only_warn_on_failure: false, setup_path: true, gr
222
227
old_path = ENV . fetch ( "PATH" , nil )
223
228
old_gem_path = ENV . fetch ( "GEM_PATH" , nil )
224
229
old_gem_home = ENV . fetch ( "GEM_HOME" , nil )
230
+ old_gem_spec_cache = ENV . fetch ( "GEM_SPEC_CACHE" , nil )
225
231
old_bundle_gemfile = ENV . fetch ( "BUNDLE_GEMFILE" , nil )
226
232
old_bundle_with = ENV . fetch ( "BUNDLE_WITH" , nil )
227
233
old_bundle_frozen = ENV . fetch ( "BUNDLE_FROZEN" , nil )
@@ -343,6 +349,7 @@ def self.install_bundler_gems!(only_warn_on_failure: false, setup_path: true, gr
343
349
ENV [ "PATH" ] = old_path
344
350
ENV [ "GEM_PATH" ] = old_gem_path
345
351
ENV [ "GEM_HOME" ] = old_gem_home
352
+ ENV [ "GEM_SPEC_CACHE" ] = old_gem_spec_cache
346
353
ENV [ "BUNDLE_GEMFILE" ] = old_bundle_gemfile
347
354
ENV [ "BUNDLE_WITH" ] = old_bundle_with
348
355
ENV [ "BUNDLE_FROZEN" ] = old_bundle_frozen
0 commit comments