#99 Enhance rubygems macro
Opened 2 years ago by pvalena. Modified 2 years ago
rpms/ pvalena/ruby macros  into  rawhide

file modified
+1
@@ -63,6 +63,7 @@ 

    \

    dep = spec.dependencies.detect { |d| d.type == type && d.name == name } \

    if dep \

+     abort("Can't add #{name} dependency without explicitly defined requirements; gemspec entry already exists") unless requirements \

      dep.requirement.concat requirements \

    else \

      spec.public_send "add_#{type}_dependency", name, requirements \

file modified
+4 -1
@@ -1374,7 +1374,10 @@ 

  

  

  %changelog

- * Tue Sep 14 2021 Sahana Prasad <sahana@redhat.com>

+ * Thu Sep 16 2021 Pavel Valena <pvalena@redhat.com> - 3.0.2-153

+ - Enhance rubygems macro error message

+ 

+ * Tue Sep 14 2021 Sahana Prasad <sahana@redhat.com> - 3.0.2-153

  - Rebuilt with OpenSSL 3.0.0

  

  * Tue Aug 24 2021 Vít Ondruch <vondruch@redhat.com> - 3.0.2-152

to fail on duplicate dependency without defined requirements.

rebased onto 221074da28688b5c705a78771d7615dbc6dd7fdc

2 years ago

Build failed. More information on how to proceed and troubleshoot errors available at https://fedoraproject.org/wiki/Zuul-based-ci

In my understanding, the dep object is selected by the type (runtime or development) and the gem name.

dep = spec.dependencies.detect { |d| d.type == type && d.name == name }

Regarding to the abort message, I am not sure why we can say the dep object is always "the the dependency without defined requirements". If a dependency has requirement such as ['>= 3.0', '< 5'] in the gemspec file, it looks the message is still printed, right? The requirements in unless requirements is about the macro's argument, right?

In my understanding, the dep object is selected by the type (runtime or development) and the gem name.

Yes, that's the dependency, which is to be modified (addition in this case).

One of the modification parameters (arument) are requirements, which may or may not be specified.

  requirements = %{*}%{!?1:nil} \

Regarding to the abort message, I am not sure why we can say the dep object is always "the the dependency without defined requirements".

unless requirements means if requirements.nil?

IOW no requirements are specified in such a case, but the dependency was already found (it is in gemspec). The operation does not make sense (possible NOOP), and therefore an error is thrown instead.

If a dependency has requirement such as ['>= 3.0', '< 5'] in the gemspec file, it looks the message is still printed, right? The requirements in unless requirements is about the macro's argument, right?

That is not true:

irb(main):001:0> requirements = ['>= 3.0', '< 5']
=> [">= 3.0", "< 5"]
irb(main):002:0> abort('#{name} dependency without explicitly defined requirements already exists') unless requirements
=> nil
irb(main):003:0> # No error

Whether the gemspec entry, which was found (dep) already has or does not have any requirement defined is not relevant in this case.

rebased onto 4ca0f34114aad89931fa5198f2323068e2240c4a

2 years ago

Build failed. More information on how to proceed and troubleshoot errors available at https://fedoraproject.org/wiki/Zuul-based-ci

Build failed. More information on how to proceed and troubleshoot errors available at https://fedoraproject.org/wiki/Zuul-based-ci

That is not true:

Sorry I haven't read all the message from you yet. I know the meaning of unless. That's not the point.

But for example for the following files,

rack.gemspec

Gem::Specification.new do |s|
  ...
  s.add_development_dependency 'minitest', "~> 5.0"
  ...
end

rack.spec

gemspec_add_dep -g minitest -s /path/to/rack.spec -d

The abort is executed as printing the message "minitest dependency without explicitly defined requirements already exists"?

rebased onto 00a2ca6

2 years ago

That is not true:

Sorry I haven't read all the message from you yet. I know the meaning of unless. That's not the point.

But for example for the following files,

rack.gemspec

Gem::Specification.new do |s| ... s.add_development_dependency 'minitest', "~> 5.0" ... end

Note: the gemspec entry itself is irrelevant (other than it exists).

rack.spec

gemspec_add_dep -g minitest -s /path/to/rack.spec -d

The abort is executed as printing the message "minitest dependency without explicitly defined requirements already exists"?

Oh, I should've read the error message once more, as it was malformed.
Maybe this is more explanative?

Error: Can't add #{name} dependency without explicitly defined requirements; gemspec entry already exists.

Build failed. More information on how to proceed and troubleshoot errors available at https://fedoraproject.org/wiki/Zuul-based-ci

Metadata