2
0
mirror of https://github.com/checkpoint-restore/criu synced 2025-08-22 01:51:51 +00:00

lib: use separate packages for pycriu and crit

Newer versions of pip use an isolated virtual environment when building
Python projects. However, when the source code of CRIT is copied into
the isolated environment, the symlink for `../lib/py` (pycriu) becomes
invalid. As a workaround, we used the `--no-build-isolation` option for
`pip install`. However, this functionality has issues in some versions
of PIP [1, 2]. To fix this problem, this patch adds separate packages
for pycriu and crit, and each package is installed independently.

[1] https://github.com/pypa/pip/pull/8221
[2] https://github.com/pypa/pip/issues/8165#issuecomment-625401463

Signed-off-by: Radostin Stoyanov <rstoyanov@fedoraproject.org>
This commit is contained in:
Radostin Stoyanov 2023-10-09 15:55:25 +01:00 committed by Andrei Vagin
parent 97b8b659c9
commit 0b62f4267a
29 changed files with 182 additions and 66 deletions

View File

@ -164,7 +164,7 @@ HOSTCFLAGS += $(WARNINGS) $(DEFINES) -iquote include/
export AFLAGS CFLAGS USERCLFAGS HOSTCFLAGS export AFLAGS CFLAGS USERCLFAGS HOSTCFLAGS
# Default target # Default target
all: criu lib all: criu lib crit
.PHONY: all .PHONY: all
# #
@ -288,9 +288,9 @@ clean mrproper:
$(Q) $(MAKE) $(build)=criu $@ $(Q) $(MAKE) $(build)=criu $@
$(Q) $(MAKE) $(build)=soccr $@ $(Q) $(MAKE) $(build)=soccr $@
$(Q) $(MAKE) $(build)=lib $@ $(Q) $(MAKE) $(build)=lib $@
$(Q) $(MAKE) $(build)=crit $@
$(Q) $(MAKE) $(build)=compel $@ $(Q) $(MAKE) $(build)=compel $@
$(Q) $(MAKE) $(build)=compel/plugins $@ $(Q) $(MAKE) $(build)=compel/plugins $@
$(Q) $(MAKE) $(build)=lib $@
.PHONY: clean mrproper .PHONY: clean mrproper
clean-amdgpu_plugin: clean-amdgpu_plugin:
@ -337,6 +337,10 @@ amdgpu_plugin: criu
$(Q) $(MAKE) -C plugins/amdgpu all $(Q) $(MAKE) -C plugins/amdgpu all
.PHONY: amdgpu_plugin .PHONY: amdgpu_plugin
crit: lib
$(Q) $(MAKE) -C crit
.PHONY: crit
# #
# Generating tar requires tag matched CRIU_VERSION. # Generating tar requires tag matched CRIU_VERSION.
# If not found then simply use GIT's describe with # If not found then simply use GIT's describe with
@ -402,6 +406,7 @@ help:
@echo ' Targets:' @echo ' Targets:'
@echo ' all - Build all [*] targets' @echo ' all - Build all [*] targets'
@echo ' * criu - Build criu' @echo ' * criu - Build criu'
@echo ' * crit - Build crit'
@echo ' zdtm - Build zdtm test-suite' @echo ' zdtm - Build zdtm test-suite'
@echo ' docs - Build documentation' @echo ' docs - Build documentation'
@echo ' install - Install CRIU (see INSTALL.md)' @echo ' install - Install CRIU (see INSTALL.md)'
@ -425,11 +430,12 @@ lint:
flake8 --config=scripts/flake8.cfg test/zdtm.py flake8 --config=scripts/flake8.cfg test/zdtm.py
flake8 --config=scripts/flake8.cfg test/inhfd/*.py flake8 --config=scripts/flake8.cfg test/inhfd/*.py
flake8 --config=scripts/flake8.cfg test/others/rpc/config_file.py flake8 --config=scripts/flake8.cfg test/others/rpc/config_file.py
flake8 --config=scripts/flake8.cfg lib/py/images/pb2dict.py flake8 --config=scripts/flake8.cfg lib/pycriu/images/pb2dict.py
flake8 --config=scripts/flake8.cfg lib/py/images/images.py flake8 --config=scripts/flake8.cfg lib/pycriu/images/images.py
flake8 --config=scripts/flake8.cfg scripts/criu-ns flake8 --config=scripts/flake8.cfg scripts/criu-ns
flake8 --config=scripts/flake8.cfg test/others/criu-ns/run.py flake8 --config=scripts/flake8.cfg test/others/criu-ns/run.py
flake8 --config=scripts/flake8.cfg crit/setup.py flake8 --config=scripts/flake8.cfg crit/*.py
flake8 --config=scripts/flake8.cfg crit/crit/*.py
flake8 --config=scripts/flake8.cfg scripts/uninstall_module.py flake8 --config=scripts/flake8.cfg scripts/uninstall_module.py
flake8 --config=scripts/flake8.cfg coredump/ coredump/coredump flake8 --config=scripts/flake8.cfg coredump/ coredump/coredump
flake8 --config=scripts/flake8.cfg scripts/github-indent-warnings.py flake8 --config=scripts/flake8.cfg scripts/github-indent-warnings.py

View File

@ -37,6 +37,10 @@ install-lib: lib
$(Q) $(MAKE) $(build)=lib install $(Q) $(MAKE) $(build)=lib install
.PHONY: install-lib .PHONY: install-lib
install-crit: lib
$(Q) $(MAKE) $(build)=crit install
.PHONY: install-crit
install-criu: criu install-criu: criu
$(Q) $(MAKE) $(build)=criu install $(Q) $(MAKE) $(build)=criu install
.PHONY: install-criu .PHONY: install-criu
@ -50,12 +54,13 @@ install-compel: $(compel-install-targets)
$(Q) $(MAKE) $(build)=compel/plugins install $(Q) $(MAKE) $(build)=compel/plugins install
.PHONY: install-compel .PHONY: install-compel
install: install-man install-lib install-criu install-compel install-amdgpu_plugin ; install: install-man install-lib install-crit install-criu install-compel install-amdgpu_plugin ;
.PHONY: install .PHONY: install
uninstall: uninstall:
$(Q) $(MAKE) -C Documentation $@ $(Q) $(MAKE) -C Documentation $@
$(Q) $(MAKE) $(build)=lib $@ $(Q) $(MAKE) $(build)=lib $@
$(Q) $(MAKE) $(build)=crit $@
$(Q) $(MAKE) $(build)=criu $@ $(Q) $(MAKE) $(build)=criu $@
$(Q) $(MAKE) $(build)=compel $@ $(Q) $(MAKE) $(build)=compel $@
$(Q) $(MAKE) $(build)=compel/plugins $@ $(Q) $(MAKE) $(build)=compel/plugins $@

View File

@ -1 +1 @@
../lib/py/ ../lib/pycriu

2
crit/.gitignore vendored
View File

@ -1,2 +1,4 @@
crit.egg-info/ crit.egg-info/
build/ build/
dist/
version.py

40
crit/Makefile Normal file
View File

@ -0,0 +1,40 @@
PYTHON_EXTERNALLY_MANAGED := $(shell $(PYTHON) -c 'import os, sysconfig; print(int(os.path.isfile(os.path.join(sysconfig.get_path("stdlib"), "EXTERNALLY-MANAGED"))))')
PIP_BREAK_SYSTEM_PACKAGES := 0
VERSION_FILE := $(if $(obj),$(addprefix $(obj)/,crit/version.py),crit/version.py)
all-y += ${VERSION_FILE}
cleanup-y += ${VERSION_FILE}
${VERSION_FILE}:
$(Q) echo "__version__ = '${CRIU_VERSION}'" > $@
install: ${VERSION_FILE}
ifeq ($(PYTHON_EXTERNALLY_MANAGED),1)
ifeq ($(PIP_BREAK_SYSTEM_PACKAGES),0)
$(E) " SKIP INSTALL crit: Externally managed python environment (See PEP 668 for more information)"
$(E) " Consider using PIP_BREAK_SYSTEM_PACKAGES=1 make install"
else
$(E) " INSTALL " crit
$(Q) $(PYTHON) -m pip install --upgrade --ignore-installed --prefix=$(DESTDIR)$(PREFIX) ./crit
endif
else
$(E) " INSTALL " crit
$(Q) $(PYTHON) -m pip install --upgrade --ignore-installed --prefix=$(DESTDIR)$(PREFIX) ./crit
endif
.PHONY: install
uninstall:
ifeq ($(PYTHON_EXTERNALLY_MANAGED),1)
ifeq ($(PIP_BREAK_SYSTEM_PACKAGES),0)
$(E) " SKIP UNINSTALL crit: Externally managed python environment (See PEP 668 for more information)"
$(E) " Consider using PIP_BREAK_SYSTEM_PACKAGES=1 make uninstall"
else
$(E) " UNINSTALL" crit
$(Q) $(PYTHON) ./scripts/uninstall_module.py --prefix=$(DESTDIR)$(PREFIX) crit
endif
else
$(E) " UNINSTALL" crit
$(Q) $(PYTHON) ./scripts/uninstall_module.py --prefix=$(DESTDIR)$(PREFIX) crit
endif
.PHONY: uninstall

1
crit/crit/__init__.py Normal file
View File

@ -0,0 +1 @@
from .version import __version__

View File

@ -5,6 +5,7 @@ import json
import os import os
import pycriu import pycriu
from . import __version__
def inf(opts): def inf(opts):
@ -41,8 +42,8 @@ def decode(opts):
try: try:
img = pycriu.images.load(inf(opts), opts['pretty'], opts['nopl']) img = pycriu.images.load(inf(opts), opts['pretty'], opts['nopl'])
except pycriu.images.MagicException as exc: except pycriu.images.MagicException as exc:
print("Unknown magic %#x.\n"\ print("Unknown magic %#x.\n"
"Maybe you are feeding me an image with "\ "Maybe you are feeding me an image with "
"raw data(i.e. pages.img)?" % exc.magic, file=sys.stderr) "raw data(i.e. pages.img)?" % exc.magic, file=sys.stderr)
sys.exit(1) sys.exit(1)
@ -59,8 +60,8 @@ def encode(opts):
try: try:
img = json.load(inf(opts)) img = json.load(inf(opts))
except UnicodeDecodeError: except UnicodeDecodeError:
print("Cannot read JSON.\n"\ print("Cannot read JSON.\n"
"Maybe you are feeding me an image with protobuf data? "\ "Maybe you are feeding me an image with protobuf data? "
"Encode expects JSON input.", file=sys.stderr) "Encode expects JSON input.", file=sys.stderr)
sys.exit(1) sys.exit(1)
pycriu.images.dump(img, outf(opts, False)) pycriu.images.dump(img, outf(opts, False))
@ -131,7 +132,7 @@ def ftype_find_in_files(opts, ft, fid):
if files_img is None: if files_img is None:
try: try:
files_img = pycriu.images.load(dinf(opts, "files.img"))['entries'] files_img = pycriu.images.load(dinf(opts, "files.img"))['entries']
except: except Exception:
files_img = [] files_img = []
if len(files_img) == 0: if len(files_img) == 0:
@ -364,7 +365,7 @@ def main():
desc = 'CRiu Image Tool' desc = 'CRiu Image Tool'
parser = argparse.ArgumentParser( parser = argparse.ArgumentParser(
description=desc, formatter_class=argparse.RawTextHelpFormatter) description=desc, formatter_class=argparse.RawTextHelpFormatter)
parser.add_argument('--version', action='version', version=pycriu.__version__) parser.add_argument('--version', action='version', version=__version__)
subparsers = parser.add_subparsers( subparsers = parser.add_subparsers(
help='Use crit CMD --help for command-specific help') help='Use crit CMD --help for command-specific help')
@ -374,8 +375,7 @@ def main():
'decode', help='convert criu image from binary type to json') 'decode', help='convert criu image from binary type to json')
decode_parser.add_argument( decode_parser.add_argument(
'--pretty', '--pretty',
help= help='Multiline with indents and some numerical fields in field-specific format',
'Multiline with indents and some numerical fields in field-specific format',
action='store_true') action='store_true')
decode_parser.add_argument( decode_parser.add_argument(
'-i', '-i',

View File

@ -1 +0,0 @@
../lib/py/

View File

@ -1,3 +1,22 @@
[build-system] [build-system]
# Minimum requirements for the build system to execute. requires = ["setuptools"]
requires = ["setuptools", "wheel"] # PEP 508 specifications. build-backend = "setuptools.build_meta"
[project]
name = "crit"
description = "CRiu Image Tool"
authors = [
{name = "CRIU team", email = "criu@openvz.org"},
]
license = {text = "GPLv2"}
dynamic = ["version"]
requires-python = ">=3.6"
[project.scripts]
crit = "crit.__main__:main"
[tool.setuptools]
packages = ["crit"]
[tool.setuptools.dynamic]
version = {attr = "crit.__version__"}

View File

@ -1,7 +0,0 @@
# We need pip version 20.1 or newer to correctly build with 'pycriu' symlink.
# - Building of local directories with pip 20.1 or newer is done in place,
# instead of a temporary location containing a copy of the directory tree.
# (https://github.com/pypa/pip/issues/7555)
pip>=20.1
setuptools>=42.0.0
wheel

20
crit/setup.cfg Normal file
View File

@ -0,0 +1,20 @@
# Configuring setuptools using pyproject.toml files was introduced in setuptools 61.0.0
# https://setuptools.pypa.io/en/latest/history.html#v61-0-0
# For older versions of setuptools, we need to use the setup.cfg file
# https://setuptools.pypa.io/en/latest/userguide/declarative_config.html#declarative-config
[metadata]
name = crit
description = CRiu Image Tool
author = CRIU team
author_email = criu@openvz.org
license = GPLv2
version = attr: crit.__version__
[options]
packages = crit
python_requires = >=3.6
[options.entry_points]
console_scripts =
crit = crit.__main__:main

View File

@ -1,15 +1,6 @@
from setuptools import setup, find_packages #!/usr/bin/env python3
import pycriu import setuptools
setup(
name='crit', if __name__ == '__main__':
version=pycriu.__version__, setuptools.setup()
description='CRiu Image Tool',
author='CRIU team',
author_email='criu@openvz.org',
license='GPLv2',
url='https://github.com/checkpoint-restore/criu',
packages=find_packages('.'),
scripts=['crit'],
install_requires=[],
)

1
lib/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
pycriu.egg-info/

View File

@ -28,17 +28,17 @@ lib-a: lib/c/$(CRIU_A)
# #
# Python bindings. # Python bindings.
lib/py/Makefile: ; lib/pycriu/Makefile: ;
lib/py/%: .FORCE lib/pycriu/%: .FORCE
$(call msg-gen, $@) $(call msg-gen, $@)
$(Q) $(MAKE) $(build)=lib/py $@ $(Q) $(MAKE) $(build)=lib/pycriu $@
lib-py: lib-py:
$(Q) $(MAKE) $(build)=lib/py all $(Q) $(MAKE) $(build)=lib/pycriu all
.PHONY: lib-py .PHONY: lib-py
clean-lib: clean-lib:
$(Q) $(MAKE) $(build)=lib/c clean $(Q) $(MAKE) $(build)=lib/c clean
$(Q) $(MAKE) $(build)=lib/py clean $(Q) $(MAKE) $(build)=lib/pycriu clean
.PHONY: clean-lib .PHONY: clean-lib
clean: clean-lib clean: clean-lib
cleanup-y += lib/c/$(CRIU_SO) lib/c/$(CRIU_A) lib/c/criu.pc cleanup-y += lib/c/$(CRIU_SO) lib/c/$(CRIU_A) lib/c/criu.pc
@ -59,17 +59,15 @@ install: lib-c lib-a lib-py lib/c/criu.pc.in
$(Q) install -m 644 lib/c/criu.pc $(DESTDIR)$(LIBDIR)/pkgconfig $(Q) install -m 644 lib/c/criu.pc $(DESTDIR)$(LIBDIR)/pkgconfig
ifeq ($(PYTHON_EXTERNALLY_MANAGED),1) ifeq ($(PYTHON_EXTERNALLY_MANAGED),1)
ifeq ($(PIP_BREAK_SYSTEM_PACKAGES),0) ifeq ($(PIP_BREAK_SYSTEM_PACKAGES),0)
$(E) " SKIP INSTALL crit: Externally managed python environment (See PEP 668 for more information)" $(E) " SKIP INSTALL pycriu: Externally managed python environment (See PEP 668 for more information)"
$(E) " Consider using PIP_BREAK_SYSTEM_PACKAGES=1 make install" $(E) " Consider using PIP_BREAK_SYSTEM_PACKAGES=1 make install"
else else
$(E) " INSTALL " crit $(E) " INSTALL " pycriu
$(Q) $(PYTHON) -m pip install -r ./crit/requirements.txt $(Q) $(PYTHON) -m pip install --upgrade --ignore-installed --prefix=$(DESTDIR)$(PREFIX) ./lib
$(Q) $(PYTHON) -m pip install --no-build-isolation --upgrade --ignore-installed --prefix=$(DESTDIR)$(PREFIX) ./crit
endif endif
else else
$(E) " INSTALL " crit $(E) " INSTALL " pycriu
$(Q) $(PYTHON) -m pip install -r ./crit/requirements.txt $(Q) $(PYTHON) -m pip install --upgrade --ignore-installed --prefix=$(DESTDIR)$(PREFIX) ./lib
$(Q) $(PYTHON) -m pip install --no-build-isolation --upgrade --ignore-installed --prefix=$(DESTDIR)$(PREFIX) ./crit
endif endif
.PHONY: install .PHONY: install
@ -84,14 +82,14 @@ uninstall:
$(Q) $(RM) $(addprefix $(DESTDIR)$(LIBDIR)/pkgconfig/,criu.pc) $(Q) $(RM) $(addprefix $(DESTDIR)$(LIBDIR)/pkgconfig/,criu.pc)
ifeq ($(PYTHON_EXTERNALLY_MANAGED),1) ifeq ($(PYTHON_EXTERNALLY_MANAGED),1)
ifeq ($(PIP_BREAK_SYSTEM_PACKAGES),0) ifeq ($(PIP_BREAK_SYSTEM_PACKAGES),0)
$(E) " SKIP UNINSTALL crit: Externally managed python environment (See PEP 668 for more information)" $(E) " SKIP UNINSTALL pycriu: Externally managed python environment (See PEP 668 for more information)"
$(E) " Consider using PIP_BREAK_SYSTEM_PACKAGES=1 make uninstall" $(E) " Consider using PIP_BREAK_SYSTEM_PACKAGES=1 make uninstall"
else else
$(E) " UNINSTALL" crit $(E) " UNINSTALL" pycriu
$(Q) $(PYTHON) ./scripts/uninstall_module.py --prefix=$(DESTDIR)$(PREFIX) crit $(Q) $(PYTHON) ./scripts/uninstall_module.py --prefix=$(DESTDIR)$(PREFIX) pycriu
endif endif
else else
$(E) " UNINSTALL" crit $(E) " UNINSTALL" pycriu
$(Q) $(PYTHON) ./scripts/uninstall_module.py --prefix=$(DESTDIR)$(PREFIX) crit $(Q) $(PYTHON) ./scripts/uninstall_module.py --prefix=$(DESTDIR)$(PREFIX) pycriu
endif endif
.PHONY: uninstall .PHONY: uninstall

View File

@ -1,3 +1,4 @@
__pycache__
*_pb2.py *_pb2.py
*.pyc *.pyc
version.py version.py

19
lib/pyproject.toml Normal file
View File

@ -0,0 +1,19 @@
[build-system]
requires = ["setuptools", "protobuf<4.0"]
build-backend = "setuptools.build_meta"
[project]
name = "pycriu"
description = "Python bindings for CRIU"
authors = [
{name = "CRIU team", email = "criu@openvz.org"},
]
license = {text = "GPLv2"}
dynamic = ["version"]
requires-python = ">=3.6"
[tool.setuptools]
packages = ["pycriu", "pycriu.images"]
[tool.setuptools.dynamic]
version = {attr = "pycriu.__version__"}

16
lib/setup.cfg Normal file
View File

@ -0,0 +1,16 @@
# Configuring setuptools using pyproject.toml files was introduced in setuptools 61.0.0
# https://setuptools.pypa.io/en/latest/history.html#v61-0-0
# For older versions of setuptools, we need to use the setup.cfg file
# https://setuptools.pypa.io/en/latest/userguide/declarative_config.html#declarative-config
[metadata]
name = pycriu
description = Python bindings for CRIU
author = CRIU team
author_email = criu@openvz.org
license = GPLv2
version = attr: pycriu.__version__
[options]
packages = find:
python_requires = >=3.6

4
crit/crit → lib/setup.py Executable file → Normal file
View File

@ -1,6 +1,6 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import setuptools
from pycriu import cli
if __name__ == '__main__': if __name__ == '__main__':
cli.main() setuptools.setup()

View File

@ -1,8 +1,13 @@
#!/bin/sh #!/bin/sh
CRIU=$(readlink -f `dirname ${BASH_SOURCE[0]}`/../../criu/criu) BASE_DIR="$(readlink -f "$(dirname "${BASH_SOURCE[0]}")/../../")"
CRIU="${BASE_DIR}/criu/criu"
criu=$CRIU criu=$CRIU
CRIT=$(readlink -f `dirname ${BASH_SOURCE[0]}`/../../crit/crit)
export PYTHONPATH="${BASE_DIR}/lib:${BASE_DIR}/crit:${PYTHONPATH-}"
CRIT="python3 -m crit"
crit=$CRIT crit=$CRIT
CRIU_COREDUMP=$(readlink -f `dirname ${BASH_SOURCE[0]}`/../../coredump/coredump)
CRIU_COREDUMP="${BASE_DIR}/coredump/coredump"
criu_coredump=$CRIU_COREDUMP criu_coredump=$CRIU_COREDUMP

View File

@ -1 +1 @@
../lib/py/ ../lib/pycriu

View File

@ -1,7 +1,7 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import sys import sys
sys.path.append("../crit") sys.path.append("../lib")
import pycriu import pycriu
import os, os.path import os, os.path