Repository: mesonbuild/meson

Issue:
fix(rpm): remove unnecessary index in loop
Discovered this error while attempting to build swaync

```
Traceback (most recent call last):
  File "/usr/lib/python3.10/site-packages/mesonbuild/mesonmain.py", line 228, in run
    return options.run_func(options)
  File "/usr/lib/python3.10/site-packages/mesonbuild/msetup.py", line 281, in run
    app.generate()
  File "/usr/lib/python3.10/site-packages/mesonbuild/msetup.py", line 184, in generate
    self._generate(env)
  File "/usr/lib/python3.10/site-packages/mesonbuild/msetup.py", line 223, in _generate
    intr.run()
  File "/usr/lib/python3.10/site-packages/mesonbuild/interpreter/interpreter.py", line 2476, in run
    super().run()
  File "/usr/lib/python3.10/site-packages/mesonbuild/interpreterbase/interpreterbase.py", line 132, in run
    self.evaluate_codeblock(self.ast, start=1)
  File "/usr/lib/python3.10/site-packages/mesonbuild/interpreterbase/interpreterbase.py", line 157, in evaluate_codeblock
    raise e
  File "/usr/lib/python3.10/site-packages/mesonbuild/interpreterbase/interpreterbase.py", line 150, in evaluate_codeblock
    self.evaluate_statement(cur)
  File "/usr/lib/python3.10/site-packages/mesonbuild/interpreterbase/interpreterbase.py", line 167, in evaluate_statement
    return self.method_call(cur)
  File "/usr/lib/python3.10/site-packages/mesonbuild/interpreterbase/interpreterbase.py", line 598, in method_call
    return self._holderify(obj.method_call(method_name, args, kwargs))
  File "/usr/lib/python3.10/site-packages/mesonbuild/interpreter/interpreterobjects.py", line 766, in method_call
    ret = method(state, args, kwargs)
  File "/usr/lib/python3.10/site-packages/mesonbuild/interpreterbase/decorators.py", line 55, in wrapped
    return f(*wrapped_args, **wrapped_kwargs)
  File "/usr/lib/python3.10/site-packages/mesonbuild/modules/rpm.py", line 93, in generate_spec_template
    fn.write('BuildRequires: pkgconfig(%s)\n' % dep[0])
TypeError: not all arguments converted during string formatting
```
looks like some time ago it was broken (when .host was added to .deps)


Discussion:
The rpm module periodically breaks for 3 years at a time and no one notices. :/

The only swaync I can find is https://github.com/ErikReider/SwayNotificationCenter and it doesn't use this module... how do I test the change?

> The rpm module periodically breaks for 3 years at a time and no one notices. :/
> 
> The only swaync I can find is https://github.com/ErikReider/SwayNotificationCenter and it doesn't use this module... how do I test the change?

Originally swaync not uses rpm module, I've manually added
```
rpm = import('rpm')
rpm.generate_spec_template()
```
to meson.build

This PR needs some more work, i've noticed that output pkgconfig format is invalid. I'll do it this weekend 
Ah yes, this will just pass a tuple and you end up with

```
BuildRequires: pkgconfig(('name', 'gio-2.0'))
BuildRequires: pkgconfig(('name', 'gtk+-3.0'))
BuildRequires: pkgconfig(('name', 'json-glib-1.0'))
BuildRequires: pkgconfig(('name', 'libhandy-1'))
BuildRequires: pkgconfig(('name', 'gtk-layer-shell-0'))
BuildRequires: pkgconfig(('name', 'bash-completion'))
BuildRequires: pkgconfig(('name', 'fish'))
```

It gets worse if you consider that some of those dependencies can have methods or modules specified, and may not actually be of type pkgconfig at all -- e.g. a custom dependency type in `mesonbuild/dependencies/*.py` can be of type `system` and do find_library lookups, or type `cmake` and run a dummy cmake project to search for the dependency, or be powered by `/usr/bin/foo-config`...

