fedora-ruby / gem2rpm

Generate an rpm from a rubygem
Other
78 stars 45 forks source link

2 empty lines geneated in a template #104

Open junaruga opened 3 years ago

junaruga commented 3 years ago

The current gem2rpm creates 2 empty lines between cp -a and mkdir -p for a generated spec file.

As a result on the following PR line 13, the 2 lines is changed to 1 line. https://src.fedoraproject.org/rpms/rubygem-rack/pull-request/3#request_diff

1 empty line is better for the template than 2 empty lines, isn't it?

Here is the log for rubygem-rack.

$ which gem2rpm
/usr/bin/gem2rpm

$ rpm -qf /usr/bin/gem2rpm
rubygem-gem2rpm-1.0.1-6.fc33.noarch

$ gem2rpm rack-2.2.3.gem > rubygem-rack.spec.new

$ cat rubygem-rack.spec.new
...
%install
mkdir -p %{buildroot}%{gem_dir}
cp -a .%{gem_dir}/* \
        %{buildroot}%{gem_dir}/

mkdir -p %{buildroot}%{_bindir}
cp -a .%{_bindir}/* \
        %{buildroot}%{_bindir}/
...
voxik commented 3 years ago
  1. I don't personally mind the spaces. Admittedly, in this specific case, it would be probably better if they are gone.
  2. I am afraid this is not as easy to solve. If you check the template, there are not additional empty lines spaces: https://github.com/fedora-ruby/gem2rpm/blob/4783f1b4a9ce800bed95531082d4a0f27ae665eb/templates/fedora-27-rawhide.spec.erb#L56-L74 The problem is that the template tags are expanded into empty lines and AFAIK, using ERB, there is no way to get easily rid of them. In theory they could be remove for the price of worse template readability, what is not win either.
pvalena commented 3 years ago

You're right, if we stick to this formatting.

The lines 60 and 70 are responsible for the double space. Could be resolved by writing it like so. f.e.:

mkdir -p %{buildroot}%{gem_dir}
cp -a .%{gem_dir}/* \
        %{buildroot}%{gem_dir}/
<%
unless spec.extensions.empty? -%>

Or any other adjustment which changes one of those empty lines to either end with -%> or start with <%.

junaruga commented 3 years ago

The problem is that the template tags are expanded into empty lines and AFAIK, using ERB, there is no way to get easily rid of them. In theory they could be remove for the price of worse template readability, what is not win either.

I do not think so. You can see https://puppet.com/docs/puppet/5.5/lang_template_erb.html . -%> trims 1 line break after -%>. I see the reason is simply how to write the template is not correct. I sent a PR.

-%> — If the tag ends a line, trim the following line break.