Dne 15.9.2016 v 20:12 Pavel Valena napsal(a):
----- Original Message -----
> From: "Vít Ondruch" <vondruch(a)redhat.com>
> To: ruby-sig(a)lists.fedoraproject.org
> Sent: Thursday, September 15, 2016 2:00:59 PM
> Subject: Re: Macros to modify gem dependencies
>
>
>
> Dne 15.9.2016 v 10:06 Vít Ondruch napsal(a):
>> BTW this is first draft of the macros. I am going to try second
>> implementation, which will probably need to use a bit different syntax
>> for macro calls, but it might replace the 3 lines usage example above
>> with 2 lines version:
>>
>>
>> ```
>>
>> %gemspec_remove_runtime_dependency -n fog-dynect
>> %gemspec_add_runtime_dependency -n fog-dynect ['~> 10.0', '>=
10.1']
>>
>> ```
The above gives me strange result in gemspec
```
s.add_runtime_dependency(%q<fog-dynect>, [">= 10.1", ">=
10.1", "~> 10.0"])
```
Unless you fixed "gemspec_remove_runtime_dependency" by yourself, it
does not support the -n parameter yet, hence the dependency is not
cleaned up prior adding new dependencies.
However,
```
%gemspec_add_dep -n fog-dynect '~> 10.0'
```
results in
```
s.add_dependency(%q<fog-dynect>, [">= 10.1", "~> 10.0"])
```
Which I consider correct for the first example.
Also, using the notation below does not produce expected result
```
%gemspec_remove_dep fog-dynect
%gemspec_add_dep -n fog-dynect '~> 10.0'
%gemspec_add_dep -n fog-dynect '>= 10.1'
```
=>
```
s.add_dependency(%q<fog-dynect>, ["~> 10.0"])
```
FTR, in case of the non-named-variable-macro version (without '-n') the result is
correct.
>>
> As I promised, this is implementation with the '-n' parameter:
>
> ```
> %define gemspec_add_runtime_dependency(n:) \
> read -d '' add_runtime_dependency_script << 'EOR' || : \
> name = '%{-n*}' \
> version = %{*} \
> spec = Gem::Specification.load('.%{gem_spec}') \
> dep = spec.dependencies.detect { |d| d.type == :runtime && d.name ==
> name } \
> if dep \
> dep.requirement.concat version \
> else \
> spec.add_runtime_dependency name, version \
> end \
> File.write '.%{gem_spec}', spec.to_ruby \
> EOR\
> echo "$add_runtime_dependency_script" | ruby \
> %{nil}
>
> ```
The above can be also written as
```
%define gemspec_add_dep(n:) \
echo ' \
name = %q<%{-n*}> \
version = %{*} \
spec = Gem::Specification.load(%q<.%{gem_spec}>) \
dep = spec.dependencies.detect { |d| d.type == :runtime && d.name == name } \
if dep \
dep.requirement.concat version \
else \
spec.add_runtime_dependency name, version \
end \
File.write %q<.%{gem_spec}>, spec.to_ruby \
' | ruby
%{nil}
```
Yes, you can write it like this, but you have to be careful about the
usage later, e.g. the example you have used above:
```
%gemspec_add_dep -n fog-dynect '~> 10.0'
```
is probably reason for the issues you have described. If checked the log
output correctly, you would see following output:
```
+ echo '
name = %q<fog-dynect>
version = ~'
/var/tmp/rpm-tmp.4CWGoP: line 71: 10.0
spec =
Gem::Specification.load(%q<./usr/share/gems/specifications/fog-1.38.0.gemspec>)
dep = spec.dependencies.detect { |d| d.type == :runtime && d.name ==
name }
if dep
dep.requirement.concat version
else
spec.add_runtime_dependency name, version
end
File.write %q<./usr/share/gems/specifications/fog-1.38.0.gemspec>,
spec.to_ruby
: No such file or directory
+ ruby
```
The correct usage for this would be:
```
%gemspec_add_dep -n fog-dynect "~> 10.0"
```
IOW please note the single vs double quotes ...
Vít