I am not even sure what the status of this module is. @ignatenkobrain, are you still maintaining it and verifying that it works and/or behaves as expected?
# [Codecov](https://codecov.io/gh/mesonbuild/meson/pull/9763?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) Report
> Merging [#9763](https://codecov.io/gh/mesonbuild/meson/pull/9763?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) (065f706) into [master](https://codecov.io/gh/mesonbuild/meson/commit/37b122b87e716f5a4e909db12a7793d162c599bb?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) (37b122b) will **increase** coverage by `0.55%`.
> The diff coverage is `0.00%`.

[![Impacted file tree graph](https://codecov.io/gh/mesonbuild/meson/pull/9763/graphs/tree.svg?width=650&height=150&src=pr&token=BplKwTJqLg&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None)](https://codecov.io/gh/mesonbuild/meson/pull/9763?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None)

```diff
@@            Coverage Diff             @@
##           master    #9763      +/-   ##
==========================================
+ Coverage   66.58%   67.14%   +0.55%     
==========================================
  Files         404      404              
  Lines       85773    85773              
  Branches    18919    18919              
==========================================
+ Hits        57115    57593     +478     
+ Misses      24113    23651     -462     
+ Partials     4545     4529      -16     
```


| [Impacted Files](https://codecov.io/gh/mesonbuild/meson/pull/9763?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) | Coverage Δ | |
|---|---|---|
| [mesonbuild/modules/rpm.py](https://codecov.io/gh/mesonbuild/meson/pull/9763/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None#diff-bWVzb25idWlsZC9tb2R1bGVzL3JwbS5weQ==) | `0.00% <0.00%> (ø)` | |
| [mesonbuild/scripts/vcstagger.py](https://codecov.io/gh/mesonbuild/meson/pull/9763/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None#diff-bWVzb25idWlsZC9zY3JpcHRzL3Zjc3RhZ2dlci5weQ==) | `87.50% <0.00%> (-4.17%)` | :arrow_down: |
| [mesonbuild/minstall.py](https://codecov.io/gh/mesonbuild/meson/pull/9763/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None#diff-bWVzb25idWlsZC9taW5zdGFsbC5weQ==) | `67.15% <0.00%> (-0.37%)` | :arrow_down: |
| [mesonbuild/dependencies/dev.py](https://codecov.io/gh/mesonbuild/meson/pull/9763/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None#diff-bWVzb25idWlsZC9kZXBlbmRlbmNpZXMvZGV2LnB5) | `67.16% <0.00%> (-0.30%)` | :arrow_down: |
| [mesonbuild/dependencies/base.py](https://codecov.io/gh/mesonbuild/meson/pull/9763/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None#diff-bWVzb25idWlsZC9kZXBlbmRlbmNpZXMvYmFzZS5weQ==) | `85.07% <0.00%> (-0.30%)` | :arrow_down: |
| [mesonbuild/interpreter/interpreter.py](https://codecov.io/gh/mesonbuild/meson/pull/9763/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None#diff-bWVzb25idWlsZC9pbnRlcnByZXRlci9pbnRlcnByZXRlci5weQ==) | `83.10% <0.00%> (+0.16%)` | :arrow_up: |
| [mesonbuild/cmake/interpreter.py](https://codecov.io/gh/mesonbuild/meson/pull/9763/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None#diff-bWVzb25idWlsZC9jbWFrZS9pbnRlcnByZXRlci5weQ==) | `83.35% <0.00%> (+0.22%)` | :arrow_up: |
| [mesonbuild/modules/gnome.py](https://codecov.io/gh/mesonbuild/meson/pull/9763/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None#diff-bWVzb25idWlsZC9tb2R1bGVzL2dub21lLnB5) | `77.72% <0.00%> (+0.29%)` | :arrow_up: |
| [mesonbuild/coredata.py](https://codecov.io/gh/mesonbuild/meson/pull/9763/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None#diff-bWVzb25idWlsZC9jb3JlZGF0YS5weQ==) | `83.74% <0.00%> (+0.36%)` | :arrow_up: |
| [mesonbuild/mesonlib/universal.py](https://codecov.io/gh/mesonbuild/meson/pull/9763/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None#diff-bWVzb25idWlsZC9tZXNvbmxpYi91bml2ZXJzYWwucHk=) | `81.37% <0.00%> (+0.39%)` | :arrow_up: |
| ... and [24 more](https://codecov.io/gh/mesonbuild/meson/pull/9763/diff?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/mesonbuild/meson/pull/9763?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/mesonbuild/meson/pull/9763?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None). Last update [37b122b...065f706](https://codecov.io/gh/mesonbuild/meson/pull/9763?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None).


Resolving patch:
diff --git a/mesonbuild/modules/rpm.py b/mesonbuild/modules/rpm.py
deleted file mode 100644
--- a/mesonbuild/modules/rpm.py
+++ /dev/null
@@ -1,186 +0,0 @@
-# Copyright 2015 The Meson development team
-
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-
-#     http://www.apache.org/licenses/LICENSE-2.0
-
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-'''This module provides helper functions for RPM related
-functionality such as generating template RPM spec file.'''
-
-from .. import build
-from .. import compilers
-import datetime
-from .. import mlog
-from . import GirTarget, TypelibTarget
-from . import ExtensionModule
-from ..interpreterbase import noKwargs
-
-import os
-
-class RPMModule(ExtensionModule):
-    def __init__(self, interpreter):
-        super().__init__(interpreter)
-        self.methods.update({
-            'generate_spec_template': self.generate_spec_template,
-        })
-
-    @noKwargs
-    def generate_spec_template(self, state, args, kwargs):
-        required_compilers = self.__get_required_compilers(state)
-        proj = state.project_name.replace(' ', '_').replace('\t', '_')
-        so_installed = False
-        devel_subpkg = False
-        files = set()
-        files_devel = set()
-        to_delete = set()
-        for target in state.targets.values():
-            if isinstance(target, build.Executable) and target.need_install:
-                files.add('%%{_bindir}/%s' % target.get_filename())
-            elif isinstance(target, build.SharedLibrary) and target.need_install:
-                files.add('%%{_libdir}/%s' % target.get_filename())
-                for alias in target.get_aliases():
-                    if alias.endswith('.so'):
-                        files_devel.add('%%{_libdir}/%s' % alias)
-                    else:
-                        files.add('%%{_libdir}/%s' % alias)
-                so_installed = True
-            elif isinstance(target, build.StaticLibrary) and target.need_install:
-                to_delete.add('%%{buildroot}%%{_libdir}/%s' % target.get_filename())
-                mlog.warning('removing', mlog.bold(target.get_filename()),
-                             'from package because packaging static libs not recommended')
-            elif isinstance(target, GirTarget) and target.should_install():
-                files_devel.add('%%{_datadir}/gir-1.0/%s' % target.get_filename()[0])
-            elif isinstance(target, TypelibTarget) and target.should_install():
-                files.add('%%{_libdir}/girepository-1.0/%s' % target.get_filename()[0])
-        for header in state.headers:
-            if header.get_install_subdir():
-                files_devel.add('%%{_includedir}/%s/' % header.get_install_subdir())
-            else:
-                for hdr_src in header.get_sources():
-                    files_devel.add('%%{_includedir}/%s' % hdr_src)
-        for man in state.man:
-            for man_file in man.get_sources():
-                if man.locale:
-                    files.add('%%{_mandir}/%s/man%u/%s.*' % (man.locale, int(man_file.split('.')[-1]), man_file))
-                else:
-                    files.add('%%{_mandir}/man%u/%s.*' % (int(man_file.split('.')[-1]), man_file))
-        if files_devel:
-            devel_subpkg = True
-
-        filename = os.path.join(state.environment.get_build_dir(),
-                                '%s.spec' % proj)
-        with open(filename, 'w+', encoding='utf-8') as fn:
-            fn.write('Name: %s\n' % proj)
-            fn.write('Version: # FIXME\n')
-            fn.write('Release: 1%{?dist}\n')
-            fn.write('Summary: # FIXME\n')
-            fn.write('License: # FIXME\n')
-            fn.write('\n')
-            fn.write('Source0: %{name}-%{version}.tar.xz # FIXME\n')
-            fn.write('\n')
-            fn.write('BuildRequires: meson\n')
-            for compiler in required_compilers:
-                fn.write('BuildRequires: %s\n' % compiler)
-            for dep in state.environment.coredata.deps.host:
-                fn.write('BuildRequires: pkgconfig(%s)\n' % dep[0])
-#   ext_libs and ext_progs have been removed from coredata so the following code
-#   no longer works. It is kept as a reminder of the idea should anyone wish
-#   to re-implement it.
-#
-#            for lib in state.environment.coredata.ext_libs.values():
-#                name = lib.get_name()
-#                fn.write('BuildRequires: {} # FIXME\n'.format(name))
-#                mlog.warning('replace', mlog.bold(name), 'with the real package.',
-#                             'You can use following command to find package which '
-#                             'contains this lib:',
-#                             mlog.bold("dnf provides '*/lib{}.so'".format(name)))
-#            for prog in state.environment.coredata.ext_progs.values():
-#                if not prog.found():
-#                    fn.write('BuildRequires: %%{_bindir}/%s # FIXME\n' %
-#                             prog.get_name())
-#                else:
-#                    fn.write('BuildRequires: {}\n'.format(prog.get_path()))
-            fn.write('\n')
-            fn.write('%description\n')
-            fn.write('\n')
-            if devel_subpkg:
-                fn.write('%package devel\n')
-                fn.write('Summary: Development files for %{name}\n')
-                fn.write('Requires: %{name}%{?_isa} = %{?epoch:%{epoch}:}{version}-%{release}\n')
-                fn.write('\n')
-                fn.write('%description devel\n')
-                fn.write('Development files for %{name}.\n')
-                fn.write('\n')
-            fn.write('%prep\n')
-            fn.write('%autosetup\n')
-            fn.write('\n')
-            fn.write('%build\n')
-            fn.write('%meson\n')
-            fn.write('%meson_build\n')
-            fn.write('\n')
-            fn.write('%install\n')
-            fn.write('%meson_install\n')
-            if to_delete:
-                fn.write('rm -vf %s\n' % ' '.join(to_delete))
-            fn.write('\n')
-            fn.write('%check\n')
-            fn.write('%meson_test\n')
-            fn.write('\n')
-            fn.write('%files\n')
-            for f in files:
-                fn.write('%s\n' % f)
-            fn.write('\n')
-            if devel_subpkg:
-                fn.write('%files devel\n')
-                for f in files_devel:
-                    fn.write('%s\n' % f)
-                fn.write('\n')
-            if so_installed:
-                fn.write('%post -p /sbin/ldconfig\n')
-                fn.write('%postun -p /sbin/ldconfig\n')
-            fn.write('\n')
-            fn.write('%changelog\n')
-            fn.write('* %s meson <meson@example.com> - \n' %
-                     datetime.date.today().strftime('%a %b %d %Y'))
-            fn.write('- \n')
-            fn.write('\n')
-        mlog.log('RPM spec template written to %s.spec.\n' % proj)
-
-    def __get_required_compilers(self, state):
-        required_compilers = set()
-        for compiler in state.environment.coredata.compilers.host.values():
-            # Elbrus has one 'lcc' package for every compiler
-            if isinstance(compiler, compilers.GnuCCompiler):
-                required_compilers.add('gcc')
-            elif isinstance(compiler, compilers.GnuCPPCompiler):
-                required_compilers.add('gcc-c++')
-            elif isinstance(compiler, compilers.ElbrusCCompiler):
-                required_compilers.add('lcc')
-            elif isinstance(compiler, compilers.ElbrusCPPCompiler):
-                required_compilers.add('lcc')
-            elif isinstance(compiler, compilers.ElbrusFortranCompiler):
-                required_compilers.add('lcc')
-            elif isinstance(compiler, compilers.ValaCompiler):
-                required_compilers.add('vala')
-            elif isinstance(compiler, compilers.GnuFortranCompiler):
-                required_compilers.add('gcc-gfortran')
-            elif isinstance(compiler, compilers.GnuObjCCompiler):
-                required_compilers.add('gcc-objc')
-            elif compiler == compilers.GnuObjCPPCompiler:
-                required_compilers.add('gcc-objc++')
-            else:
-                mlog.log('RPM spec file not created, generation not allowed for:',
-                         mlog.bold(compiler.get_id()))
-        return required_compilers
-
-
-def initialize(*args, **kwargs):
-    return RPMModule(*args, **kwargs)


Test patch: