summaryrefslogtreecommitdiff
path: root/lib/rubygems/specification.rb
AgeCommit message (Collapse)Author
2 days[ruby/rubygems] Fix RubyGems not able to require the right gem:Edouard CHIN
- Fix https://github.com/ruby/rubygems/issues/9238 - ### Problem This is an issue that bites gem maintainers from time to time, with the most recent one in https://github.com/minitest/minitest/issues/1040#issuecomment-3679370619 The issue is summarized as follow: 1) A gem "X" has a feature in "lib/feature.rb" 2) Maintainer wants to extract this feature into its own gem "Y" 3) Maintainer cut a release of X without that new feature. 4) Users install the new version of X and also install the new gem "Y" since the feature is now extracted. 5) When a call to "require 'feature'" is encountered, RG will fail to load the right gem, resulting in a `LoadError`. ### Details Now that we have two gems (old version of X and new gem Y) with the same path, RubyGems will detect that `feature.rb` can be loaded from the old version of X, but if the new version of X had already been loaded, then RubyGems will raise due to versions conflicting. ```ruby require 'x' # Loads the new version of X without the feature which was extracted. require 'feature' # Rubygems see that the old version of X include that file and tries to activate the spec. ``` ### Solution I propose that RubyGems fallback to a spec that's not yet loaded. We try to find a spec by its path and filter it out in case a spec with the same name has already been loaded. Its worth to note that RubyGems already has a `find_inactive_by_path` but we can't use it. This method only checks if the spec object is active and doesn't look if other spec with the same name have been loaded. The new method we are introducing verifies this. https://github.com/ruby/rubygems/commit/f298e2c68e
2025-12-26[ruby/rubygems] Remove deprecated, unused Gem::ListHiroshi SHIBATA
https://github.com/ruby/rubygems/commit/43371085f4
2025-11-18[ruby/rubygems] Undeprecate `Gem::Version.new(nil)`Aaron Patterson
It seems like we were trying to deprecate passing `nil` to Gem::Version.new. This breaks existing code, and I don't think there is a good reason to deprecate this usage. I believe what we want to prevent is the following code: ```ruby Gem::Specification.new do |spec| spec.version = nil # suddenly the spec version is 0! p spec.version end ``` This commit allows people to manually construct `Gem::Version.new(nil)`, but when someone assigns `nil` as the Gem specification version, it sets the spec version to `nil` (making the specification invalid). People who manually construct `Gem::Version` objects and use nil should be allowed to do it, and `Gem::Version.new(nil) == Gem::Version.new("0")`, but people who assign `nil` in a gemspec will get an invalid gemspec. I think deprecation started [here](https://github.com/ruby/rubygems/pull/2203) but there doesn't seem to be a reason to do it. Fixes https://github.com/ruby/rubygems/pull/9052 https://github.com/ruby/rubygems/commit/ded5e909c2
2025-11-14[ruby/rubygems] Removed deprecated Gem::Specification#has_rdoc, has_rdoc= ↵Hiroshi SHIBATA
and has_rdoc? https://github.com/ruby/rubygems/commit/b043538576
2025-11-14[ruby/rubygems] bin/rubocop -a --only Layout/EmptyLinesAroundClassBodyHiroshi SHIBATA
https://github.com/ruby/rubygems/commit/94d4e633d1
2025-11-14[ruby/rubygems] Removed deprecated Gem::Specification#validate_metadata, ↵Hiroshi SHIBATA
validate_dependencies and validate_permissions https://github.com/ruby/rubygems/commit/fbf38fc190
2025-11-14[ruby/rubygems] Removed deprecated Gem::Specification#default_executableHiroshi SHIBATA
https://github.com/ruby/rubygems/commit/84ceaff1b7
2025-10-15[rubygems/rubygems] remove some memoizationAaron Patterson
I don't think these methods are hotspots, and since gem specifications are sometimes serialized to yaml / marshal, I think we should remove as many instance variables as possible https://github.com/rubygems/rubygems/commit/40490d918b
2025-08-18[rubygems/rubygems] Use spaces around optional parameter valuesDavid Rodríguez
https://github.com/rubygems/rubygems/commit/b58829a868
2025-06-03[rubygems/rubygems] misc: fix spellingJohn Bampton
https://github.com/rubygems/rubygems/commit/0e40e7d938
2025-04-01[rubygems/rubygems] Sorting files in metadata for reproducibilityGiacomo Benedetti
https://github.com/rubygems/rubygems/commit/792117980b
2025-02-03[rubygems/rubygems] Raise a simpler error when RubyGems fails to activate a ↵David Rodríguez
dependency If you force uninstall a dependency but leave other gems depending on it, those gems will fail to be activated. In that case, RubyGems prints a rather complicated error: ``` $ rails --version /Users/deivid/.asdf/installs/ruby/3.4.1/lib/ruby/site_ruby/3.4.0/rubygems/specification.rb:1413:in 'block in Gem::Specification#activate_dependencies': Could not find 'activesupport' (= 8.0.1) among 478 total gem(s) (Gem::MissingSpecError) Checked in 'GEM_PATH=/Users/deivid/.local/share/gem/ruby/3.4.0:/Users/deivid/.asdf/installs/ruby/3.4.1/lib/ruby/gems/3.4.0' at: /Users/deivid/.asdf/installs/ruby/3.4.1/lib/ruby/gems/3.4.0/specifications/railties-8.0.1.gemspec, execute `gem env` for more information from /Users/deivid/.asdf/installs/ruby/3.4.1/lib/ruby/site_ruby/3.4.0/rubygems/specification.rb:1399:in 'Array#each' from /Users/deivid/.asdf/installs/ruby/3.4.1/lib/ruby/site_ruby/3.4.0/rubygems/specification.rb:1399:in 'Gem::Specification#activate_dependencies' from /Users/deivid/.asdf/installs/ruby/3.4.1/lib/ruby/site_ruby/3.4.0/rubygems/specification.rb:1381:in 'Gem::Specification#activate' from /Users/deivid/.asdf/installs/ruby/3.4.1/lib/ruby/site_ruby/3.4.0/rubygems.rb:283:in 'block in Gem.activate_bin_path' from /Users/deivid/.asdf/installs/ruby/3.4.1/lib/ruby/site_ruby/3.4.0/rubygems.rb:282:in 'Thread::Mutex#synchronize' from /Users/deivid/.asdf/installs/ruby/3.4.1/lib/ruby/site_ruby/3.4.0/rubygems.rb:282:in 'Gem.activate_bin_path' from /Users/deivid/.asdf/installs/ruby/3.4.1/bin/rails:25:in '<main>' /Users/deivid/.asdf/installs/ruby/3.4.1/lib/ruby/site_ruby/3.4.0/rubygems/dependency.rb:303:in 'Gem::Dependency#to_specs': Could not find 'activesupport' (= 8.0.1) - did find: [activesupport-7.1.3,activesupport-7.0.8.7] (Gem::MissingSpecVersionError) Checked in 'GEM_PATH=/Users/deivid/.local/share/gem/ruby/3.4.0:/Users/deivid/.asdf/installs/ruby/3.4.1/lib/ruby/gems/3.4.0' , execute `gem env` for more information from /Users/deivid/.asdf/installs/ruby/3.4.1/lib/ruby/site_ruby/3.4.0/rubygems/specification.rb:1411:in 'block in Gem::Specification#activate_dependencies' from /Users/deivid/.asdf/installs/ruby/3.4.1/lib/ruby/site_ruby/3.4.0/rubygems/specification.rb:1399:in 'Array#each' from /Users/deivid/.asdf/installs/ruby/3.4.1/lib/ruby/site_ruby/3.4.0/rubygems/specification.rb:1399:in 'Gem::Specification#activate_dependencies' from /Users/deivid/.asdf/installs/ruby/3.4.1/lib/ruby/site_ruby/3.4.0/rubygems/specification.rb:1381:in 'Gem::Specification#activate' from /Users/deivid/.asdf/installs/ruby/3.4.1/lib/ruby/site_ruby/3.4.0/rubygems.rb:283:in 'block in Gem.activate_bin_path' from /Users/deivid/.asdf/installs/ruby/3.4.1/lib/ruby/site_ruby/3.4.0/rubygems.rb:282:in 'Thread::Mutex#synchronize' from /Users/deivid/.asdf/installs/ruby/3.4.1/lib/ruby/site_ruby/3.4.0/rubygems.rb:282:in 'Gem.activate_bin_path' from /Users/deivid/.asdf/installs/ruby/3.4.1/bin/rails:25:in '<main>' ``` With this commit, the error becomes a bit simpler to parse: ``` $ rails --version /Users/deivid/.asdf/installs/ruby/3.4.1/lib/ruby/site_ruby/3.4.0/rubygems/specification.rb:1421:in 'block in Gem::Specification#activate_dependencies': Could not find 'activesupport' (= 8.0.1) among 478 total gem(s) (Gem::MissingSpecError) Checked in 'GEM_PATH=/Users/deivid/.local/share/gem/ruby/3.4.0:/Users/deivid/.asdf/installs/ruby/3.4.1/lib/ruby/gems/3.4.0' at: /Users/deivid/.asdf/installs/ruby/3.4.1/lib/ruby/gems/3.4.0/specifications/railties-8.0.1.gemspec, execute `gem env` for more information from /Users/deivid/.asdf/installs/ruby/3.4.1/lib/ruby/site_ruby/3.4.0/rubygems/specification.rb:1407:in 'Array#each' from /Users/deivid/.asdf/installs/ruby/3.4.1/lib/ruby/site_ruby/3.4.0/rubygems/specification.rb:1407:in 'Gem::Specification#activate_dependencies' from /Users/deivid/.asdf/installs/ruby/3.4.1/lib/ruby/site_ruby/3.4.0/rubygems/specification.rb:1389:in 'Gem::Specification#activate' from /Users/deivid/.asdf/installs/ruby/3.4.1/lib/ruby/site_ruby/3.4.0/rubygems.rb:283:in 'block in Gem.activate_bin_path' from /Users/deivid/.asdf/installs/ruby/3.4.1/lib/ruby/site_ruby/3.4.0/rubygems.rb:282:in 'Thread::Mutex#synchronize' from /Users/deivid/.asdf/installs/ruby/3.4.1/lib/ruby/site_ruby/3.4.0/rubygems.rb:282:in 'Gem.activate_bin_path' from /Users/deivid/.asdf/installs/ruby/3.4.1/bin/rails:25:in '<main>' ``` And also, we reduce exception based control flow in our code. https://github.com/rubygems/rubygems/commit/7e48c49f2d
2025-01-16[rubygems/rubygems] fix `@licenses` array unmarshallingMichael Rykov
https://github.com/rubygems/rubygems/commit/12f3e78c95
2024-12-24Merge RubyGems-3.6.2 and Bundler-2.6.2David Rodríguez
Notes: Merged: https://github.com/ruby/ruby/pull/12444
2024-12-06[rubygems/rubygems] Skip unresolved deps warning on ↵David Rodríguez
`Gem::Specification.reset` on benign cases If `Gem::Specification.reset` is used, but there are still unresolved dependencies, RubyGems prints a warning. There are though, certain cases where the situation will not cause any issues. One such case is when the unresolved dependency does not restrict any versions (>= 0) and there's a default gem matching it. In this situation, it doesn't matter if Gem paths change, because default gems are still activatable, so the dependency will be properly activated if ever needed. https://github.com/rubygems/rubygems/commit/e5f8a3068e
2024-11-26[rubygems/rubygems] More aggressive `Performance/FlatMap` cop configurationDavid Rodríguez
https://github.com/rubygems/rubygems/commit/d8d68cc00e
2024-11-06[rubygems/rubygems] Fix manifest in gem package using incorrect platform ↵David Rodríguez
sometimes If a gem package is built from a specification whose platform has been modified, it will include metadata using the old platform. This change should fix the problem by making sure `original_platform` is always properly set. https://github.com/rubygems/rubygems/commit/ecd5cd4547
2024-10-16[rubygems/rubygems] Add missing comma in documentationLeo Arnold
https://github.com/rubygems/rubygems/commit/fe9999f2cf
2024-10-09[rubygems/rubygems] Add `Gem::Specification#gem_dir` backDavid Rodríguez
If old Bundler versions that unconditionally try to remove this method are run with RubyGems versions _without_ this method, Bundler crashes because it tries to remove a method that does not exist. We need to wait until RubyGems cannot install any Bundler versions that unconditionally remove this method. https://github.com/rubygems/rubygems/commit/98804d261d
2024-10-09[rubygems/rubygems] Fix `Gem::Specification#gem_dir` losing custom source ↵David Rodríguez
for some reason https://github.com/rubygems/rubygems/commit/f8f589b1b8
2024-09-30[rubygems/rubygems] Don't add duplicated specs to unresolved specsDavid Rodríguez
This could happen when a regular gem shadows a default gem. https://github.com/rubygems/rubygems/commit/9ef70dd1f7
2024-09-30[rubygems/rubygems] Don't list duplicated version in ↵David Rodríguez
`Gem::Specification.reset` warning https://github.com/rubygems/rubygems/commit/e6e3db821f
2024-09-20[rubygems/rubygems] Unconditionally set installed_by_versionSamuel Giddins
It has been supported since RubyGems 2.2.0 via https://github.com/rubygems/rubygems/commit/4525e45a4d45 Signed-off-by: Samuel Giddins <segiddins@segiddins.me> https://github.com/rubygems/rubygems/commit/bf39c583e8
2024-09-18[rubygems/rubygems] Add a note about when hack can be removedDavid Rodríguez
https://github.com/rubygems/rubygems/commit/058b29fe98
2024-09-18[rubygems/rubygems] Stop fighting with ourselvesDavid Rodríguez
https://github.com/rubygems/rubygems/commit/7cf2fdcfa1
2024-08-31[rubygems/rubygems] fix `@license` typo preventing licenses from being ↵Durable Programming Team
correctly unmarshalled https://github.com/rubygems/rubygems/commit/d6ba7ef79f
2024-07-18[rubygems/rubygems] Fix gemspec `require_paths` type validationDavid Rodríguez
It was not properly being detected as an Array attribute, and thus not properly validated. Fixing this allows us to remove a strange `rescue` clause in Bundler. https://github.com/rubygems/rubygems/commit/4121a32408
2024-07-18[rubygems/rubygems] Use `caller_locations` instead of splitting `caller`Nobuyoshi Nakada
Also limit caller ranges https://github.com/rubygems/rubygems/commit/a274b1af78
2024-07-02[rubygems/rubygems] Feature add_dependency more prominentlyJerome Dalbert
https://github.com/rubygems/rubygems/commit/0236cb6191
2024-06-25[rubygems/rubygems] Add Specification#validate_for_resolutionThomas Marshall
This method validates only what is required for resolution, skipping any irrelevant metadata validation. This will be used by Bundler instead of doing a full validation, allowing gem authors to use `bundle` commands immediately in newly created gems without first having to fix invalid metafata fields in the default gemspec. https://github.com/rubygems/rubygems/commit/da7704cfc0
2024-06-13[rubygems/rubygems] Also disambiguate gems not in the first Gem.path positionDavid Rodríguez
https://github.com/rubygems/rubygems/commit/7e6e7ccc58
2024-06-13[rubygems/rubygems] Fix default gem priority when sorting specsDavid Rodríguez
https://github.com/rubygems/rubygems/commit/8dbe1dbdc7 Co-authored-by: MSP-Greg <Greg.mpls@gmail.com>
2024-05-31[rubygems/rubygems] Make stub sorting stableDavid Rodríguez
https://github.com/rubygems/rubygems/commit/6b70e9043d
2024-05-16[rubygems/rubygems] Fix binstubs sometimes not getting regenerated when ↵David Rodriguez
`--destdir` is given This was only working for gems also installed in the default gem home. https://github.com/rubygems/rubygems/commit/47df02dbd9
2024-05-16[rubygems/rubygems] Refactor `Gem::Specification#find_all_by_name`David Rodriguez
So that it can also be delegated to `Gem::SpecificationRecord`. https://github.com/rubygems/rubygems/commit/1407807a99
2024-05-14[rubygems/rubygems] Fix issue when cleaning up plugin stubsDavid Rodriguez
When `gem uninstall <gem> --install-dir <dir>` is run, if the version removed had a plugin, and that same version happened to also be installed globally, then the plugin stub would fail to be removed. https://github.com/rubygems/rubygems/commit/4e2fa0be77
2024-05-14[rubygems/rubygems] Extract a `Gem::SpecificationRecord` classDavid Rodriguez
This class handles all logic to handle the list of specifications, given a set of GEM_PATH directories. Makes `Gem::Specification` has less responsibilities and will help with fixing some bugs next. https://github.com/rubygems/rubygems/commit/df280dbbed
2024-05-14[rubygems/rubygems] Add missing docsDavid Rodriguez
Other analog methods are documented, so document this one too. https://github.com/rubygems/rubygems/commit/76da34d44d
2024-05-14[rubygems/rubygems] Simplify documentationDavid Rodriguez
I don't think this method is any worse than others, let's only document what it does. https://github.com/rubygems/rubygems/commit/dec722187f
2024-05-14[rubygems/rubygems] Remove redundant receiversDavid Rodriguez
https://github.com/rubygems/rubygems/commit/7b71965a70
2024-05-03[rubygems/rubygems] Remove `Gem::Specification#mark_version`David Rodriguez
This gets in the middle if we ever start allowing to build as if using a different RubyGems version than the one being run. This could be useful to make `gem rebuild` a little more usable, and it's already done by Bundler specs which already make this method a noop when they need this. I'm not sure forcefully setting this, even if user explicitly specified something else is helpful. Since this could potentially prevent gems explicitly setting a constant RubyGems version from building, I changed the error of incorrect RubyGems version from a hard error to a warning, since it will start happening in those cases if we stop overwriting the version. https://github.com/rubygems/rubygems/commit/45676af80d
2024-02-21[rubygems/rubygems] Skip nil-value keys to make metadata reproducibleNobuyoshi Nakada
Nil-value keys in a mapping end with a space or not depending on libyaml versions, and result metadata are different per platforms. This commit makes to skip such keys to make metadata reproducible accross platforms. https://github.com/rubygems/rubygems/commit/74b4db8d30
2024-02-21[rubygems/rubygems] Use https instead of httpHiroshi SHIBATA
https://github.com/rubygems/rubygems/commit/bcbe6f7b7a
2024-02-02[rubygems/rubygems] feat: Gem::Specification#initialize_copy deep-copies ↵Mike Dalessio
requirements to avoid accidentally mutating the original's state when doing: ```ruby spec2 = spec.dup spec2.required_rubygems_version.concat([">= 3.3.22"]) ``` see https://github.com/rake-compiler/rake-compiler/pull/236 for a real-world use case that would be made simpler with this behavior. https://github.com/rubygems/rubygems/commit/c1d52389f0
2024-01-18[rubygems/rubygems] Drop two TODOs from specification.rbOlle Jonsson
These were introduced 13 years ago, in a documentation update. Perhaps we can let the TODOs go, without taking any action? https://github.com/rubygems/rubygems/commit/fb23fa84f9
2024-01-11[rubygems/rubygems] Update documentation to use squiggly heredocBrave Hager
https://github.com/rubygems/rubygems/commit/4691b959ad
2023-12-12[rubygems/rubygems] Remove non-transparent requirement added to prerelease gemsDavid Rodríguez
I think we can safely assume these days that all RubyGems and Bundler versions that will ever bundle a new gem created in 2023 support prereleases. So this non transparent requirement is not necessary. In my opinion, it should be the gem author to explicitly add this constraint, not RubyGems. https://github.com/rubygems/rubygems/commit/b165e6d725
2023-12-07[rubygems/rubygems] Use modern hashes consistentlyDavid Rodríguez
https://github.com/rubygems/rubygems/commit/bb66253f2c
2023-11-13[rubygems/rubygems] Remove now unnecessary dupsDavid Rodríguez
https://github.com/rubygems/rubygems/commit/56ce2a6445
2023-11-13[rubygems/rubygems] Let RuboCop target Ruby 3.0David Rodríguez
https://github.com/rubygems/rubygems/commit/70243b1d72