#389 Make percentage signs escaping work with RPM 4.19 as well
Merged a year ago by churchyard. Opened a year ago by churchyard.
rpms/ churchyard/pyproject-rpm-macros rpm4.19  into  rawhide

file modified
+7
@@ -104,7 +104,14 @@ 

  %pyproject_extras_subpkg(n:i:f:F) %{expand:%{?python_extras_subpkg:%{python_extras_subpkg%{?!-i:%{?!-f:%{?!-F: -f %{_pyproject_ghost_distinfo}}}} %**}}}

  

  

+ # Escaping an actual percentage sign in path by 8 signs has been verified in RPM 4.16 and 4.17.

+ # See this thread http://lists.rpm.org/pipermail/rpm-list/2021-June/002048.html

+ # Since RPM 4.19, 2 signs are needed instead.

+ # On the CI, we build tests/escape_percentages.spec to verify the assumptions.

+ # We should check RPM version here instead of Fedora/RHEL, but it's hard;

+ # see https://github.com/rpm-software-management/rpm/issues/2523

  %pyproject_save_files() %{expand:\\\

+ %{expr:0%{?fedora} >= 39 || 0%{?rhel} >= 10 ? "RPM_PERCENTAGES_COUNT=2" : "RPM_PERCENTAGES_COUNT=8" } \\

  %{__python3} %{_rpmconfigdir}/redhat/pyproject_save_files.py \\

    --output-files "%{pyproject_files}" \\

    --output-modules "%{_pyproject_modules}" \\

@@ -163,6 +163,7 @@ 

  %changelog

  * Wed May 31 2023 Miro Hrončok <mhroncok@redhat.com> - 1.8.1-1

  - On Python older than 3.11, use tomli instead of deprecated toml

+ - Fix literal %% handling in %%{pyproject_files} on RPM 4.19

  

  * Tue May 23 2023 Miro Hrončok <mhroncok@redhat.com> - 1.8.0-2

  - Rebuilt for ELN dependency changes

file modified
+7 -7
@@ -12,6 +12,9 @@ 

  # From RPM's build/files.c strtokWithQuotes delim argument

  RPM_FILES_DELIMETERS = ' \n\t'

  

+ # See the comment in the macro that wraps this script

+ RPM_PERCENTAGES_COUNT = int(os.getenv('RPM_PERCENTAGES_COUNT', '2'))

+ 

  # RPM hardcodes the lists of manpage extensions and directories,

  # so we have to maintain separate ones :(

  # There is an issue for RPM to provide the lists as macros:
@@ -441,13 +444,13 @@ 

          '"/usr/lib/python3.9/site-packages/setuptools/script (dev).tmpl"'

  

          >>> escape_rpm_path('/usr/share/data/100%valid.path')

-         '/usr/share/data/100%%%%%%%%valid.path'

+         '/usr/share/data/100%%valid.path'

  

          >>> escape_rpm_path('/usr/share/data/100 % valid.path')

-         '"/usr/share/data/100 %%%%%%%% valid.path"'

+         '"/usr/share/data/100 %% valid.path"'

  

          >>> escape_rpm_path('/usr/share/data/1000 %% valid.path')

-         '"/usr/share/data/1000 %%%%%%%%%%%%%%%% valid.path"'

+         '"/usr/share/data/1000 %%%% valid.path"'

  

          >>> escape_rpm_path('/usr/share/data/spaces and "quotes"')

          Traceback (most recent call last):
@@ -461,10 +464,7 @@ 

      """

      orig_path = path = str(path)

      if "%" in path:

-         # Escaping by 8 %s has been verified in RPM 4.16 and 4.17, but probably not stable

-         # See this thread http://lists.rpm.org/pipermail/rpm-list/2021-June/002048.html

-         # On the CI, we build tests/escape_percentages.spec to verify this assumption

-         path = path.replace("%", "%" * 8)

+         path = path.replace("%", "%" * RPM_PERCENTAGES_COUNT)

      if any(symbol in path for symbol in RPM_FILES_DELIMETERS):

          if '"' in path:

              # As far as we know, RPM cannot list such file individually

file modified
+48 -8
@@ -1,5 +1,5 @@ 

  Name:           escape_percentages

- Version:        0

+ Version:        0.1

  Release:        0

  Summary:        ...

  License:        MIT
@@ -7,19 +7,59 @@ 

  

  %description

  This spec file verifies that escaping percentage signs in paths is possible via

- exactly 8 percentage signs in a filelist and directly in the %%files section.

+ exactly 2 (or 8) percentage signs in a filelist and directly in the %%files section.

  It serves as a regression test for pyproject_save_files:escape_rpm_path().

  When this breaks, the function needs to be adapted.

  

- %install

+ 

+ %prep

+ cat > pyproject.toml << EOF

+ [build-system]

+ requires = ["setuptools"]

+ build-backend = "setuptools.build_meta"

+ EOF

+ 

+ cat > setup.cfg << EOF

+ [metadata]

+ name = escape_percentages

+ version = 0.1

+ [options]

+ packages =

+     escape_percentages

+ [options.package_data]

+ escape_percentages =

+     *

+ EOF

+ 

+ mkdir -p escape_percentages

+ touch escape_percentages/__init__.py

  # the paths on disk will have 1 percentage sign if we type 2 in the spec

  # we use the word 'version' after the sign, as that is a known existing macro

- touch '%{buildroot}/one%%version'

+ touch 'escape_percentages/one%%version'

+ 

+ 

+ %generate_buildrequires

+ %pyproject_buildrequires

+ 

+ 

+ %build

+ %pyproject_wheel

+ 

+ 

+ %install

+ %pyproject_install

+ %pyproject_save_files escape_percentages

  touch '%{buildroot}/two%%version'

  

- # the filelist will contain 8 percentage signs when we type 16 in spec

- echo '/one%%%%%%%%%%%%%%%%version' > filelist

- test $(wc -c filelist | cut -f1 -d' ') -eq 20  # 8 signs + /one (4) + version (7) + newline (1)

  

- %files -f filelist

+ %check

+ grep '/escape_percentages/one' %{pyproject_files}

+ 

+ 

+ 

+ %files -f %{pyproject_files}

+ %if 0%{?fedora} >= 39 || 0%{?rhel} >= 10

+ /two%%version

+ %else

  /two%%%%%%%%version

+ %endif

file modified
+1 -1
@@ -93,7 +93,7 @@ 

          run: ./mocktest.sh python-virtualenv

      - escape_percentages:

          dir: .

-         run: rpmbuild -ba escape_percentages.spec

+         run: ./mocktest.sh escape_percentages

      required_packages:

      - mock

      - rpmdevtools

This is now intentionally rebased on top of https://src.fedoraproject.org/rpms/pyproject-rpm-macros/pull-request/388 so it is possible to merge this right after that one.

Build succeeded.
https://fedora.softwarefactory-project.io/zuul/buildset/030f1f919fb94dc0865e28c55280a806

rebased onto 33f002bace4a7aa9668a94b71be86b03c45db98e

a year ago

Build succeeded.
https://fedora.softwarefactory-project.io/zuul/buildset/87815a70d06042c0aa6600f69c085c3b

I really don't like checking for Fedora/RHEL, but I guess shelling out to rpm --version is worse.

Shelling out to rpm --version requires parsing the output, which is quite horrible.

We could check the presence of %__systemd_sysusers, %_langpack_template or %add_sysuser but that seems like a hack.

Shelling out to rpm --version requires parsing the output, which is quite horrible.

%(rpm --version | cut -d" " -f3) works since at least CentOS 7, but as the project maintainer, you get to choose which type of hack you prefer (not) to maintain :). That output is stable until it's not...


Looking at the actual code...

RPM_PERENTAGES_COUNT = os.getenv('RPM_PERENTAGES_COUNT') or 2

os.getenv('RPM_PERENTAGES_COUNT') will return a string. That needs to be converted to an int.

I'd write this as

RPM_PERENTAGES_COUNT = int(os.getenv('RPM_PERENTAGES_COUNT', '2'))

The commit body could perhaps use a sentence of context.


%{expr:0%{?fedora} >= 39 || 0%{?rhel} >= 10 ? "RPM_PERENTAGES_COUNT=2" : "RPM_PERENTAGES_COUNT=8" } \\

Is there a reason you used %{expr:} instead of %[]? Based on my understanding of the rpm docs [1], the latter is preferred.

[1] https://rpm-software-management.github.io/rpm/manual/macros.html#expression-expansion

I'm using %{expr:} instead of %[] as it generally seems more stable, see e.g. https://github.com/rpm-software-management/rpm/issues/2354

Good catch with the int thing. I wonder why the CI passed...

I wonder why the CI passed...

Because neither of our spec files actually uses this code. I'll rework escape_percentages to do it.

1 new commit added

  • fixup! Make percentage signs escaping work with RPM 4.19 as well
a year ago

1 new commit added

  • Rework the escape_percentages.spec to actually run our code as well
a year ago

1 new commit added

  • fixup: don't render the comment in the parsed specfile
a year ago

1 new commit added

  • typo
a year ago

Build failed. More information on how to proceed and troubleshoot errors available at https://fedoraproject.org/wiki/Zuul-based-ci
https://fedora.softwarefactory-project.io/zuul/buildset/d5d575b616ee421a997190a1e9552dc1

rebased onto d372624a24abc63ef55cf50f2e9762df848340a0

a year ago

rebased onto 02cd9a317bc5a4037c87b74c92be79f210fbdddc

a year ago

Build succeeded.
https://fedora.softwarefactory-project.io/zuul/buildset/df38499671134b3db70f2a00e853f1bf

rebased onto 5ab7319

a year ago

rebased onto 31606d1eae0c34e5a46d4349a6000b8fbe9fc1b2

a year ago

rebased onto 5ab7319

a year ago

Build succeeded.
https://fedora.softwarefactory-project.io/zuul/buildset/57d7a2e18f954009bb0af44674dd2f7e

rebased onto 638ba27

a year ago

Pull-Request has been merged by churchyard

a year ago

Build succeeded.
https://fedora.softwarefactory-project.io/zuul/buildset/f37aff36b8c44eea830d6bf6be804b4f