You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

254 lines
12 KiB

  1. From ab4cfb5e84a95decd06487dc4e59827ddb8ce79d Mon Sep 17 00:00:00 2001
  2. From: Georgia Garcia <georgia.garcia@canonical.com>
  3. Date: Wed, 10 Nov 2021 19:50:35 +0000
  4. Subject: [PATCH] replace deprecated distutils with setuptools
  5. Adds python3 setuptools as a build dependency for libapparmor
  6. Fixes: https://gitlab.com/apparmor/apparmor/-/issues/202
  7. MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/813
  8. Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
  9. Acked-by: Christian Boltz <apparmor@cboltz.de>
  10. (cherry picked from commit 21e5a721ab2abe26bb12b9da7accc39d4fff9804)
  11. Signed-off-by: John Johansen <john.johansen@canonical.com>
  12. ---
  13. .gitignore | 3 ++
  14. .gitlab-ci.yml | 2 +-
  15. libraries/libapparmor/m4/ac_python_devel.m4 | 36 +++++++++----------
  16. libraries/libapparmor/swig/python/Makefile.am | 2 +-
  17. libraries/libapparmor/swig/python/setup.py.in | 2 +-
  18. .../libapparmor/swig/python/test/Makefile.am | 2 +-
  19. profiles/Makefile | 2 +-
  20. utils/Makefile | 1 +
  21. utils/python-tools-setup.py | 6 ++--
  22. utils/test/Makefile | 2 +-
  23. utils/test/README.md | 18 ++++++++++
  24. 11 files changed, 49 insertions(+), 27 deletions(-)
  25. create mode 100644 utils/test/README.md
  26. --- a/.gitignore
  27. +++ b/.gitignore
  28. @@ -159,6 +159,7 @@ libraries/libapparmor/swig/perl/libappar
  29. libraries/libapparmor/swig/perl/libapparmor_wrap.o
  30. libraries/libapparmor/swig/perl/pm_to_blib
  31. libraries/libapparmor/swig/python/LibAppArmor.py
  32. +libraries/libapparmor/swig/python/LibAppArmor.egg-info/
  33. libraries/libapparmor/swig/python/build/
  34. libraries/libapparmor/swig/python/libapparmor_wrap.c
  35. libraries/libapparmor/swig/python/Makefile
  36. @@ -203,6 +204,8 @@ utils/*.tmp
  37. utils/po/*.mo
  38. utils/apparmor/*.pyc
  39. utils/apparmor/rule/*.pyc
  40. +utils/apparmor.egg-info/
  41. +utils/build/
  42. utils/htmlcov/
  43. utils/test/common_test.pyc
  44. utils/test/.coverage
  45. --- a/.gitlab-ci.yml
  46. +++ b/.gitlab-ci.yml
  47. @@ -1,7 +1,7 @@
  48. ---
  49. image: ubuntu:latest
  50. before_script:
  51. - - export DEBIAN_FRONTEND=noninteractive && apt-get update -qq && apt-get install --no-install-recommends -y build-essential apache2-dev autoconf automake bison dejagnu flex libpam-dev libtool perl liblocale-gettext-perl pkg-config python-all-dev python3-all-dev pyflakes3 ruby-dev swig lsb-release python3-notify2 python3-psutil zlib1g-dev
  52. + - export DEBIAN_FRONTEND=noninteractive && apt-get update -qq && apt-get install --no-install-recommends -y build-essential apache2-dev autoconf automake bison dejagnu flex libpam-dev libtool perl liblocale-gettext-perl pkg-config python-all-dev python3-all-dev pyflakes3 ruby-dev swig lsb-release python3-notify2 python3-psutil python3-setuptools zlib1g-dev
  53. - lsb_release -a
  54. - uname -a
  55. --- a/libraries/libapparmor/m4/ac_python_devel.m4
  56. +++ b/libraries/libapparmor/m4/ac_python_devel.m4
  57. @@ -66,17 +66,17 @@ variable to configure. See ``configure -
  58. fi
  59. #
  60. - # Check if you have distutils, else fail
  61. + # Check if you have setuptools, else fail
  62. #
  63. - AC_MSG_CHECKING([for the distutils Python package])
  64. - ac_distutils_result=`$PYTHON -c "import distutils" 2>&1`
  65. - if test -z "$ac_distutils_result"; then
  66. + AC_MSG_CHECKING([for the setuptools Python package])
  67. + ac_setuptools_result=`$PYTHON -c "import setuptools" 2>&1`
  68. + if test -z "$ac_setuptools_result"; then
  69. AC_MSG_RESULT([yes])
  70. else
  71. AC_MSG_RESULT([no])
  72. - AC_MSG_ERROR([cannot import Python module "distutils".
  73. + AC_MSG_ERROR([cannot import Python module "setuptools".
  74. Please check your Python installation. The error was:
  75. -$ac_distutils_result])
  76. +$ac_setuptools_result])
  77. PYTHON_VERSION=""
  78. fi
  79. @@ -88,8 +88,8 @@ $ac_distutils_result])
  80. PYTHON_CPPFLAGS=`$PYTHON_CONFIG --includes`
  81. fi
  82. if test -z "$PYTHON_CPPFLAGS"; then
  83. - python_path=`$PYTHON -c "import sys; import distutils.sysconfig;\
  84. -sys.stdout.write('%s\n' % distutils.sysconfig.get_python_inc());"`
  85. + python_path=`$PYTHON -c "import sys; import sysconfig;\
  86. +sys.stdout.write('%s\n' % sysconfig.get_path('include'));"`
  87. if test -n "${python_path}"; then
  88. python_path="-I$python_path"
  89. fi
  90. @@ -108,8 +108,8 @@ sys.stdout.write('%s\n' % distutils.sysc
  91. if test -z "$PYTHON_LDFLAGS"; then
  92. # (makes two attempts to ensure we've got a version number
  93. # from the interpreter)
  94. - py_version=`$PYTHON -c "import sys; from distutils.sysconfig import *; \
  95. -sys.stdout.write('%s\n' % ''.join(get_config_vars('VERSION')))"`
  96. + py_version=`$PYTHON -c "import sys; import sysconfig; \
  97. +sys.stdout.write('%s\n' % ''.join(sysconfig.get_config_vars('VERSION')))"`
  98. if test "$py_version" == "[None]"; then
  99. if test -n "$PYTHON_VERSION"; then
  100. py_version=$PYTHON_VERSION
  101. @@ -119,8 +119,8 @@ sys.stdout.write("%s\n" % sys.version[[:
  102. fi
  103. fi
  104. - PYTHON_LDFLAGS=`$PYTHON -c "import sys; from distutils.sysconfig import *; \
  105. -sys.stdout.write('-L' + get_python_lib(0,1) + ' -lpython\n')"`$py_version`$PYTHON -c \
  106. + PYTHON_LDFLAGS=`$PYTHON -c "import sys; import sysconfig; \
  107. +sys.stdout.write('-L' + sysconfig.get_path('stdlib') + ' -lpython\n')"`$py_version`$PYTHON -c \
  108. "import sys; sys.stdout.write('%s' % getattr(sys,'abiflags',''))"`
  109. fi
  110. AC_MSG_RESULT([$PYTHON_LDFLAGS])
  111. @@ -131,8 +131,8 @@ sys.stdout.write('-L' + get_python_lib(0
  112. #
  113. AC_MSG_CHECKING([for Python site-packages path])
  114. if test -z "$PYTHON_SITE_PKG"; then
  115. - PYTHON_SITE_PKG=`$PYTHON -c "import sys; import distutils.sysconfig; \
  116. -sys.stdout.write('%s\n' % distutils.sysconfig.get_python_lib(0,0));"`
  117. + PYTHON_SITE_PKG=`$PYTHON -c "import sys; import sysconfig; \
  118. +sys.stdout.write('%s\n' % sysconfig.get_path('purelib'));"`
  119. fi
  120. AC_MSG_RESULT([$PYTHON_SITE_PKG])
  121. AC_SUBST([PYTHON_SITE_PKG])
  122. @@ -146,8 +146,8 @@ sys.stdout.write('%s\n' % distutils.sysc
  123. PYTHON_EXTRA_LIBS=''
  124. fi
  125. if test -z "$PYTHON_EXTRA_LIBS"; then
  126. - PYTHON_EXTRA_LIBS=`$PYTHON -c "import sys; import distutils.sysconfig; \
  127. -conf = distutils.sysconfig.get_config_var; \
  128. + PYTHON_EXTRA_LIBS=`$PYTHON -c "import sys; import sysconfig; \
  129. +conf = sysconfig.get_config_var; \
  130. sys.stdout.write('%s %s %s\n' % (conf('BLDLIBRARY'), conf('LOCALMODLIBS'), conf('LIBS')))"`
  131. fi
  132. AC_MSG_RESULT([$PYTHON_EXTRA_LIBS])
  133. @@ -162,8 +162,8 @@ sys.stdout.write('%s %s %s\n' % (conf('B
  134. PYTHON_EXTRA_LDFLAGS=''
  135. fi
  136. if test -z "$PYTHON_EXTRA_LDFLAGS"; then
  137. - PYTHON_EXTRA_LDFLAGS=`$PYTHON -c "import sys; import distutils.sysconfig; \
  138. -conf = distutils.sysconfig.get_config_var; \
  139. + PYTHON_EXTRA_LDFLAGS=`$PYTHON -c "import sys; import sysconfig; \
  140. +conf = sysconfig.get_config_var; \
  141. sys.stdout.write('%s\n' % conf('LINKFORSHARED'))"`
  142. fi
  143. AC_MSG_RESULT([$PYTHON_EXTRA_LDFLAGS])
  144. --- a/libraries/libapparmor/swig/python/Makefile.am
  145. +++ b/libraries/libapparmor/swig/python/Makefile.am
  146. @@ -21,7 +21,7 @@ install-exec-local:
  147. clean-local:
  148. if test -x "$(PYTHON)"; then $(PYTHON) setup.py clean; fi
  149. - rm -rf build
  150. + rm -rf build LibAppArmor.egg-info
  151. if test $(top_srcdir) != $(top_builddir) ; then rm -f libapparmor_wrap.c ; fi
  152. endif
  153. --- a/libraries/libapparmor/swig/python/setup.py.in
  154. +++ b/libraries/libapparmor/swig/python/setup.py.in
  155. @@ -1,4 +1,4 @@
  156. -from distutils.core import setup, Extension
  157. +from setuptools import setup, Extension
  158. import string
  159. setup(name = 'LibAppArmor',
  160. --- a/libraries/libapparmor/swig/python/test/Makefile.am
  161. +++ b/libraries/libapparmor/swig/python/test/Makefile.am
  162. @@ -11,7 +11,7 @@ test_python.py: test_python.py.in $(top_
  163. CLEANFILES = test_python.py
  164. # bah, how brittle is this?
  165. -PYTHON_DIST_BUILD_PATH = '$(builddir)/../build/$$($(PYTHON) -c "import distutils.util; import platform; print(\"lib.%s-%s\" %(distutils.util.get_platform(), platform.python_version()[:3]))")'
  166. +PYTHON_DIST_BUILD_PATH = '$(builddir)/../build/$$($(PYTHON) -c "import sysconfig; print(\"lib.%s-%s\" %(sysconfig.get_platform(), sysconfig.get_python_version()))")'
  167. TESTS = test_python.py
  168. TESTS_ENVIRONMENT = \
  169. --- a/profiles/Makefile
  170. +++ b/profiles/Makefile
  171. @@ -41,7 +41,7 @@ ifdef USE_SYSTEM
  172. LOGPROF?=aa-logprof
  173. else
  174. # PYTHON_DIST_BUILD_PATH based on libapparmor/swig/python/test/Makefile.am
  175. - PYTHON_DIST_BUILD_PATH = ../libraries/libapparmor/swig/python/build/$$($(PYTHON) -c "import distutils.util; import platform; print(\"lib.%s-%s\" %(distutils.util.get_platform(), platform.python_version()[:3]))")
  176. + PYTHON_DIST_BUILD_PATH = ../libraries/libapparmor/swig/python/build/$$($(PYTHON) -c "import sysconfig; print(\"lib.%s-%s\" %(sysconfig.get_platform(), sysconfig.get_python_version()))")
  177. LIBAPPARMOR_PATH=../libraries/libapparmor/src/.libs/
  178. LD_LIBRARY_PATH=$(LIBAPPARMOR_PATH):$(PYTHON_DIST_BUILD_PATH)
  179. PYTHONPATH=../utils/:$(PYTHON_DIST_BUILD_PATH)
  180. --- a/utils/Makefile
  181. +++ b/utils/Makefile
  182. @@ -67,6 +67,7 @@ clean: pod_clean
  183. rm -rf staging/ build/
  184. rm -f apparmor/*.pyc apparmor/rule/*.pyc
  185. rm -rf apparmor/__pycache__/ apparmor/rule/__pycache__/
  186. + rm -rf apparmor.egg-info/
  187. # ${CAPABILITIES} is defined in common/Make.rules
  188. .PHONY: check_severity_db
  189. --- a/utils/python-tools-setup.py
  190. +++ b/utils/python-tools-setup.py
  191. @@ -20,14 +20,14 @@
  192. # Note: --version=... must be the last argument to this script
  193. #
  194. -from distutils.command.install import install as _install
  195. -from distutils.core import setup
  196. +from setuptools.command.install import install as _install
  197. +from setuptools import setup
  198. import os
  199. import shutil
  200. import sys
  201. class Install(_install, object):
  202. - '''Override distutils to install the files where we want them.'''
  203. + '''Override setuptools to install the files where we want them.'''
  204. def run(self):
  205. # Now byte-compile everything
  206. super(Install, self).run()
  207. --- a/utils/test/Makefile
  208. +++ b/utils/test/Makefile
  209. @@ -28,7 +28,7 @@ ifdef USE_SYSTEM
  210. PARSER=
  211. else
  212. # PYTHON_DIST_BUILD_PATH based on libapparmor/swig/python/test/Makefile.am
  213. - PYTHON_DIST_BUILD_PATH = ../../libraries/libapparmor/swig/python/build/$$($(PYTHON) -c "import distutils.util; import platform; print(\"lib.%s-%s\" %(distutils.util.get_platform(), platform.python_version()[:3]))")
  214. + PYTHON_DIST_BUILD_PATH = ../../libraries/libapparmor/swig/python/build/$$($(PYTHON) -c "import sysconfig; print(\"lib.%s-%s\" %(sysconfig.get_platform(), sysconfig.get_python_version()))")
  215. LIBAPPARMOR_PATH=../../libraries/libapparmor/src/.libs/
  216. LD_LIBRARY_PATH=$(LIBAPPARMOR_PATH):$(PYTHON_DIST_BUILD_PATH)
  217. PYTHONPATH=..:$(PYTHON_DIST_BUILD_PATH)
  218. --- /dev/null
  219. +++ b/utils/test/README.md
  220. @@ -0,0 +1,18 @@
  221. +# Running individual tests
  222. +
  223. +Python's unittest allows individual tests to be executed by specifying the class name and the test on the command line.
  224. +When running tests individually, the unittest framework executes the "setUp" and "tearDown" methods automatically.
  225. +For more information, refer to the [unittest documentation](https://docs.python.org/3/library/unittest.html).
  226. +
  227. +Make sure to set the environment variables pointing to the in-tree apparmor modules, and the in-tree libapparmor and its python wrapper:
  228. +
  229. +```bash
  230. +$ export PYTHONPATH=..:../../libraries/libapparmor/swig/python/build/$(/usr/bin/python3 -c "import sysconfig; print(\"lib.%s-%s\" %(sysconfig.get_platform(), sysconfig.get_python_version()))")
  231. +$ export __AA_CONFDIR=.
  232. +```
  233. +
  234. +To execute the test individually, run:
  235. +
  236. +```bash
  237. +$ python3 ./test-tile.py ClassFoo.test_bar
  238. +```
  239. \ No newline at end of file