@@ -44,7 +44,7 @@ def run_bundler(runtime_ctx, bundler_arguments, previous_result):
4444# $ bundle config --local | --global config-option config-value
4545#
4646# @config_category can be either 'local' or 'global'
47- def set_bundler_config (runtime_ctx , previous_result , config_category = "local" ):
47+ def set_bundler_config (runtime_ctx , previous_result , has_lock = True , config_category = "local" ):
4848 # Bundler is deprecating various flags in favor of the configuration.
4949 # HOWEVER — for reasons I can't explain, Bazel runs "bundle install" *prior*
5050 # to setting these flags. So the flags are then useless until we can force the
@@ -53,11 +53,11 @@ def set_bundler_config(runtime_ctx, previous_result, config_category = "local"):
5353 #
5454 # Set local configuration options for bundler
5555 bundler_config = {
56- "deployment" : "true" ,
56+ "deployment" : "true" if has_lock else "false" ,
5757 "standalone" : "true" ,
5858 "force" : "false" ,
5959 "redownload" : "false" ,
60- "frozen" : "true" ,
60+ "frozen" : "true" if has_lock else "false" ,
6161 "path" : BUNDLE_PATH ,
6262 "jobs" : "20" ,
6363 "shebang" : runtime_ctx .interpreter ,
@@ -116,12 +116,12 @@ def install_bundler(runtime_ctx, bundler_version):
116116def bundle_install (runtime_ctx , previous_result ):
117117 cwd = runtime_ctx .ctx .path ("." )
118118 bundler_args = [
119- "install" ,
120- "--binstubs={}" .format (cwd .get_child (BUNDLE_BIN_PATH )),
121- "--path={}" .format (cwd .get_child (BUNDLE_PATH )),
119+ "install" , "-V" ,
122120 "--standalone" ,
123121 "--gemfile={}" .format (runtime_ctx .ctx .attr .gemfile .name ),
122+ "--jobs=10" , # run a few jobs to ensure no gem install is blocking another
124123 ]
124+
125125 if runtime_ctx .ctx .attr .gemfile_lock :
126126 bundler_args += ["--deployment" , "--frozen" ]
127127
@@ -133,8 +133,15 @@ def bundle_install(runtime_ctx, previous_result):
133133
134134 if result .return_code :
135135 fail ("bundle install failed: %s%s" % (result .stdout , result .stderr ))
136- else :
137- return result
136+
137+ # Creates a directory and place any executables from the gem there.
138+ result = run_bundler (runtime_ctx , [
139+ "binstubs" , "--all" , "--path" , "{}" .format (BUNDLE_BIN_PATH )
140+ ], previous_result )
141+ if result .return_code :
142+ fail ("bundle binstubs failed: %s%s" % (result .stdout , result .stderr ))
143+
144+ return result
138145
139146def generate_bundle_build_file (runtime_ctx , previous_result ):
140147 if runtime_ctx .ctx .attr .gemfile_lock :
@@ -185,16 +192,27 @@ def _ruby_bundle_impl(ctx):
185192 environment = {"RUBYOPT" : "--enable-gems" },
186193 )
187194
195+ result = run_bundler (
196+ runtime_ctx ,
197+ ["clean" ],
198+ None ,
199+ )
200+
188201 # 1. Install the right version of the Bundler Gem
189202 result = install_bundler (runtime_ctx , bundler_version )
190203
191- # 2. Set Bundler config in the .bundle/config file
204+ # 2. Generate a Gemfile.lock file if one isn't provided
205+ if not runtime_ctx .ctx .attr .gemfile_lock :
206+ result = set_bundler_config (runtime_ctx , result , has_lock = False )
207+ result = bundle_install (runtime_ctx , result )
208+
209+ # 3. Set Bundler config in the .bundle/config file
192210 result = set_bundler_config (runtime_ctx , result )
193211
194- # 3 . Run bundle install
212+ # 4 . Run bundle install
195213 result = bundle_install (runtime_ctx , result )
196214
197- # 4 . Generate the BUILD file for the bundle
215+ # 5 . Generate the BUILD file for the bundle
198216 generate_bundle_build_file (runtime_ctx , result )
199217
200218ruby_bundle_install = repository_rule (
0 commit comments