Browse code

rpm: add python3-macros to rpm-build

python3: fix macros.python

Change-Id: I79c9d993b7c83dc7698643fc32af3106303eeff8
Signed-off-by: Shreenidhi Shedi <sshedi@vmware.com>
Reviewed-on: http://photon-jenkins.eng.vmware.com:8082/14111
Tested-by: gerrit-photon <photon-checkins@vmware.com>
Reviewed-by: Oliver Kurth <okurth@vmware.com>

Shreenidhi Shedi authored on 2021/08/16 18:47:39
Showing 4 changed files
1 1
deleted file mode 100644
... ...
@@ -1,17 +0,0 @@
1
-From 5cffb1ed6a7f5afe74e4384d59f1670be29a7930 Mon Sep 17 00:00:00 2001
2
-From: elena <elena@rategia.com>
3
-Date: Tue, 24 Apr 2018 13:44:30 +0300
4
-Subject: [PATCH] Explain that the orderness of the result is system-dependant
5
-
6
-+++ b/Doc/library/glob.rst	2019-11-05 05:42:58.296024048 +0000
7
-@@ -42,7 +42,8 @@ For example, ``'[?]'`` matches the chara
8
-    a string containing a path specification. *pathname* can be either absolute
9
-    (like :file:`/usr/src/Python-1.5/Makefile`) or relative (like
10
-    :file:`../../Tools/\*/\*.gif`), and can contain shell-style wildcards. Broken
11
--   symlinks are included in the results (as in the shell).
12
-+   symlinks are included in the results (as in the shell). Whether or not the
13
-+   results are sorted depends on the file system.
14
- 
15
-    .. index::
16
-       single: **; in glob-style wildcards
... ...
@@ -1,43 +1,106 @@
1 1
 %__python3 /usr/bin/python3
2
+%python3 %__python3
2 3
 %python3_sitelib %(%{__python3} -Ic "from distutils.sysconfig import get_python_lib; print(get_python_lib())")
3 4
 %python3_sitearch %(%{__python3} -Ic "from distutils.sysconfig import get_python_lib; print(get_python_lib(1))")
4
-%python3_version %(%{__python3} -Ic "import sys; sys.stdout.write(sys.version[:3])")
5
-%python3_version_nodots %(%{__python3} -Ic "import sys; sys.stdout.write(sys.version[:3].replace('.',''))")
5
+%python3_version %(%{__python3} -Ic "import sys; sys.stdout.write('{0.major}.{0.minor}'.format(sys.version_info))")
6
+%python3_version_nodots %(%{__python3} -Ic "import sys; sys.stdout.write('{0.major}{0.minor}'.format(sys.version_info))")
6 7
 %python3_platform %(%{__python3} -Ic "import sysconfig; print(sysconfig.get_platform())")
8
+%python3_platform_triplet %(%{__python3} -Ic "import sysconfig; print(sysconfig.get_config_var('MULTIARCH'))")
9
+%python3_ext_suffix %(%{__python3} -Ic "import sysconfig; print(sysconfig.get_config_var('EXT_SUFFIX'))")
7 10
 %py3dir %{_builddir}/python3-%{name}-%{version}-%{release}
8
- 
11
+
12
+%py_setup setup.py
9 13
 %py3_shbang_opts -s
