-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrpmlint-mini.spec
168 lines (144 loc) · 6.02 KB
/
rpmlint-mini.spec
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
%global py_ver %(%{__python3} -c 'import sys; print(sys.version[:3])')
%define py_libdir %{_libdir}/python%{py_ver}
# The base directory (almost chroot) for rpmlint-mini
# This has to be /opt/testing for obs-build to find /opt/testing/bin/rpmlint
%define sa_base /opt/testing
Name: rpmlint-mini
BuildRequires: glib2-devel glib2-static pkgconfig rpm-python rpmlint
# These are the packages that rpmlint pulls in and need to be included into this standalone package
%define rpmlint_requires rpmlint python3-magic python3-toml python3-xdg python3-setuptools python3-zstd rpm-python
# python3-enchant is not yet packaged and is dynamically loaded
BuildRequires: python3-devel
BuildRequires: python3-magic
BuildRequires: libtool
#!BuildIgnore: rpmlint-mini
Summary: Rpm correctness checker
Version: 2.0.0+git4
Release: 1
Url: https://github.com/rpm-software-management/rpmlint
License: GPLv2+
Source: desktop-file-utils-0.17.tar.bz2
Patch10: static-desktop-file-validate.diff
# Not using macro as check_package_is_complete failed when using py_ver macro here
Source100: rpmlint-deps-3.8.txt
Source101: rpmlint.wrapper
# Config
Source200: rpmlint-mini-rpmlintrc
Source201: polkit-default-privs.config
# Test assets: Spec file and a tiny rpm
Source300: basesystem.spectest
Source301: basesystem-11+git1-1.3.65.jolla.noarch.rpm
Source302: basesystem-rpmlintrc
# Readme
Source400: README.jolla
%description
rpmlint-mini is a self-contained and minimal re-package of rpmlint,
python3 and required python modules with minimal requirements.
Rpmlint is a tool to check common errors on rpm packages. Binary and
source packages can be checked.
%prep
%setup -q -n desktop-file-utils-0.17
%patch10
%build
autoreconf -fi
%configure
pushd src
make desktop-file-validate V=1
popd
%install
rm -rf $RPM_BUILD_ROOT
# test if the rpmlint works at all
set +e
# check installed rpmlint package
echo "Testing vanilla rpmlint is installed and runs correctly. If this fails then rpmlint is broken!"
/usr/bin/rpmlint -i rpmlint
test $? -gt 0 -a $? -lt 60 && exit 1
set -e
# okay, lets put it together in the standalone root:
%define sa_root %{buildroot}%{sa_base}
rm -rf %{sa_root}
mkdir -p %{sa_root}%{_bindir}
mkdir -p %{sa_root}/bin
mkdir -p %{sa_root}%{_libdir}
mkdir -p %{sa_root}%{_sysconfdir}/rpmlint
mkdir -p %{sa_root}%{_sysconfdir}/pythonstart
# Install our desktop-file-validate binary
install -m 755 -D src/desktop-file-validate %{sa_root}/usr/bin/desktop-file-validate
# Install config files
for i in "%{SOURCE200}" "%{SOURCE201}"; do
cp $i %{sa_root}%{_sysconfdir}/rpmlint
done
# Setup a minimal python3
install -D %{_bindir}/python3 %{sa_root}/%{_bindir}/python3
cp -a %{_libdir}/libpython%{py_ver}.so* %{sa_root}/%{_libdir}
install -m 644 -D /usr/include/python%{py_ver}/pyconfig.h %{sa_root}/usr/include/python%{py_ver}/pyconfig.h
# These are the python modules and libraries needed by rpmlint etc
pushd %{py_libdir}
for f in $(<%{SOURCE100}); do
find -path "*/$f" -exec install -D {} %{sa_root}/%{py_libdir}/{} \;
done
popd
# Follow the same approach as sb2-tools-template to setup rpmlint and dependencies
# Copy all files from the rpms that rpmlint requires into the sa_root
rpm -ql %{rpmlint_requires} > rpmlint.files
tar --no-recursion -T rpmlint.files -cpf - | ( cd %{sa_root} && tar -xvpf - ) > rpmlint.files_in_sa_root
# The rpmlint-mini wrapper will set LD_LIBRARY_PATH to sa_root/_libdir
# so we can add libraries in there.
# libmagic is part of 'file' and needed by python3-magic
cp -a %{_libdir}/libmagic.so.* %{sa_root}/%{_libdir}
ldd %{python3_sitearch}/rpm/*.so | while read LIB TARGET RESOLVED_LIB ADDRESS
do
# skip libc, it must match the system ld.so (which we cannot replace)
case $LIB in libc.*) continue;; esac
cp '-aLt%{buildroot}/opt/testing/%{_libdir}' "${RESOLVED_LIB}" || # is it a virtual library?
! <"${RESOLVED_LIB}" || # it is a real library and still could not be copied
false # this is necessary to really fail
done
# Now we byte-compile and optimise to compress
# Ues the 'legacy' pyc naming as per the PEP
# https://www.python.org/dev/peps/pep-3147/#case-4-legacy-pyc-files-and-source-less-imports
# so we can remove the .py files (this doesn't work with __pycache__/ dirs!)
pushd %{sa_root}/%{py_libdir}/
%{__python3} -O -m compileall -b .
find . -name \*py | xargs rm
popd
# Use the rpmlint-mini wrapper
mv %{sa_root}/%{_bindir}/rpmlint %{sa_root}/%{_bindir}/rpmlint.real
install -m 755 -D %{SOURCE101} %{sa_root}/%{_bindir}/rpmlint
ln -s ../%{_bindir}/rpmlint %{sa_root}/bin/rpmlint
# work around the rpmbuild require/provide
%define my_requires %{_builddir}/%{?buildsubdir}/%{name}-requires
cat << EOF > %my_requires
cat - > /tmp/file.list
%{__find_requires} < /tmp/file.list > /tmp/requires.list
%{__find_provides} < /tmp/file.list > /tmp/provides.list
while read i; do
grep -F -v "\$i" /tmp/requires.list > /tmp/requires.list.new
mv /tmp/requires.list.new /tmp/requires.list
done < /tmp/provides.list
cat /tmp/requires.list
rm -f /tmp/requires.list /tmp/provides.list /tmp/file.list
EOF
chmod +x %my_requires
%define _use_internal_dependency_generator 0
%define __find_requires %my_requires
%define __find_provides %nil
# Errors from here are hopefully down to things required by rpmlint and python3
echo Running standalone rpmlint to check for missing python imports libraries etc
# The rpmlint wrapper allows us to override the standalone root using $SA_ROOT
export SA_ROOT=%{sa_root}
# Check the wrapper runs with no Checks
%{sa_root}/bin/rpmlint --verbose --help || exit 1
# Now just run the Checks against a simple rpm and this spec file so
# we're not caught out when running real tests. If anything fails due to
# missing imports then update rpmlint-deps*.txt
# First check spec file
%{sa_root}/bin/rpmlint --verbose %{SOURCE300} || exit 1
# And then a tiny test rpm
%{sa_root}/bin/rpmlint --verbose --rpmlintrc %{SOURCE302} %{SOURCE301} || exit 1
echo "ok.... standalone rpmlint-mini has run successfully"
%clean
rm -rf $RPM_BUILD_ROOT
%files
%defattr(-,root,root,0755)
%{sa_base}