@@ -13,19 +13,23 @@ load("//ruby/private/tools:deprecations.bzl", "deprecated_attribute")
1313
1414# Runs bundler with arbitrary arguments
1515# eg: run_bundler(runtime_ctx, [ "lock", " --gemfile", "Gemfile.rails5" ])
16- def run_bundler (runtime_ctx , bundler_arguments ):
17- #print("BUNDLE RUN", bundler_arguments)
18-
16+ def run_bundler (runtime_ctx , bundler_arguments , previous_result ):
1917 # Now we are running bundle install
18+ bundler_command = bundler_arguments [0 ]
19+ bundler_args = []
20+
21+ # add --verbose to all commands except install
22+ if bundler_command != "install" :
23+ bundler_args += ["--verbose" ]
24+
25+ bundler_args += bundler_arguments [1 :]
26+
2027 args = [
2128 runtime_ctx .interpreter , # ruby
22- "--enable=gems" , # bundler must run with rubygems enabled
23- "-I" ,
24- "." ,
2529 "-I" , # Used to tell Ruby where to load the library scripts
2630 BUNDLE_PATH , # Add vendor/bundle to the list of resolvers
2731 BUNDLE_BINARY , # our binary
28- ] + bundler_arguments
32+ ] + [ bundler_command ] + bundler_args
2933
3034 # print("Bundler Command:\n\n", args)
3135
@@ -41,7 +45,7 @@ def run_bundler(runtime_ctx, bundler_arguments):
4145# $ bundle config --local | --global config-option config-value
4246#
4347# @config_category can be either 'local' or 'global'
44- def set_bundler_config (runtime_ctx , config_category = "local" ):
48+ def set_bundler_config (runtime_ctx , previous_result , config_category = "local" ):
4549 # Bundler is deprecating various flags in favor of the configuration.
4650 # HOWEVER — for reasons I can't explain, Bazel runs "bundle install" *prior*
4751 # to setting these flags. So the flags are then useless until we can force the
@@ -52,16 +56,20 @@ def set_bundler_config(runtime_ctx, config_category = "local"):
5256 bundler_config = {
5357 "deployment" : "true" ,
5458 "standalone" : "true" ,
59+ "force" : "false" ,
60+ "redownload" : "false" ,
5561 "frozen" : "true" ,
56- "without" : "development,test" ,
5762 "path" : BUNDLE_PATH ,
5863 "jobs" : "20" ,
64+ "shebang" : runtime_ctx .interpreter ,
5965 }
6066
61- for option , value in bundler_config .items ():
62- args = ["config" , "--%s" % (config_category ), option , value ]
67+ last_result = previous_result
6368
64- result = run_bundler (runtime_ctx , args )
69+ for option , value in bundler_config .items ():
70+ args = ["config" , "set" , "--%s" % (config_category ), option , value ]
71+ result = run_bundler (runtime_ctx , args , last_result )
72+ last_result = result
6573 if result .return_code :
6674 message = "Failed to set bundle config {} to {}: {}" .format (
6775 option ,
@@ -70,8 +78,7 @@ def set_bundler_config(runtime_ctx, config_category = "local"):
7078 )
7179 fail (message )
7280
73- # The new way to generate binstubs is via the binstubs command, not config option.
74- return run_bundler (runtime_ctx , ["binstubs" , "--path" , BUNDLE_BIN_PATH ])
81+ return last_result
7582
7683# This function is called "pure_ruby" because it downloads and unpacks the gem
7784# file into a given folder, which for gems without C-extensions is the same
@@ -96,6 +103,8 @@ def install_pure_ruby_gem(runtime_ctx, gem_name, gem_version, folder):
96103 result .stderr ,
97104 )
98105 fail (message )
106+ else :
107+ return result
99108
100109def install_bundler (runtime_ctx , bundler_version ):
101110 return install_pure_ruby_gem (
@@ -105,21 +114,26 @@ def install_bundler(runtime_ctx, bundler_version):
105114 "bundler" ,
106115 )
107116
108- def bundle_install (runtime_ctx ):
117+ def bundle_install (runtime_ctx , previous_result ):
109118 result = run_bundler (
110119 runtime_ctx ,
111120 [
112- "install" , # bundle install
113- "--standalone" , # Makes a bundle that can work without depending on Rubygems or Bundler at runtime.
114- "--binstubs={}" .format (BUNDLE_BIN_PATH ), # Creates a directory and place any executables from the gem there.
115- "--path={}" .format (BUNDLE_PATH ), # The location to install the specified gems to.
121+ "install" ,
122+ "--binstubs={}" .format (BUNDLE_BIN_PATH ),
123+ "--path={}" .format (BUNDLE_PATH ),
124+ "--deployment" ,
125+ "--standalone" ,
126+ "--frozen" ,
116127 ],
128+ previous_result ,
117129 )
118130
119131 if result .return_code :
120132 fail ("bundle install failed: %s%s" % (result .stdout , result .stderr ))
133+ else :
134+ return result
121135
122- def generate_bundle_build_file (runtime_ctx ):
136+ def generate_bundle_build_file (runtime_ctx , previous_result ):
123137 # Create the BUILD file to expose the gems to the WORKSPACE
124138 # USAGE: ./create_bundle_build_file.rb BUILD.bazel Gemfile.lock repo-name [excludes-json] workspace-name
125139 args = [
@@ -160,19 +174,16 @@ def _ruby_bundle_impl(ctx):
160174 )
161175
162176 # 1. Install the right version of the Bundler Gem
163- install_bundler (runtime_ctx , bundler_version )
164-
165- # Create label for the Bundler executable
166- bundler = Label ("//:" + BUNDLE_BINARY )
177+ result = install_bundler (runtime_ctx , bundler_version )
167178
168179 # 2. Set Bundler config in the .bundle/config file
169- set_bundler_config (runtime_ctx )
180+ result = set_bundler_config (runtime_ctx , result )
170181
171182 # 3. Run bundle install
172- bundle_install (runtime_ctx )
183+ result = bundle_install (runtime_ctx , result )
173184
174185 # 4. Generate the BUILD file for the bundle
175- generate_bundle_build_file (runtime_ctx )
186+ generate_bundle_build_file (runtime_ctx , result )
176187
177188ruby_bundle = repository_rule (
178189 implementation = _ruby_bundle_impl ,
0 commit comments