Proof of concept: Macros to manipulate %py3_shebang_flags
Currently, when packagers want to strip the -s flag, they define %py3_shebang_flags to %nil or they %undefine it. However, if we are to add more default flags in the future, they will lose them all. Instead, we now have %py3_shebang_flags_add and %py3_shebang_flags_remove so packagers can explicitly remove the -s flag. Intentionally, the old %py3_build macro keeps using the default.
This commit is contained in:
parent
e250f28d09
commit
fba6a77032
|
@ -11,9 +11,45 @@
|
|||
%python_ext_suffix %(RPM_BUILD_ROOT= %{__python} -Esc "import sysconfig; print(sysconfig.get_config_var('EXT_SUFFIX'))")
|
||||
|
||||
%py_setup setup.py
|
||||
|
||||
# This is the "201x-era" macro, we also use it to define the default
|
||||
%py_shbang_opts -s
|
||||
%py_shbang_opts_nodash %(opts=%{py_shbang_opts}; echo ${opts#-})
|
||||
%py_shebang_flags %(opts=%{py_shbang_opts}; echo ${opts#-})
|
||||
|
||||
# This is a convenient helper that strips the leading dash from %%py_shbang_opts
|
||||
%py_shbang_opts_nodash %{lua:print((rpm.expand('%?py_shbang_opts'):gsub('^%-', '')))}
|
||||
|
||||
# Finally, this is the value everybody should actually use, with _add and _remove helpers
|
||||
%py_shebang_flags %{lua:
|
||||
-- py_shebang_flags is also a Lua global, so we can conveniently manipulate it repeatedly
|
||||
-- in the beginning however, it is not set, so we need to do it
|
||||
if py_shebang_flags == nil then
|
||||
py_shebang_flags = rpm.expand('%?py_shbang_opts_nodash')
|
||||
end
|
||||
print(py_shebang_flags)
|
||||
}
|
||||
|
||||
%py_shebang_flags_add() %{lua:
|
||||
if py_shebang_flags == nil then
|
||||
py_shebang_flags = rpm.expand('%?py_shbang_opts_nodash')
|
||||
end
|
||||
for flag in rpm.expand('%?*'):gmatch('%a') do
|
||||
index, _ = py_shebang_flags:find(flag)
|
||||
if index == nil then
|
||||
py_shebang_flags = py_shebang_flags .. flag
|
||||
end
|
||||
end
|
||||
}
|
||||
|
||||
%py_shebang_flags_remove() %{lua:
|
||||
if py_shebang_flags == nil then
|
||||
py_shebang_flags = rpm.expand('%?py_shbang_opts_nodash')
|
||||
end
|
||||
for flag in rpm.expand('%?*'):gmatch('%a') do
|
||||
py_shebang_flags, _ = py_shebang_flags:gsub(flag, '')
|
||||
end
|
||||
}
|
||||
|
||||
|
||||
%py_shebang_fix %{expand:\\\
|
||||
if [ -f /usr/bin/pathfix%{python_version}.py ]; then
|
||||
pathfix=/usr/bin/pathfix%{python_version}.py
|
||||
|
|
|
@ -9,9 +9,44 @@
|
|||
%python3_ext_suffix %(RPM_BUILD_ROOT= %{__python3} -Ic "import sysconfig; print(sysconfig.get_config_var('EXT_SUFFIX'))")
|
||||
%py3dir %{_builddir}/python3-%{name}-%{version}-%{release}
|
||||
|
||||
# This is the "201x-era" macro, we also use it to define the default
|
||||
%py3_shbang_opts -s
|
||||
%py3_shbang_opts_nodash %(opts=%{py3_shbang_opts}; echo ${opts#-})
|
||||
%py3_shebang_flags %(opts=%{py3_shbang_opts}; echo ${opts#-})
|
||||
|
||||
# This is a convenient helper that strips the leading dash from %%py3_shbang_opts
|
||||
%py3_shbang_opts_nodash %{lua:print((rpm.expand('%?py3_shbang_opts'):gsub('^%-', '')))}
|
||||
|
||||
# Finally, this is the value everybody should actually use, with _add and _remove helpers
|
||||
%py3_shebang_flags %{lua:
|
||||
-- py3_shebang_flags is also a Lua global, so we can conveniently manipulate it repeatedly
|
||||
-- in the beginning however, it is not set, so we need to do it
|
||||
if py3_shebang_flags == nil then
|
||||
py3_shebang_flags = rpm.expand('%?py3_shbang_opts_nodash')
|
||||
end
|
||||
print(py3_shebang_flags)
|
||||
}
|
||||
|
||||
%py3_shebang_flags_add() %{lua:
|
||||
if py3_shebang_flags == nil then
|
||||
py3_shebang_flags = rpm.expand('%?py3_shbang_opts_nodash')
|
||||
end
|
||||
for flag in rpm.expand('%?*'):gmatch('%a') do
|
||||
index, _ = py3_shebang_flags:find(flag)
|
||||
if index == nil then
|
||||
py3_shebang_flags = py3_shebang_flags .. flag
|
||||
end
|
||||
end
|
||||
}
|
||||
|
||||
%py3_shebang_flags_remove() %{lua:
|
||||
if py3_shebang_flags == nil then
|
||||
py3_shebang_flags = rpm.expand('%?py3_shbang_opts_nodash')
|
||||
end
|
||||
for flag in rpm.expand('%?*'):gmatch('%a') do
|
||||
py3_shebang_flags, _ = py3_shebang_flags:gsub(flag, '')
|
||||
end
|
||||
}
|
||||
|
||||
|
||||
%py3_shebang_fix %{expand:\\\
|
||||
if [ -f /usr/bin/pathfix%{python3_version}.py ]; then
|
||||
pathfix=/usr/bin/pathfix%{python3_version}.py
|
||||
|
|
Loading…
Reference in New Issue