Skip to content

Add support for adding just the gems in a particular bundle group #127

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
31 changes: 30 additions & 1 deletion ruby/private/bundle/create_bundle_build_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@
)
GEM_TEMPLATE

GEM_GROUP = <<~GEM_GROUP
ruby_library(
name = "gems_{group_name}_group",
deps = {group_gems}
)
GEM_GROUP

ALL_GEMS = <<~ALL_GEMS
ruby_library(
name = "gems",
Expand Down Expand Up @@ -84,6 +91,10 @@
Dir.glob("lib/#{RbConfig::CONFIG['RUBY_INSTALL_NAME']}/#{ruby_version}/specifications/#{gem_name}-#{gem_version}*.gemspec").first
end

EXTENSIONS_PATH = ->(ruby_version, gem_name, gem_version) do
Dir.glob("lib/#{RbConfig::CONFIG['RUBY_INSTALL_NAME']}/#{ruby_version}/extensions/*/#{gem_name}/**/*").first
end

require 'bundler'
require 'json'
require 'stringio'
Expand Down Expand Up @@ -211,7 +222,14 @@ def generate!
bundle_lib_paths = []
bundle_binaries = {} # gem-name => [ gem's binaries ], ...
gems = bundle.specs.map(&:name)

bundle_deps = Bundler::Definition.build(gemfile_lock.chomp('.lock'), gemfile_lock, {}).dependencies
groups = bundle_deps.map{|dep| dep.groups}.flatten.uniq
gems_by_group = groups.map{ |g| {g => bundle_deps
.select{|dep| dep.groups.include?(g)}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please annotate with comments each line here and explain what it's doing.

.reject{|dep| dep.source.path? unless dep.source.nil?}
.map(&:name)}
}
.reduce Hash.new, :merge
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What?

bundle.specs.each { |spec| register_gem(spec, template_out, bundle_lib_paths, bundle_binaries) }

template_out.puts ALL_GEMS
Expand All @@ -223,6 +241,13 @@ def generate!
.gsub('{bundle_deps}', gems.map { |g| ":#{g}" }.to_s)
.gsub('{exclude}', DEFAULT_EXCLUDES.to_s)

gems_by_group.each do |key, value|
template_out.puts GEM_GROUP
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to do GEM_GROUP.dup to bypass the frozen constant error. The way it's written right now, the code is attempting to modify the frozen constant.

.gsub('{group_name}', key.to_s)
.gsub('{group_gems}', value.map{|s| s.prepend ':' unless s.start_with? ':'}.compact.to_s)
end


::File.open(build_file, 'w') { |f| f.puts template_out.string }
end

Expand Down Expand Up @@ -312,6 +337,10 @@ def find_bundle_binaries(gem_path)
.map { |binary| "bin/#{binary}" }
end

def gems_in_group(gems, group_name)
gems
end

def include_array(gem_name)
(includes[gem_name] || [])
end
Expand Down