Skip to content

Commit

Permalink
Decouple extract_gem_files from Gem class dependency
Browse files Browse the repository at this point in the history
- Removed the dependency on the Gem class from the extract_gem_files method. Previously, this method extracted loaded specs directly from Gem.
- Transferred the code that retrieves loaded specs from Gem to the build process side. This change allows the build process to decide whether to collect used Gems.
  • Loading branch information
shinokaro committed Jun 25, 2024
1 parent 22ee06a commit 09e2703
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions bin/ocran
Original file line number Diff line number Diff line change
Expand Up @@ -397,8 +397,6 @@ EOF
features_from_gems = []
gems = {}

# Include Gems that are loaded
Gem.loaded_specs.each { |name, spec| gems[name] ||= spec }
# Fall back to gem detection (loaded_specs are not population on
# all Ruby versions)
features.each do |feature|
Expand Down Expand Up @@ -523,9 +521,12 @@ EOF
# Find gems files and remove them from features
if defined?(Gem)
gemfile_gems = specs_from_gemfile.map { |spec| [spec.name, spec] }.to_h
# Include Gems that are loaded
loaded_specs = Gem.loaded_specs.values.map { |spec| [spec.name, spec] }.to_h

features_from_gems, detected_gems = extract_gem_files(features)
# Prioritize the spec detected from Gemfile.
gemspecs = detected_gems.merge(gemfile_gems).values
gemspecs = detected_gems.merge(loaded_specs).merge(gemfile_gems).values
gem_files = find_gem_files(features_from_gems, gemspecs)
features -= (features_from_gems - gem_files)
else
Expand Down

0 comments on commit 09e2703

Please sign in to comment.