-
Notifications
You must be signed in to change notification settings - Fork 35
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
base: master
Are you sure you want to change the base?
Changes from all commits
2d953d2
f3dbb5e
231a94c
92134ec
5169a86
4856c9f
e084ce4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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", | ||
|
@@ -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' | ||
|
@@ -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)} | ||
.reject{|dep| dep.source.path? unless dep.source.nil?} | ||
.map(&:name)} | ||
} | ||
.reduce Hash.new, :merge | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You need to do |
||
.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 | ||
|
||
|
@@ -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 | ||
|
There was a problem hiding this comment.
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.