11load (
22 "//ruby/private:constants.bzl" ,
33 "BUNDLE_ATTRS" ,
4+ "BUNDLE_BINARY" ,
5+ "BUNDLE_BIN_PATH" ,
6+ "BUNDLE_PATH" ,
47 "RULES_RUBY_WORKSPACE_NAME" ,
8+ "SCRIPT_BUILD_FILE_GENERATOR" ,
9+ "SCRIPT_INSTALL_GEM" ,
510)
611load ("//ruby/private:providers.bzl" , "RubyRuntimeContext" )
712load ("//ruby/private/tools:deprecations.bzl" , "deprecated_attribute" )
813
9- BUNDLE_BIN_PATH = "bin"
10- BUNDLE_PATH = "lib"
11- BUNDLE_BINARY = "bundler/exe/bundler"
12- SCRIPT_INSTALL_GEM = "install_bundler.rb"
13- SCRIPT_BUILD_FILE_GENERATOR = "create_bundle_build_file.rb"
14-
1514# Runs bundler with arbitrary arguments
16- #
1715# eg: run_bundler(runtime_ctx, [ "lock", " --gemfile", "Gemfile.rails5" ])
18- #
1916def run_bundler (runtime_ctx , bundler_arguments ):
17+ #print("BUNDLE RUN", bundler_arguments)
18+
2019 # Now we are running bundle install
2120 args = [
2221 runtime_ctx .interpreter , # ruby
@@ -39,7 +38,7 @@ def run_bundler(runtime_ctx, bundler_arguments):
3938#
4039# Sets local bundler config values by calling
4140#
42- # $ bundler config --local | --global config-option config-value
41+ # $ bundle config --local | --global config-option config-value
4342#
4443# @config_category can be either 'local' or 'global'
4544def set_bundler_config (runtime_ctx , config_category = "local" ):
@@ -51,16 +50,15 @@ def set_bundler_config(runtime_ctx, config_category = "local"):
5150 #
5251 # Set local configuration options for bundler
5352 bundler_config = {
54- "binstubs" : BUNDLE_BIN_PATH ,
55- "deployment" : "'true'" ,
56- "standalone" : "'true'" ,
57- "frozen" : "'true'" ,
53+ "deployment" : "true" ,
54+ "standalone" : "true" ,
55+ "frozen" : "true" ,
5856 "without" : "development,test" ,
5957 "path" : BUNDLE_PATH ,
6058 "jobs" : "20" ,
6159 }
6260
63- for option , value in [( option , value ) for option , value in bundler_config .items ()] :
61+ for option , value in bundler_config .items ():
6462 args = ["config" , "--%s" % (config_category ), option , value ]
6563
6664 result = run_bundler (runtime_ctx , args )
@@ -72,6 +70,13 @@ def set_bundler_config(runtime_ctx, config_category = "local"):
7270 )
7371 fail (message )
7472
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 ])
75+
76+ # This function is called "pure_ruby" because it downloads and unpacks the gem
77+ # file into a given folder, which for gems without C-extensions is the same
78+ # as install. To support gems that have C-extensions, the Ruby file install_gem.rb
79+ # will need to be modified to use Gem::Installer.at(path).install(gem) API.
7580def install_pure_ruby_gem (runtime_ctx , gem_name , gem_version , folder ):
7681 # USAGE: ./install_bundler.rb gem-name gem-version destination-folder
7782 args = [
@@ -104,7 +109,7 @@ def bundle_install(runtime_ctx):
104109 result = run_bundler (
105110 runtime_ctx ,
106111 [
107- "install" , # > bundle install
112+ "install" , # bundle install
108113 "--standalone" , # Makes a bundle that can work without depending on Rubygems or Bundler at runtime.
109114 "--binstubs={}" .format (BUNDLE_BIN_PATH ), # Creates a directory and place any executables from the gem there.
110115 "--path={}" .format (BUNDLE_PATH ), # The location to install the specified gems to.
@@ -120,7 +125,7 @@ def generate_bundle_build_file(runtime_ctx):
120125 args = [
121126 runtime_ctx .interpreter , # ruby interpreter
122127 "--enable=gems" , # prevent the addition of gem installation directories to the default load path
123- "-I" , # -I lib (adds this folder to $LOAD_PATH where ruby searchesf for things)
128+ "-I" , # -I lib (adds this folder to $LOAD_PATH where ruby searches for things)
124129 "bundler/lib" ,
125130 SCRIPT_BUILD_FILE_GENERATOR , # The template used to created bundle file
126131 "BUILD.bazel" , # Bazel build file (can be empty)
@@ -134,14 +139,18 @@ def generate_bundle_build_file(runtime_ctx):
134139 if result .return_code :
135140 fail ("build file generation failed: %s%s" % (result .stdout , result .stderr ))
136141
137- def bundle_install_impl (ctx ):
142+ def _ruby_bundle_impl (ctx ):
138143 ctx .symlink (ctx .attr .gemfile , "Gemfile" )
139144 ctx .symlink (ctx .attr .gemfile_lock , "Gemfile.lock" )
140145 ctx .symlink (ctx .attr ._create_bundle_build_file , SCRIPT_BUILD_FILE_GENERATOR )
141146 ctx .symlink (ctx .attr ._install_bundler , SCRIPT_INSTALL_GEM )
142147
143148 # version is too generic for this operation
144149 deprecated_attribute (ctx , "version" , "bundler_version" )
150+ if ctx .attr .bundler_version :
151+ bundler_version = ctx .attr .bundler_version
152+ else :
153+ bundler_version = ctx .attr .version
145154
146155 # Setup this provider that we pass around between functions for convenience
147156 runtime_ctx = RubyRuntimeContext (
@@ -151,7 +160,7 @@ def bundle_install_impl(ctx):
151160 )
152161
153162 # 1. Install the right version of the Bundler Gem
154- install_bundler (runtime_ctx , ctx . attr . bundler_version )
163+ install_bundler (runtime_ctx , bundler_version )
155164
156165 # Create label for the Bundler executable
157166 bundler = Label ("//:" + BUNDLE_BINARY )
@@ -166,6 +175,6 @@ def bundle_install_impl(ctx):
166175 generate_bundle_build_file (runtime_ctx )
167176
168177ruby_bundle = repository_rule (
169- implementation = bundle_install_impl ,
178+ implementation = _ruby_bundle_impl ,
170179 attrs = BUNDLE_ATTRS ,
171180)
0 commit comments