10
- 
14
+%py3_shbang_opts_nodash %(opts=%{py3_shbang_opts}; echo ${opts#-})
15
+%py3_shebang_flags %(opts=%{py3_shbang_opts}; echo ${opts#-})
16
+%py3_shebang_fix %{expand:\\\
17
+  if [ -f /usr/bin/pathfix%{python3_version}.py ]; then
18
+    pathfix=/usr/bin/pathfix%{python3_version}.py
19
+  else
20
+    # older versions of Python don't have it and must BR /usr/bin/pathfix.py from python3-devel explicitly
21
+    pathfix=/usr/bin/pathfix.py
22
+  fi
23
+  if [ -z "%{?py3_shebang_flags}" ]; then
24
+    shebang_flags="-k"
25
+  else
26
+    shebang_flags="-ka%{py3_shebang_flags}"
27
+  fi
28
+  $pathfix -pni %{__python3} $shebang_flags}
29
+
11 30
 # Use the slashes after expand so that the command starts on the same line as
12 31
 # the macro
13 32
 %py3_build() %{expand:\\\
14 33
   CFLAGS="${CFLAGS:-${RPM_OPT_FLAGS}}" LDFLAGS="${LDFLAGS:-${RPM_LD_FLAGS}}"\\\
15 34
   %{__python3} %{py_setup} %{?py_setup_args} build --executable="%{__python3} %{py3_shbang_opts}" %{?*}
16
-  sleep 1
17 35
 }
18
- 
36
+
19 37
 %py3_build_egg() %{expand:\\\
20 38
   CFLAGS="${CFLAGS:-${RPM_OPT_FLAGS}}" LDFLAGS="${LDFLAGS:-${RPM_LD_FLAGS}}"\\\
21 39
   %{__python3} %{py_setup} %{?py_setup_args} bdist_egg %{?*}
22
-  sleep 1
23 40
 }
24
- 
41
+
25 42
 %py3_build_wheel() %{expand:\\\
26 43
   CFLAGS="${CFLAGS:-${RPM_OPT_FLAGS}}" LDFLAGS="${LDFLAGS:-${RPM_LD_FLAGS}}"\\\
27 44
   %{__python3} %{py_setup} %{?py_setup_args} bdist_wheel %{?*}
28
-  sleep 1
29 45
 }
30
- 
46
+
31 47
 %py3_install() %{expand:\\\
32 48
   CFLAGS="${CFLAGS:-${RPM_OPT_FLAGS}}" LDFLAGS="${LDFLAGS:-${RPM_LD_FLAGS}}"\\\
33 49
   %{__python3} %{py_setup} %{?py_setup_args} install -O1 --skip-build --root %{buildroot} %{?*}
50
+  rm -rfv %{buildroot}%{_bindir}/__pycache__
34 51
 }
35
- 
52
+
36 53
 %py3_install_egg() %{expand:\\\
37 54
   mkdir -p %{buildroot}%{python3_sitelib}
38
-  easy_install-%{python3_version} -m --prefix %{buildroot}%{_prefix} -Z dist/*-py%{python3_version}.egg %{?*}
55
+  %{__python3} -m easy_install -m --prefix %{buildroot}%{_prefix} -Z dist/*-py%{python3_version}.egg %{?*}
56
+  rm -rfv %{buildroot}%{_bindir}/__pycache__
39 57
 }
40
- 
58
+
41 59
 %py3_install_wheel() %{expand:\\\
42
-  pip%{python3_version} install -I dist/%{1} --root %{buildroot} --strip-file-prefix %{buildroot} --no-deps
60
+  %{__python3} -m pip install -I dist/%{1} --root %{buildroot} --no-deps --no-index --no-warn-script-location
61
+  rm -rfv %{buildroot}%{_bindir}/__pycache__
62
+  for distinfo in %{buildroot}%{python3_sitelib}/*.dist-info %{buildroot}%{python3_sitearch}/*.dist-info; do
63
+    if [ -f ${distinfo}/direct_url.json ]; then
64
+      rm -fv ${distinfo}/direct_url.json
65
+      sed -i '/direct_url.json/d' ${distinfo}/RECORD
66
+    fi
67
+  done
43 68
 }
69
+
70
+# With $PATH and $PYTHONPATH set to the %%buildroot,
71
+# try to import the given Python 3 module(s).
72
+# Useful as a smoke test in %%check when running tests is not feasible.
73
+# Use spaces or commas as separators.
74
+%py3_check_import() %{expand:\\\
75
+  (cd %{_topdir} &&\\\
76
+  PATH="%{buildroot}%{_bindir}:$PATH"\\\
77
+  PYTHONPATH="${PYTHONPATH:-%{buildroot}%{python3_sitearch}:%{buildroot}%{python3_sitelib}}"\\\
78
+  PYTHONDONTWRITEBYTECODE=1\\\
79
+  %{__python3} -c "import %{lua:local m=rpm.expand('%{?*}'):gsub('[%s,]+', ', ');print(m)}"
80
+  )
81
+}
82
+
83
+# This only supports Python 3.5+ and will never work with Python 2.
84
+# Hence, it has no Python version in the name.
85
+%pycached() %{lua:
86
+  path = rpm.expand("%{?*}")
87
+  if (string.sub(path, "-3") ~= ".py") then
88
+    rpm.expand("%{error:%%pycached can only be used with paths explicitly ending with .py}")
89
+  else
90
+    print(path)
91
+    pyminor = path:match("/python3.(%d+)/") or "*"
92
+    dirname = path:match("(.*/)")
93
+    modulename = path:match(".*/([^/]+).py")
94
+    print("\\n" .. dirname .. "__pycache__/" .. modulename .. ".cpython-3" .. pyminor .. "{,.opt-?}.pyc")
95
+  end
96
+}
97
+
98
+# This is intended for Python 3 only, hence also no Python version in the name.
99
+%__pytest /usr/bin/pytest%(test %{python3_pkgversion} == 3 || echo -%{python3_version})
100
+%pytest %{expand:\\\
101
+  CFLAGS="${CFLAGS:-${RPM_OPT_FLAGS}}" LDFLAGS="${LDFLAGS:-${RPM_LD_FLAGS}}"\\\
102
+  PATH="%{buildroot}%{_bindir}:$PATH"\\\
103
+  PYTHONPATH="${PYTHONPATH:-%{buildroot}%{python3_sitearch}:%{buildroot}%{python3_sitelib}}"\\\
104
+  PYTHONDONTWRITEBYTECODE=1\\\
105
+  %{?__pytest_addopts:PYTEST_ADDOPTS="${PYTEST_ADDOPTS:-} %{__pytest_addopts}"}\\\
106
+  %__pytest}
... ...
@@ -1,7 +1,7 @@
1 1
 Summary:        A high-level scripting language
2 2
 Name:           python3
3 3
 Version:        3.9.1
4
-Release:        3%{?dist}
4
+Release:        4%{?dist}
5 5
 License:        PSF
6 6
 URL:            http://www.python.org/
7 7
 Group:          System Environment/Programming
... ...
@@ -10,7 +10,9 @@ Distribution:   Photon
10 10
 Source0:        https://www.python.org/ftp/python/%{version}/Python-%{version}.tar.xz
11 11
 %define sha1    Python=77f4105846f6740297e50d7535a42c02d6b8e7db
12 12
 Source1:        macros.python
13
+
13 14
 Patch0:         cgi3.patch
15
+
14 16
 BuildRequires:  pkg-config >= 0.28
15 17
 BuildRequires:  bzip2-devel
16 18
 BuildRequires:  ncurses-devel
... ...
@@ -23,6 +25,7 @@ BuildRequires:  sqlite-devel
23 23
 BuildRequires:  util-linux-devel
24 24
 # cross compilation requires native python3 installed for ensurepip
25 25
 %define BuildRequiresNative python3-xml
26
+
26 27
 Requires:       ncurses
27 28
 Requires:       openssl
28 29
 Requires:       python3-libs = %{version}-%{release}
... ...
@@ -57,7 +60,6 @@ Requires:       sqlite-libs
57 57
 Requires:       bzip2-libs
58 58
 Requires:       util-linux-libs
59 59
 
60
-
61 60
 %description    libs
62 61
 The python interpreter can be embedded into applications wanting to
63 62
 use python as an embedded scripting language.  The python-libs package
... ...
@@ -153,30 +155,30 @@ You should not need to install this package manually as the various
153 153
 python-devel packages require it. So install a python-devel package instead.
154 154
 
155 155
 %prep
156
-%setup -q -n Python-%{version}
157
-%patch0 -p1
156
+%autosetup -p1 -n Python-%{version}
158 157
 
159 158
 %build
160 159
 export OPT="${CFLAGS}"
161 160
 if [ %{_host} != %{_build} ]; then
162
-  ln -s python3 /bin/python
161
+  ln -sfv python3 /bin/python
163 162
   export ac_cv_buggy_getaddrinfo=no
164 163
   export ac_cv_file__dev_ptmx=yes
165 164
   export ac_cv_file__dev_ptc=no
166 165
 fi
166
+
167 167
 %configure \
168
-    CFLAGS="%{optflags}" \
169
-    CXXFLAGS="%{optflags}" \
170 168
     --enable-shared \
171 169
     --with-system-expat \
172 170
     --with-system-ffi \
173 171
     --enable-optimizations \
174 172
     --with-dbmliborder=gdbm:ndbm
173
+
175 174
 make %{?_smp_mflags}
176 175
 
177 176
 %install
178
-[ %{buildroot} != "/"] && rm -rf %{buildroot}/*
179
-make DESTDIR=%{buildroot} install
177
+[ %{buildroot} != "/" ] && rm -rf %{buildroot}/*
178
+
179
+make DESTDIR=%{buildroot} install %{?_smp_mflags}
180 180
 %{_fixperms} %{buildroot}/*
181 181
 
182 182
 # Remove unused stuff
... ...
@@ -189,7 +191,7 @@ mkdir -p %{buildroot}/usr/lib/rpm/macros.d
189 189
 install -m 644 %{SOURCE1} %{buildroot}/usr/lib/rpm/macros.d
190 190
 
191 191
 %check
192
-make  %{?_smp_mflags} test
192
+make %{?_smp_mflags} test
193 193
 
194 194
 %post
195 195
 ln -sf /usr/bin/python3 /usr/bin/python
... ...
@@ -203,7 +205,7 @@ if [ $1 -eq 0 ] ; then
203 203
     if [ -f "/usr/bin/python2" ]; then
204 204
         ln -sf /usr/bin/python2 /usr/bin/python
205 205
     else
206
-        rm /usr/bin/python
206
+        rm -f /usr/bin/python
207 207
     fi
208 208
 fi
209 209
 /sbin/ldconfig
... ...
@@ -300,6 +302,8 @@ rm -rf %{buildroot}/*
300 300
 %{_libdir}/rpm/macros.d/macros.python
301 301
 
302 302
 %changelog
303
+*   Mon Aug 16 2021 Shreenidhi Shedi <sshedi@vmware.com> 3.9.1-4
304
+-   Fix python rpm macros
303 305
 *   Sat Mar 27 2021 Tapas Kundu <tkundu@vmware.com> 3.9.1-3
304 306
 -   Remove packaging exe files in python3-pip
305 307
 *   Sat Jan 16 2021 Shreenidhi Shedi <sshedi@vmware.com> 3.9.1-2
... ...
@@ -3,7 +3,7 @@
3 3
 Summary:        Package manager
4 4
 Name:           rpm
5 5
 Version:        4.16.1.2
6
-Release:        6%{?dist}
6
+Release:        7%{?dist}
7 7
 License:        GPLv2+
8 8
 URL:            http://rpm.org
9 9
 Group:          Applications/System
... ...
@@ -46,7 +46,6 @@ BuildRequires:  file-devel
46 46
 BuildRequires:  python3-devel
47 47
 BuildRequires:  openssl >= 1.1.1
48 48
 BuildRequires:  zstd-devel
49
-BuildRequires:  systemd-rpm-macros
50 49
 
51 50
 %description
52 51
 RPM package manager
... ...
@@ -80,6 +79,7 @@ Requires:   %{name}-devel = %{version}-%{release}
80 80
 Requires:   elfutils-libelf
81 81
 Requires:   cpio
82 82
 Requires:   systemd-rpm-macros
83
+Requires:   python3-macros
83 84
 Summary:    Binaries, scripts and libraries needed to build rpms.
84 85
 %description build
85 86
 Binaries, libraries and scripts to build rpms.
... ...
@@ -258,6 +258,8 @@ rm -rf %{buildroot}
258 258
 %{python3_sitelib}/*
259 259
 
260 260
 %changelog
261
+*   Mon Aug 16 2021 Shreenidhi Shedi <sshedi@vmware.com> 4.16.1.2-7
262
+-   Add python3-macros to rpm-build
261 263
 *   Wed Jul 28 2021 Shreenidhi Shedi <sshedi@vmware.com> 4.16.1.2-6
262 264
 -   Remove python dependency from rpm main package
263 265
 *   Wed Jul 14 2021 Susant Sahani <ssahani@vmware.com> 4.16.1.2-5