@@ -15,41 +15,54 @@ def _get_bundler_lib_label(repository_ctx, ruby_sdk):
1515def bundle_install_impl (ctx ):
1616 ctx .symlink (ctx .attr .gemfile , "Gemfile" )
1717 ctx .symlink (ctx .attr .gemfile_lock , "Gemfile.lock" )
18+ ctx .symlink (ctx .attr ._create_bundle_build_file , "create_bundle_build_file.rb" )
1819
1920 ruby = _get_interpreter_label (ctx , ctx .attr .ruby_sdk )
2021 bundler = _get_bundler_label (ctx , ctx .attr .ruby_sdk )
2122
23+ # Install the Gems into the workspace
2224 args = [
23- 'env' , '-i' ,
24- ctx .path (ruby ),
25- '--disable-gems' ,
26- '-I' , ctx .path (bundler ).dirname .dirname .get_child ('lib' ),
27- ctx .path (bundler ),
28- 'install' ,
29- '--deployment' ,
30- '--standalone' ,
31- '--frozen' ,
32- '--binstubs=bin' ,
33- '--path=lib' ,
25+ 'env' , '-i' , # remove all environment variables
26+ ctx .path (ruby ), # ruby
27+ '--disable-gems' , # prevent the addition of gem installation directories to the default load path
28+ '-I' , ctx .path (bundler ).dirname .dirname .get_child ('lib' ), # Used to tell Ruby where to load the library scripts
29+ ctx .path (bundler ), # execute bundler
30+ 'install' , # install
31+ '--deployment' , # In deployment mode, Bundler will 'roll-out' the bundle for production or CI use.
32+ '--standalone' , # Makes a bundle that can work without depending on Rubygems or Bundler at runtime.
33+ '--frozen' , # Do not allow the Gemfile.lock to be updated after this install.
34+ '--binstubs=bin' , # Creates a directory and place any executables from the gem there.
35+ '--path=lib' , # The location to install the specified gems to.
3436 ]
3537 result = ctx .execute (args , quiet = False )
38+
3639 if result .return_code :
3740 fail ("Failed to install gems: %s%s" % (result .stdout , result .stderr ))
3841
42+ # exclude any specified files
3943 exclude = []
4044 for gem , globs in ctx .attr .excludes .items ():
4145 expanded = ["lib/ruby/*/gems/%s-*/%s" % (gem , glob ) for glob in globs ]
4246 exclude .extend (expanded )
4347
44- ctx .template (
48+ # Create the BUILD file to expose the gems to the WORKSPACE
49+ args = [
50+ 'env' , '-i' , # remove all environment variables
51+ ctx .path (ruby ), # ruby
52+ '--disable-gems' , # prevent the addition of gem installation directories to the default load path
53+ '-I' , ctx .path (bundler ).dirname .dirname .get_child ('lib' ), # Used to tell Ruby where to load the library scripts
54+ 'create_bundle_build_file.rb' ,
4555 'BUILD.bazel' ,
46- ctx .attr ._buildfile_template ,
47- substitutions = {
48- "{repo_name}" : ctx .name ,
49- "{exclude}" : repr (exclude ),
50- "{workspace_name}" : RULES_RUBY_WORKSPACE_NAME ,
51- },
52- )
56+ 'Gemfile.lock' ,
57+ ctx .name ,
58+ repr (exclude ),
59+ RULES_RUBY_WORKSPACE_NAME ,
60+
61+ ]
62+ result = ctx .execute (args , quiet = False )
63+
64+ if result .return_code :
65+ fail ("Failed to create build file: %s%s" % (result .stdout , result .stderr ))
5366
5467
5568bundle_install = repository_rule (
@@ -68,10 +81,10 @@ bundle_install = repository_rule(
6881 doc = "List of glob patterns per gem to be excluded from the library" ,
6982 ),
7083
71- "_buildfile_template " : attr .label (
72- default = "%s//ruby/private/bundle:BUILD.bundle.tpl " % (
84+ "_create_bundle_build_file " : attr .label (
85+ default = "%s//ruby/private/bundle:create_bundle_build_file.rb " % (
7386 RULES_RUBY_WORKSPACE_NAME ),
74- doc = "The template of BUILD files for installed gem bundles " ,
87+ doc = "Creates the BUILD file " ,
7588 allow_single_file = True ,
7689 ),
7790 },
0 commit comments