Skip to content

Commit df24fe8

Browse files
rst0gitavagin
authored andcommitted
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] pypa/pip#8221 [2] pypa/pip#8165 (comment) Signed-off-by: Radostin Stoyanov <[email protected]>
1 parent 711775f commit df24fe8

29 files changed

+182
-66
lines changed

Makefile

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ HOSTCFLAGS += $(WARNINGS) $(DEFINES) -iquote include/
164164
export AFLAGS CFLAGS USERCLFAGS HOSTCFLAGS
165165

166166
# Default target
167-
all: flog criu lib
167+
all: flog criu lib crit
168168
.PHONY: all
169169

170170
#
@@ -298,9 +298,9 @@ clean mrproper:
298298
$(Q) $(MAKE) $(build)=criu $@
299299
$(Q) $(MAKE) $(build)=soccr $@
300300
$(Q) $(MAKE) $(build)=lib $@
301+
$(Q) $(MAKE) $(build)=crit $@
301302
$(Q) $(MAKE) $(build)=compel $@
302303
$(Q) $(MAKE) $(build)=compel/plugins $@
303-
$(Q) $(MAKE) $(build)=lib $@
304304
.PHONY: clean mrproper
305305

306306
clean-amdgpu_plugin:
@@ -347,6 +347,10 @@ amdgpu_plugin: criu
347347
$(Q) $(MAKE) -C plugins/amdgpu all
348348
.PHONY: amdgpu_plugin
349349

