Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't let macro '%-x' add extra space between flag and argument #2455

Closed

Conversation

rhabacker
Copy link
Contributor

@rhabacker rhabacker commented Mar 24, 2023

Fixes #2454, depends on #2449 (the commits from #2449 are included to avoid breaking CI)

@rhabacker
Copy link
Contributor Author

This pull request required several push forces because the master branch of rpm on openSUSE 15.4 could not be built due to the missing package rpm-sequoia. The patch was therefore developed on rpm-4.14.x and ported to the master branch.

@pmatilai
Copy link
Member

FWIW, you can build without rpm-sequoia by supplying -DWITH_INTERNAL_OPENPGP=ON to cmake.

@pmatilai
Copy link
Member

We have no idea how many macros and packages out there are relying on the current, very long standing behavior. This may fix a use-case for you but is likely to break it for several others.

@rhabacker
Copy link
Contributor Author

rhabacker commented Mar 30, 2023

FWIW, you can build without rpm-sequoia by supplying -DWITH_INTERNAL_OPENPGP=ON to cmake.

Thanks for this pointer, which I can confirm that it works

To run the generated rpmbuild it looks to be required to install the build and use environment variable RPM_CONFIGDIR and LD_LIBRARY_PATH e.g.

cd ~
git clone https://github.com/rpm-software-management/rpm.git
cmake -S rpm -B rpm-build
cmake --build rpm-build
cmake --build rpm-build --target install DESTDIR=$PWD/rpm-install
RPM_CONFIGDIR=$PWD/rpm-install/usr/local/lib/rpm \
    LD_LIBRARY_PATH=$PWD/rpm-install/usr/local/lib64 \
    $PWD/rpm-install/usr/local/bin/rpmbuild --define='%foo(b:B:) %{-b}' --eval '%foo -b2 -b a=2 -B4 dsfdfdf'
-b a=2

@rhabacker
Copy link
Contributor Author

We have no idea how many macros and packages out there are relying on the current, very long standing behavior. This may fix a use-case for you but is likely to break it for several others.

On openSUSE Leap 15.4 I found the following locations where such a flag is used:

 grep -rn "%{-[a-zA-Z]}" /usr/lib/rpm
/usr/lib/rpm/macros:1403:%{__hg} init %{-q} .\
/usr/lib/rpm/macros:1404:%{__hg} add %{-q} .\
/usr/lib/rpm/macros:1405:%{__hg} commit %{-q} --user "%{__scm_author}" -m "%{NAME}-%{VERSION} base"
/usr/lib/rpm/macros:1408:%{__hg} import - %{-p:-p%{-p*}} %{-q} -m %{-m*} --user "%{__scm_author}"
/usr/lib/rpm/macros:1412:%{__git} init %{-q}\
/usr/lib/rpm/macros:1416:%{__git} commit %{-q} --allow-empty -a\\\
/usr/lib/rpm/macros:1421:%{__git} commit %{-q} -m %{-m*} --author "%{__scm_author}"
/usr/lib/rpm/macros:1425:%{expand:%__scm_setup_git %{-q}}
/usr/lib/rpm/macros:1428:%{__git} am %{-q} %{-p:-p%{-p*}}
/usr/lib/rpm/macros:1433:%{__quilt} import %{-p:-p%{-p*}} %{1} && %{__quilt} push %{-q}
/usr/lib/rpm/macros:1437:%{__bzr} init %{-q}\
/usr/lib/rpm/macros:1440:%{__bzr} commit %{-q} -m "%{NAME}-%{VERSION} base"
/usr/lib/rpm/macros:1445:%{__bzr} commit %{-q} -m %{-m*}
/usr/lib/rpm/macros:1453:    local options = rpm.expand("%{-q} %{-p:-p%{-p*}} %{-m:-m%{-m*}}")\
/usr/lib/rpm/macros:1474:%setup %{-a} %{-b} %{-c} %{-D} %{-n} %{-T} %{!-v:-q}\
/usr/lib/rpm/macros:1477:%{!-N:%autopatch %{-v} %{-p:-p%{-p*}}}
/usr/lib/rpm/macros.d/macros.kernel-source:61:          [ -n "%{-X}" ] && continue ;; \
/usr/lib/rpm/macros.d/macros.kernel-source:63:          [ -z "%{-X}" -a -n "$flavors" ] && continue ;; \
/usr/lib/rpm/macros.d/macros.kernel-source:68:      echo "%%_suse_kernel_module_subpackage -n %{-n*}%{!-n:%name} -v %{-v*}%{!-v:%version} -r %{-r*}%{!-r:%release} %{-f} %{-p} %{-b} %{-c:-c} $flavor $kver" \
/usr/lib/rpm/macros.d/macros.kernel-source:93:  %{expand:%%_kernel_module_package %{-x:-X} %{-n} %{-v} %{-r} %{-t} %{-f} %{-p} %{-b} %{-c} %*}
/usr/lib/rpm/macros.d/macros.kernel-source:98:  %{expand:%%_kernel_module_package %{-x: }%{!-x:-X} %{-n} %{-v} %{-r} %{-s:-t %{-s*}} %{-f} %{-p} %{-b} %{-c} %*}

@rhabacker
Copy link
Contributor Author

This may fix a use-case for you but is likely to break it for several others.

A number of conditions are required for this to cause a problem:

  1. in the parameter list of a macro x:must be specified.
  2. %-x is used in the macro in question
  3. the calling program supports only -x<value> and -x <value> is passed and vice versa.

In the following examples from the list given:

/usr/lib/rpm/macros:1407:%__scm_apply_hg(qp:m:)
/usr/lib/rpm/macros:1408:%{__hg} import - %{-p:-p%{-p*}} %{-q} -m %{-m*} --user "%{__scm_author}"

This post already contains a workaround for the mentioned problem, as git am requires the same syntax as the patch command with -p<n>. Only the value of %-p is used and is thus independent of the passing form.

/usr/lib/rpm/macros:1427:%__scm_apply_git_am(qp:m:)
/usr/lib/rpm/macros:1428:%{__git} am %{-q} %{-p:-p%{-p*}}

This occurrence is also a workaround for the problem mentioned, since git am requires -p<n>. Only the value of %-p is used and is thus independent of the passing form.

/usr/lib/rpm/macros:1433:%{__quilt} import %{-p:-p%{-p*}} %{1} && %{__quilt} push %{-q}

According to https://linux.die.net/man/1/quilt the format is -p <n>, but the listed location uses -p<n>, so it must work, otherwise it would already be reported as a problem. Only the value of %-p is used and is thus independent of the passing format.

/usr/lib/rpm/macros:1453: local options = rpm.expand("%{-q} %{-p:-p%{-p*}} %{-m:-m%{-m*}}")\

Only the value of %-p is used and is thus independent of the passing form.

@pmatilai
Copy link
Member

pmatilai commented Nov 2, 2023

As per the ticket conclusion, sorry but NAK: #2454

Apologies for taking so long with this.

@pmatilai pmatilai closed this Nov 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Macro %-x modifies original flag if argument follows without intervening space
2 participants