rpm-software-management / spec-cleaner

spec-cleaner
BSD 3-Clause "New" or "Revised" License
28 stars 34 forks source link

Breaks order of macro evaluation with %version reference #239

Open Vogtinator opened 6 years ago

Vogtinator commented 6 years ago

%version is only defined after Version: in the .spec file, which means in combination with %global the order is important.

Name:           asdf
Version:        1.0.5
Release:        0
# Full Plasma 5 version (e.g. 5.8.95)
%{!?_plasma5_bugfix: %global _plasma5_bugfix %{version}}
# Lasted ABI-stable Plasma (e.g. 5.8 in KF5, but 5.8.95 in KUF)
%{!?_plasma5_version: %global _plasma5_version %(echo %{_plasma5_bugfix} | awk -F. '{print $1"."$2}')}
Summary:        asdf
License:        none
Requires:       foo = %{_plasma5_version}
%description
none

evaluates to Requires: foo = 1.0.

spec-cleaner converts this to

# Full Plasma 5 version (e.g. 5.8.95)
%{!?_plasma5_bugfix: %global _plasma5_bugfix %{version}}
# Lasted ABI-stable Plasma (e.g. 5.8 in KF5, but 5.8.95 in KUF)
%{!?_plasma5_version: %global _plasma5_version %(echo %{_plasma5_bugfix} | awk -F. '{print $1"."$2}')}
Name:           asdf
Version:        1.0.5
Release:        0
Summary:        asdf
License:        none
Requires:       foo = %{_plasma5_version}
%description
none

which evaluates to Requires: foo = 1.0.5. as %version is only available after the %global expansion.

As a workaround, we switched to %define for the time being, but this results in evaluating the command once per macro expansion.

scarabeusiv commented 6 years ago

hmm globals with awk are not a really good idea for once.

But yea it should play it safe... Any ideas how to achieve that?

Vogtinator commented 6 years ago

hmm globals with awk are not a really good idea for once.

Feel free to come up with a better idea which doesn't involve lua...

But yea it should play it safe... Any ideas how to achieve that?

Is there already some kind of variable definition order tracking implemented? If not, it might be a bit difficult indeed... Maybe it could try to keep %global at the same position?

scarabeusiv commented 6 years ago

No evaluation and tracking in the code yet. Well the globals idea was that they should be used only for when they are not depending on external resources as otherwise it "just works" thanks to the command order, while all other expansions are parsed fully first and then expressed.

Conan-Kudo commented 4 years ago

@Vogtinator Two choices:

  1. Use %define so that it does lazy evaluation
  2. Use %{expand:%{version}} instead, so that block is forced to lazy evaluation
mlschroe commented 4 years ago

%{expand:%{version}} will not help. %expand is not about lazy evaluation, but instead it does a re-expansion. This re-expansion happens right away, though.