2018-07-13 18:47:00 +08:00
|
|
|
# rpmlint
|
2015-10-03 17:50:39 +08:00
|
|
|
|
2021-01-12 23:59:03 +08:00
|
|
|
![Build and Test](https://github.com/rpm-software-management/rpmlint/workflows/Build%20and%20Test/badge.svg)
|
2019-07-11 22:10:36 +08:00
|
|
|
[![Total alerts](https://img.shields.io/lgtm/alerts/g/rpm-software-management/rpmlint.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/rpm-software-management/rpmlint/alerts/)
|
|
|
|
[![Language grade: Python](https://img.shields.io/lgtm/grade/python/g/rpm-software-management/rpmlint.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/rpm-software-management/rpmlint/context:python)
|
2019-07-15 18:25:38 +08:00
|
|
|
[![Coverage Status](https://coveralls.io/repos/github/rpm-software-management/rpmlint/badge.svg?branch=master)](https://coveralls.io/github/rpm-software-management/rpmlint?branch=master)
|
2018-07-13 18:47:00 +08:00
|
|
|
|
2019-08-15 19:17:48 +08:00
|
|
|
`rpmlint` is a tool for checking common errors in RPM packages.
|
|
|
|
`rpmlint` can be used to test individual packages before uploading or to check
|
2018-07-13 18:47:00 +08:00
|
|
|
an entire distribution.
|
|
|
|
|
2019-08-15 19:17:48 +08:00
|
|
|
`rpmlint` can check binary RPMs, source RPMs, and plain specfiles, but all
|
2019-07-13 04:03:30 +08:00
|
|
|
checks do not apply to all argument types.
|
2019-08-15 19:17:48 +08:00
|
|
|
For best check coverage, run `rpmlint` on source RPMs instead of
|
2019-07-13 04:03:30 +08:00
|
|
|
plain specfiles.
|
2015-10-03 17:50:39 +08:00
|
|
|
|
2019-08-15 19:17:48 +08:00
|
|
|
The idea for `rpmlint` is from the lintian tool of the Debian project.
|
|
|
|
All the checks reside in `rpmlint/checks` folder. Feel free to provide new
|
2018-07-13 18:47:00 +08:00
|
|
|
checks and suggestions at:
|
2015-10-03 17:50:39 +08:00
|
|
|
|
|
|
|
https://github.com/rpm-software-management/rpmlint
|
|
|
|
|
2019-07-15 19:52:30 +08:00
|
|
|
## Install
|
|
|
|
|
2019-08-15 19:17:48 +08:00
|
|
|
For installation on your machine you will need the following packages:
|
2019-07-15 19:52:30 +08:00
|
|
|
|
2019-08-15 19:42:19 +08:00
|
|
|
Mandatory:
|
2019-07-15 19:52:30 +08:00
|
|
|
- Python 3.6 or newer
|
pybeam is mandatory module
addressing:
Traceback (most recent call last):
File "/home/msuchy/projects/rpmlint/lint.py", line 5, in <module>
lint()
File "/home/msuchy/projects/rpmlint/rpmlint/cli.py", line 173, in lint
lint = Lint(options)
File "/home/msuchy/projects/rpmlint/rpmlint/lint.py", line 53, in __init__
self.load_checks()
File "/home/msuchy/projects/rpmlint/rpmlint/lint.py", line 291, in load_checks
self.checks[check] = self.load_check(check)
File "/home/msuchy/projects/rpmlint/rpmlint/lint.py", line 295, in load_check
module = importlib.import_module(f'.{name}', package='rpmlint.checks')
File "/usr/lib64/python3.9/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 790, in exec_module
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "/home/msuchy/projects/rpmlint/rpmlint/checks/ErlangCheck.py", line 3, in <module>
from pybeam import BeamFile
ModuleNotFoundError: No module named 'pybeam'
2021-03-23 05:04:31 +08:00
|
|
|
- python3-setuptools, python3-toml, python3-pyxdg, python3-beam
|
2019-07-15 19:52:30 +08:00
|
|
|
- rpm and its python bindings
|
2020-10-05 17:22:15 +08:00
|
|
|
- binutils, cpio, gzip, bzip, xz and zstd
|
2019-08-15 19:17:48 +08:00
|
|
|
|
2019-08-15 19:42:19 +08:00
|
|
|
Optional:
|
2019-08-15 19:17:48 +08:00
|
|
|
- libmagic and its python bindings
|
|
|
|
- enchant and its python bindings
|
|
|
|
- appstream-util, part of appstream-glib
|
2019-07-15 19:52:30 +08:00
|
|
|
|
2021-03-23 04:27:46 +08:00
|
|
|
`rpmlint` is part of most distributions and as an user you can simply
|
|
|
|
|
|
|
|
dnf install rpmlint
|
|
|
|
|
2019-07-15 19:52:30 +08:00
|
|
|
## Testing
|
2019-07-13 04:03:30 +08:00
|
|
|
|
2020-01-27 22:17:16 +08:00
|
|
|
### Containers
|
2019-10-03 19:22:23 +08:00
|
|
|
If you want to test the `rpmlint` when developing best is to use podman
|
2019-08-15 19:17:48 +08:00
|
|
|
to provide the environment for you. There are various distribution
|
2019-07-13 04:03:30 +08:00
|
|
|
dockerfiles in `test/` folder.
|
|
|
|
|
2019-08-15 19:17:48 +08:00
|
|
|
I.e. if you want to test on the latest openSUSE you can test using the following commands:
|
2019-07-13 04:03:30 +08:00
|
|
|
|
2019-10-03 19:22:23 +08:00
|
|
|
`podman build -t opensusetw -f test/Dockerfile-opensusetw .`
|
2019-07-15 19:52:30 +08:00
|
|
|
|
2020-02-12 16:59:45 +08:00
|
|
|
`podman run -v $(pwd):/usr/src/rpmlint/ opensusetw python3 -m pytest`
|
2019-07-13 04:03:30 +08:00
|
|
|
|
2019-08-15 19:17:48 +08:00
|
|
|
### Directly
|
|
|
|
|
2019-07-15 19:52:30 +08:00
|
|
|
Another option is to run the tests on your system directly. If you
|
|
|
|
have all the required modules as listed on the Install section above.
|
2020-03-25 21:11:13 +08:00
|
|
|
You will also need `pytest`,`pytest-cov`, `pytest-xdist`, and `pytest-flake8`.
|
2019-07-15 19:52:30 +08:00
|
|
|
|
|
|
|
If all the dependencies are present you can just execute tests using:
|
|
|
|
|
2020-02-12 16:59:45 +08:00
|
|
|
`python3 -m pytest`
|
2019-07-15 19:52:30 +08:00
|
|
|
|
2019-08-15 19:17:48 +08:00
|
|
|
Or even pick one of the tests using `pytest`:
|
2019-07-26 20:32:58 +08:00
|
|
|
|
|
|
|
`python3 -m pytest test/test_config.py`
|
|
|
|
|
2019-07-26 20:57:33 +08:00
|
|
|
## Bugfixing and contributing
|
|
|
|
|
2019-08-15 19:17:48 +08:00
|
|
|
Any help is, of course, welcome but honestly most probable cause for your visit
|
|
|
|
here is that `rpmlint` is marking something as invalid while it shouldn't or
|
2019-07-26 20:57:33 +08:00
|
|
|
it is marking something as correct while it should not either :)
|
|
|
|
|
2019-08-15 19:17:48 +08:00
|
|
|
Now there is an easy way how to fix that. Our testsuite simply needs an
|
2019-07-26 20:57:33 +08:00
|
|
|
extension to take the above problem into the account.
|
|
|
|
|
|
|
|
Primarily we just need the offending rpm file (best the smallest you can
|
|
|
|
find or we would soon take few GB to take a checkout) and some basic
|
|
|
|
expectation of what should happen.
|
|
|
|
|
2019-08-15 19:17:48 +08:00
|
|
|
### Example workflow
|
2019-07-26 20:57:33 +08:00
|
|
|
|
|
|
|
1) I have rpmfile that should report unreadable zip file
|
|
|
|
2) I store this file in git under `test/binary/texlive-codepage-doc-2018.151.svn21126-38.1.noarch.rpm`
|
|
|
|
3) Now I need to figure out what `check` should test this, in this case `test_zip.py`
|
|
|
|
4) For the testing I will have to devise a small function that validates my expectations:
|
|
|
|
|
|
|
|
```
|
|
|
|
@pytest.mark.parametrize('package', ['binary/texlive-codepage-doc'])
|
|
|
|
def test_zip2(tmpdir, package, zipcheck):
|
|
|
|
output, test = zipcheck
|
|
|
|
test.check(get_tested_package(package, tmpdir))
|
|
|
|
out = output.print_results(output.results)
|
|
|
|
assert 'W: unable-to-read-zip' in out
|
|
|
|
```
|
|
|
|
|
|
|
|
As you can see it is not so hard and with each added test we get better
|
|
|
|
coverage on what is really expected from rpmlint and avoid naughty regressions
|
2019-08-15 19:17:48 +08:00
|
|
|
in the long run.
|
2019-07-26 20:57:33 +08:00
|
|
|
|
2020-03-25 21:21:21 +08:00
|
|
|
Preferable approach for binary packages is to create artificial testcase (to keep binaries small and trivial).
|
2020-02-12 16:59:45 +08:00
|
|
|
We are currently using OBS to produce binaries:
|
|
|
|
https://build.opensuse.org/project/show/devel:openSUSE:Factory:rpmlint:tests
|
|
|
|
For a sample package see:
|
|
|
|
https://build.opensuse.org/package/show/devel:openSUSE:Factory:rpmlint:tests/non-position-independent-exec
|
|
|
|
|
2018-07-13 18:47:00 +08:00
|
|
|
## Configuration
|
|
|
|
|
|
|
|
If you want to change configuration options or the list of checks you can
|
2019-08-15 19:17:48 +08:00
|
|
|
use the following locations:
|
2018-07-13 18:47:00 +08:00
|
|
|
|
2020-10-29 16:40:18 +08:00
|
|
|
`/etc/xdg/rpmlint/*toml`
|
2018-07-13 18:47:00 +08:00
|
|
|
|
2020-10-29 16:40:18 +08:00
|
|
|
`$XDG_CONFIG_HOME/rpmlint/*toml`
|
2018-07-13 18:47:00 +08:00
|
|
|
|
2019-08-15 19:17:48 +08:00
|
|
|
The configuration itself is a `toml` file where for some basic inspiration
|
2019-07-15 20:44:02 +08:00
|
|
|
you can check up `rpmlint/configdefaults.toml` which specifies format/defaults.
|
2015-10-03 17:50:39 +08:00
|
|
|
|
2020-10-29 16:40:18 +08:00
|
|
|
One can also include additional configuration files (or directories) by using the `--config` option.
|
|
|
|
Note that all TOML configuration values are merged and not overridden.
|
|
|
|
So e.g. values in a list are concatenated. If you need an override,
|
|
|
|
use `*.override.*toml` configuration file, where all defined values are selected as default.
|
|
|
|
|
2019-08-15 19:17:48 +08:00
|
|
|
Additional option to control `rpmlint` behaviour is the addition of `rpmlintrc` file
|
|
|
|
which uses old syntax for compatibility with old `rpmlint` releases, yet
|
|
|
|
it can be normal `toml` file if you wish:
|
2015-10-03 17:50:39 +08:00
|
|
|
|
2018-08-08 23:48:07 +08:00
|
|
|
`setBadness('check', 0)`
|
2015-10-03 17:50:39 +08:00
|
|
|
|
2018-08-08 23:48:07 +08:00
|
|
|
`addFilter('test-i-ignore')`
|