350+
crit: lib
351+
$(Q) $(MAKE) -C crit
352+
.PHONY: crit
353+
350354
#
351355
# Generating tar requires tag matched CRIU_VERSION.
352356
# If not found then simply use GIT's describe with
@@ -412,6 +416,7 @@ help:
412416
@echo ' Targets:'
413417
@echo ' all - Build all [*] targets'
414418
@echo ' * criu - Build criu'
419+
@echo ' * crit - Build crit'
415420
@echo ' zdtm - Build zdtm test-suite'
416421
@echo ' docs - Build documentation'
417422
@echo ' install - Install CRIU (see INSTALL.md)'
@@ -435,11 +440,12 @@ lint:
435440
flake8 --config=scripts/flake8.cfg test/zdtm.py
436441
flake8 --config=scripts/flake8.cfg test/inhfd/*.py
437442
flake8 --config=scripts/flake8.cfg test/others/rpc/config_file.py
438-
flake8 --config=scripts/flake8.cfg lib/py/images/pb2dict.py
439-
flake8 --config=scripts/flake8.cfg lib/py/images/images.py
443+
flake8 --config=scripts/flake8.cfg lib/pycriu/images/pb2dict.py
444+
flake8 --config=scripts/flake8.cfg lib/pycriu/images/images.py
440445
flake8 --config=scripts/flake8.cfg scripts/criu-ns
441446
flake8 --config=scripts/flake8.cfg test/others/criu-ns/run.py
442-
flake8 --config=scripts/flake8.cfg crit/setup.py
447+
flake8 --config=scripts/flake8.cfg crit/*.py
448+
flake8 --config=scripts/flake8.cfg crit/crit/*.py
443449
flake8 --config=scripts/flake8.cfg scripts/uninstall_module.py
444450
flake8 --config=scripts/flake8.cfg coredump/ coredump/coredump
445451
flake8 --config=scripts/flake8.cfg scripts/github-indent-warnings.py

Makefile.install

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ install-lib: lib
3737
$(Q) $(MAKE) $(build)=lib install
3838
.PHONY: install-lib
3939

40+
install-crit: lib
41+
$(Q) $(MAKE) $(build)=crit install
42+
.PHONY: install-crit
43+
4044
install-criu: criu
4145
$(Q) $(MAKE) $(build)=criu install
4246
.PHONY: install-criu
@@ -50,12 +54,13 @@ install-compel: $(compel-install-targets)
5054
$(Q) $(MAKE) $(build)=compel/plugins install
5155
.PHONY: install-compel
5256

53-
install: install-man install-lib install-criu install-compel install-amdgpu_plugin ;
57+
install: install-man install-lib install-crit install-criu install-compel install-amdgpu_plugin ;
5458
.PHONY: install
5559

5660
uninstall:
5761
$(Q) $(MAKE) -C Documentation $@
5862
$(Q) $(MAKE) $(build)=lib $@
63+
$(Q) $(MAKE) $(build)=crit $@
5964
$(Q) $(MAKE) $(build)=criu $@
6065
$(Q) $(MAKE) $(build)=compel $@
6166
$(Q) $(MAKE) $(build)=compel/plugins $@

coredump/pycriu

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
../lib/py/
1+
../lib/pycriu

crit/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
crit.egg-info/
22
build/
3+
dist/
4+
version.py

crit/Makefile

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
PYTHON_EXTERNALLY_MANAGED := $(shell $(PYTHON) -c 'import os, sysconfig; print(int(os.path.isfile(os.path.join(sysconfig.get_path("stdlib"), "EXTERNALLY-MANAGED"))))')
2+
PIP_BREAK_SYSTEM_PACKAGES := 0
3+
4+
VERSION_FILE := $(if $(obj),$(addprefix $(obj)/,crit/version.py),crit/version.py)
5+
6+
all-y += ${VERSION_FILE}
7+
cleanup-y += ${VERSION_FILE}
8+
9+
${VERSION_FILE}:
10+
$(Q) echo "__version__ = '${CRIU_VERSION}'" > $@
11+
12+
install: ${VERSION_FILE}
13+
ifeq ($(PYTHON_EXTERNALLY_MANAGED),1)
14+
ifeq ($(PIP_BREAK_SYSTEM_PACKAGES),0)
15+
$(E) " SKIP INSTALL crit: Externally managed python environment (See PEP 668 for more information)"
16+
$(E) " Consider using PIP_BREAK_SYSTEM_PACKAGES=1 make install"
17+
else
18+
$(E) " INSTALL " crit
19+
$(Q) $(PYTHON) -m pip install --upgrade --ignore-installed --prefix=$(DESTDIR)$(PREFIX) ./crit
20+
endif
21+
else
22+
$(E) " INSTALL " crit
23+
$(Q) $(PYTHON) -m pip install --upgrade --ignore-installed --prefix=$(DESTDIR)$(PREFIX) ./crit
24+
endif
25+
.PHONY: install
26+
27+
uninstall:
28+
ifeq ($(PYTHON_EXTERNALLY_MANAGED),1)
29+
ifeq ($(PIP_BREAK_SYSTEM_PACKAGES),0)
30+
$(E) " SKIP UNINSTALL crit: Externally managed python environment (See PEP 668 for more information)"
31+
$(E) " Consider using PIP_BREAK_SYSTEM_PACKAGES=1 make uninstall"
32+
else
33+
$(E) " UNINSTALL" crit
34+
$(Q) $(PYTHON) ./scripts/uninstall_module.py --prefix=$(DESTDIR)$(PREFIX) crit
35+
endif
36+
else
37+
$(E) " UNINSTALL" crit
38+
$(Q) $(PYTHON) ./scripts/uninstall_module.py --prefix=$(DESTDIR)$(PREFIX) crit
39+
endif
40+
.PHONY: uninstall

crit/crit/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from .version import __version__

lib/py/cli.py renamed to crit/crit/__main__.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import os
66

77
import pycriu
8+
from . import __version__
89

910

1011
def inf(opts):
@@ -41,9 +42,9 @@ def decode(opts):
4142
try:
4243
img = pycriu.images.load(inf(opts), opts['pretty'], opts['nopl'])
4344
except pycriu.images.MagicException as exc:
44-
print("Unknown magic %#x.\n"\
45-
"Maybe you are feeding me an image with "\
46-
"raw data(i.e. pages.img)?" % exc.magic, file=sys.stderr)
45+
print("Unknown magic %#x.\n"
46+
"Maybe you are feeding me an image with "
47+
"raw data(i.e. pages.img)?" % exc.magic, file=sys.stderr)
4748
sys.exit(1)
4849

4950
if opts['pretty']:
@@ -59,9 +60,9 @@ def encode(opts):
5960
try:
6061
img = json.load(inf(opts))
6162
except UnicodeDecodeError:
62-
print("Cannot read JSON.\n"\
63-
"Maybe you are feeding me an image with protobuf data? "\
64-
"Encode expects JSON input.", file=sys.stderr)
63+
print("Cannot read JSON.\n"
64+
"Maybe you are feeding me an image with protobuf data? "
65+
"Encode expects JSON input.", file=sys.stderr)
6566
sys.exit(1)
6667
pycriu.images.dump(img, outf(opts, False))
6768

@@ -131,7 +132,7 @@ def ftype_find_in_files(opts, ft, fid):
131132
if files_img is None:
132133
try:
133134
files_img = pycriu.images.load(dinf(opts, "files.img"))['entries']
134-
except:
135+
except Exception:
135136
files_img = []
136137

137138
if len(files_img) == 0:
@@ -364,7 +365,7 @@ def main():
364365
desc = 'CRiu Image Tool'
365366
parser = argparse.ArgumentParser(
366367
description=desc, formatter_class=argparse.RawTextHelpFormatter)
367-
parser.add_argument('--version', action='version', version=pycriu.__version__)
368+
parser.add_argument('--version', action='version', version=__version__)
368369

369370
subparsers = parser.add_subparsers(
370371
help='Use crit CMD --help for command-specific help')
@@ -374,8 +375,7 @@ def main():
374375
'decode', help='convert criu image from binary type to json')
375376
decode_parser.add_argument(
376377
'--pretty',
377-
help=
378-
'Multiline with indents and some numerical fields in field-specific format',
378+
help='Multiline with indents and some numerical fields in field-specific format',
379379
action='store_true')
380380
decode_parser.add_argument(
381381
'-i',

crit/pycriu

Lines changed: 0 additions & 1 deletion
This file was deleted.

crit/pyproject.toml

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
11
[build-system]
2-
# Minimum requirements for the build system to execute.
3-
requires = ["setuptools", "wheel"] # PEP 508 specifications.
2+
requires = ["setuptools"]
3+
build-backend = "setuptools.build_meta"
4+
5+
[project]
6+
name = "crit"
7+
description = "CRiu Image Tool"
8+
authors = [
9+
{name = "CRIU team", email = "[email protected]"},
10+
]
11+
license = {text = "GPLv2"}
12+
dynamic = ["version"]
13+
requires-python = ">=3.6"
14+
15+
[project.scripts]
16+
crit = "crit.__main__:main"
17+
18+
[tool.setuptools]
19+
packages = ["crit"]
20+
21+
[tool.setuptools.dynamic]
22+
version = {attr = "crit.__version__"}

crit/requirements.txt

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)