diff options
author | Fredrik Gustafsson <fredrik.gustafsson@axis.com> | 2020-07-24 16:42:33 +0200 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2020-07-27 19:58:10 +0100 |
commit | b8d3d22ccdd3c61d9aab8c39ce13afeccb5dea56 (patch) | |
tree | 7a339b47896709f8b745302e3337dfcc9be7408b /meta | |
parent | 9129dfe523488b61c711dde5cd46328d39e4c368 (diff) | |
download | poky-b8d3d22ccdd3c61d9aab8c39ce13afeccb5dea56.tar.gz |
rpm: Move rootfs to its own dir
This is a part of a refactor that will split the package manager
code so that it's possible to use other package managers in other
layers.
(From OE-Core rev: e4f07444276a88f336d5fe5e60688fcfb2f22df7)
Signed-off-by: Fredrik Gustafsson <fredrigu@axis.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta')
-rw-r--r-- | meta/lib/oe/package_manager/rpm/rootfs.py | 148 | ||||
-rw-r--r-- | meta/lib/oe/rootfs.py | 142 |
2 files changed, 150 insertions, 140 deletions
diff --git a/meta/lib/oe/package_manager/rpm/rootfs.py b/meta/lib/oe/package_manager/rpm/rootfs.py new file mode 100644 index 0000000000..3d9eb95528 --- /dev/null +++ b/meta/lib/oe/package_manager/rpm/rootfs.py | |||
@@ -0,0 +1,148 @@ | |||
1 | # | ||
2 | # SPDX-License-Identifier: GPL-2.0-only | ||
3 | # | ||
4 | |||
5 | from oe.rootfs import Rootfs | ||
6 | from oe.package_manager import RpmPM | ||
7 | from oe.manifest import Manifest | ||
8 | from oe.utils import execute_pre_post_process | ||
9 | from oe.package_manager.rpm.manifest import RpmManifest | ||
10 | |||
11 | class RpmRootfs(Rootfs): | ||
12 | def __init__(self, d, manifest_dir, progress_reporter=None, logcatcher=None): | ||
13 | super(RpmRootfs, self).__init__(d, progress_reporter, logcatcher) | ||
14 | self.log_check_regex = r'(unpacking of archive failed|Cannot find package'\ | ||
15 | r'|exit 1|ERROR: |Error: |Error |ERROR '\ | ||
16 | r'|Failed |Failed: |Failed$|Failed\(\d+\):)' | ||
17 | |||
18 | self.manifest = RpmManifest(d, manifest_dir) | ||
19 | |||
20 | self.pm = RpmPM(d, | ||
21 | d.getVar('IMAGE_ROOTFS'), | ||
22 | self.d.getVar('TARGET_VENDOR') | ||
23 | ) | ||
24 | |||
25 | self.inc_rpm_image_gen = self.d.getVar('INC_RPM_IMAGE_GEN') | ||
26 | if self.inc_rpm_image_gen != "1": | ||
27 | bb.utils.remove(self.image_rootfs, True) | ||
28 | else: | ||
29 | self.pm.recovery_packaging_data() | ||
30 | bb.utils.remove(self.d.getVar('MULTILIB_TEMP_ROOTFS'), True) | ||
31 | |||
32 | self.pm.create_configs() | ||
33 | |||
34 | ''' | ||
35 | While rpm incremental image generation is enabled, it will remove the | ||
36 | unneeded pkgs by comparing the new install solution manifest and the | ||
37 | old installed manifest. | ||
38 | ''' | ||
39 | def _create_incremental(self, pkgs_initial_install): | ||
40 | if self.inc_rpm_image_gen == "1": | ||
41 | |||
42 | pkgs_to_install = list() | ||
43 | for pkg_type in pkgs_initial_install: | ||
44 | pkgs_to_install += pkgs_initial_install[pkg_type] | ||
45 | |||
46 | installed_manifest = self.pm.load_old_install_solution() | ||
47 | solution_manifest = self.pm.dump_install_solution(pkgs_to_install) | ||
48 | |||
49 | pkg_to_remove = list() | ||
50 | for pkg in installed_manifest: | ||
51 | if pkg not in solution_manifest: | ||
52 | pkg_to_remove.append(pkg) | ||
53 | |||
54 | self.pm.update() | ||
55 | |||
56 | bb.note('incremental update -- upgrade packages in place ') | ||
57 | self.pm.upgrade() | ||
58 | if pkg_to_remove != []: | ||
59 | bb.note('incremental removed: %s' % ' '.join(pkg_to_remove)) | ||
60 | self.pm.remove(pkg_to_remove) | ||
61 | |||
62 | self.pm.autoremove() | ||
63 | |||
64 | def _create(self): | ||
65 | pkgs_to_install = self.manifest.parse_initial_manifest() | ||
66 | rpm_pre_process_cmds = self.d.getVar('RPM_PREPROCESS_COMMANDS') | ||
67 | rpm_post_process_cmds = self.d.getVar('RPM_POSTPROCESS_COMMANDS') | ||
68 | |||
69 | # update PM index files | ||
70 | self.pm.write_index() | ||
71 | |||
72 | execute_pre_post_process(self.d, rpm_pre_process_cmds) | ||
73 | |||
74 | if self.progress_reporter: | ||
75 | self.progress_reporter.next_stage() | ||
76 | |||
77 | if self.inc_rpm_image_gen == "1": | ||
78 | self._create_incremental(pkgs_to_install) | ||
79 | |||
80 | if self.progress_reporter: | ||
81 | self.progress_reporter.next_stage() | ||
82 | |||
83 | self.pm.update() | ||
84 | |||
85 | pkgs = [] | ||
86 | pkgs_attempt = [] | ||
87 | for pkg_type in pkgs_to_install: | ||
88 | if pkg_type == Manifest.PKG_TYPE_ATTEMPT_ONLY: | ||
89 | pkgs_attempt += pkgs_to_install[pkg_type] | ||
90 | else: | ||
91 | pkgs += pkgs_to_install[pkg_type] | ||
92 | |||
93 | if self.progress_reporter: | ||
94 | self.progress_reporter.next_stage() | ||
95 | |||
96 | self.pm.install(pkgs) | ||
97 | |||
98 | if self.progress_reporter: | ||
99 | self.progress_reporter.next_stage() | ||
100 | |||
101 | self.pm.install(pkgs_attempt, True) | ||
102 | |||
103 | if self.progress_reporter: | ||
104 | self.progress_reporter.next_stage() | ||
105 | |||
106 | self.pm.install_complementary() | ||
107 | |||
108 | if self.progress_reporter: | ||
109 | self.progress_reporter.next_stage() | ||
110 | |||
111 | self._setup_dbg_rootfs(['/etc', '/var/lib/rpm', '/var/cache/dnf', '/var/lib/dnf']) | ||
112 | |||
113 | execute_pre_post_process(self.d, rpm_post_process_cmds) | ||
114 | |||
115 | if self.inc_rpm_image_gen == "1": | ||
116 | self.pm.backup_packaging_data() | ||
117 | |||
118 | if self.progress_reporter: | ||
119 | self.progress_reporter.next_stage() | ||
120 | |||
121 | |||
122 | @staticmethod | ||
123 | def _depends_list(): | ||
124 | return ['DEPLOY_DIR_RPM', 'INC_RPM_IMAGE_GEN', 'RPM_PREPROCESS_COMMANDS', | ||
125 | 'RPM_POSTPROCESS_COMMANDS', 'RPM_PREFER_ELF_ARCH'] | ||
126 | |||
127 | def _get_delayed_postinsts(self): | ||
128 | postinst_dir = self.d.expand("${IMAGE_ROOTFS}${sysconfdir}/rpm-postinsts") | ||
129 | if os.path.isdir(postinst_dir): | ||
130 | files = os.listdir(postinst_dir) | ||
131 | for f in files: | ||
132 | bb.note('Delayed package scriptlet: %s' % f) | ||
133 | return files | ||
134 | |||
135 | return None | ||
136 | |||
137 | def _save_postinsts(self): | ||
138 | # this is just a stub. For RPM, the failed postinstalls are | ||
139 | # already saved in /etc/rpm-postinsts | ||
140 | pass | ||
141 | |||
142 | def _log_check(self): | ||
143 | self._log_check_warn() | ||
144 | self._log_check_error() | ||
145 | |||
146 | def _cleanup(self): | ||
147 | if bb.utils.contains("IMAGE_FEATURES", "package-management", True, False, self.d): | ||
148 | self.pm._invoke_dnf(["clean", "all"]) | ||
diff --git a/meta/lib/oe/rootfs.py b/meta/lib/oe/rootfs.py index 876e13079c..4895f1ebb9 100644 --- a/meta/lib/oe/rootfs.py +++ b/meta/lib/oe/rootfs.py | |||
@@ -355,146 +355,6 @@ class Rootfs(object, metaclass=ABCMeta): | |||
355 | self.image_rootfs, "-D", devtable]) | 355 | self.image_rootfs, "-D", devtable]) |
356 | 356 | ||
357 | 357 | ||
358 | class RpmRootfs(Rootfs): | ||
359 | def __init__(self, d, manifest_dir, progress_reporter=None, logcatcher=None): | ||
360 | super(RpmRootfs, self).__init__(d, progress_reporter, logcatcher) | ||
361 | self.log_check_regex = r'(unpacking of archive failed|Cannot find package'\ | ||
362 | r'|exit 1|ERROR: |Error: |Error |ERROR '\ | ||
363 | r'|Failed |Failed: |Failed$|Failed\(\d+\):)' | ||
364 | |||
365 | self.manifest = RpmManifest(d, manifest_dir) | ||
366 | |||
367 | self.pm = RpmPM(d, | ||
368 | d.getVar('IMAGE_ROOTFS'), | ||
369 | self.d.getVar('TARGET_VENDOR') | ||
370 | ) | ||
371 | |||
372 | self.inc_rpm_image_gen = self.d.getVar('INC_RPM_IMAGE_GEN') | ||
373 | if self.inc_rpm_image_gen != "1": | ||
374 | bb.utils.remove(self.image_rootfs, True) | ||
375 | else: | ||
376 | self.pm.recovery_packaging_data() | ||
377 | bb.utils.remove(self.d.getVar('MULTILIB_TEMP_ROOTFS'), True) | ||
378 | |||
379 | self.pm.create_configs() | ||
380 | |||
381 | ''' | ||
382 | While rpm incremental image generation is enabled, it will remove the | ||
383 | unneeded pkgs by comparing the new install solution manifest and the | ||
384 | old installed manifest. | ||
385 | ''' | ||
386 | def _create_incremental(self, pkgs_initial_install): | ||
387 | if self.inc_rpm_image_gen == "1": | ||
388 | |||
389 | pkgs_to_install = list() | ||
390 | for pkg_type in pkgs_initial_install: | ||
391 | pkgs_to_install += pkgs_initial_install[pkg_type] | ||
392 | |||
393 | installed_manifest = self.pm.load_old_install_solution() | ||
394 | solution_manifest = self.pm.dump_install_solution(pkgs_to_install) | ||
395 | |||
396 | pkg_to_remove = list() | ||
397 | for pkg in installed_manifest: | ||
398 | if pkg not in solution_manifest: | ||
399 | pkg_to_remove.append(pkg) | ||
400 | |||
401 | self.pm.update() | ||
402 | |||
403 | bb.note('incremental update -- upgrade packages in place ') | ||
404 | self.pm.upgrade() | ||
405 | if pkg_to_remove != []: | ||
406 | bb.note('incremental removed: %s' % ' '.join(pkg_to_remove)) | ||
407 | self.pm.remove(pkg_to_remove) | ||
408 | |||
409 | self.pm.autoremove() | ||
410 | |||
411 | def _create(self): | ||
412 | pkgs_to_install = self.manifest.parse_initial_manifest() | ||
413 | rpm_pre_process_cmds = self.d.getVar('RPM_PREPROCESS_COMMANDS') | ||
414 | rpm_post_process_cmds = self.d.getVar('RPM_POSTPROCESS_COMMANDS') | ||
415 | |||
416 | # update PM index files | ||
417 | self.pm.write_index() | ||
418 | |||
419 | execute_pre_post_process(self.d, rpm_pre_process_cmds) | ||
420 | |||
421 | if self.progress_reporter: | ||
422 | self.progress_reporter.next_stage() | ||
423 | |||
424 | if self.inc_rpm_image_gen == "1": | ||
425 | self._create_incremental(pkgs_to_install) | ||
426 | |||
427 | if self.progress_reporter: | ||
428 | self.progress_reporter.next_stage() | ||
429 | |||
430 | self.pm.update() | ||
431 | |||
432 | pkgs = [] | ||
433 | pkgs_attempt = [] | ||
434 | for pkg_type in pkgs_to_install: | ||
435 | if pkg_type == Manifest.PKG_TYPE_ATTEMPT_ONLY: | ||
436 | pkgs_attempt += pkgs_to_install[pkg_type] | ||
437 | else: | ||
438 | pkgs += pkgs_to_install[pkg_type] | ||
439 | |||
440 | if self.progress_reporter: | ||
441 | self.progress_reporter.next_stage() | ||
442 | |||
443 | self.pm.install(pkgs) | ||
444 | |||
445 | if self.progress_reporter: | ||
446 | self.progress_reporter.next_stage() | ||
447 | |||
448 | self.pm.install(pkgs_attempt, True) | ||
449 | |||
450 | if self.progress_reporter: | ||
451 | self.progress_reporter.next_stage() | ||
452 | |||
453 | self.pm.install_complementary() | ||
454 | |||
455 | if self.progress_reporter: | ||
456 | self.progress_reporter.next_stage() | ||
457 | |||
458 | self._setup_dbg_rootfs(['/etc', '/var/lib/rpm', '/var/cache/dnf', '/var/lib/dnf']) | ||
459 | |||
460 | execute_pre_post_process(self.d, rpm_post_process_cmds) | ||
461 | |||
462 | if self.inc_rpm_image_gen == "1": | ||
463 | self.pm.backup_packaging_data() | ||
464 | |||
465 | if self.progress_reporter: | ||
466 | self.progress_reporter.next_stage() | ||
467 | |||
468 | |||
469 | @staticmethod | ||
470 | def _depends_list(): | ||
471 | return ['DEPLOY_DIR_RPM', 'INC_RPM_IMAGE_GEN', 'RPM_PREPROCESS_COMMANDS', | ||
472 | 'RPM_POSTPROCESS_COMMANDS', 'RPM_PREFER_ELF_ARCH'] | ||
473 | |||
474 | def _get_delayed_postinsts(self): | ||
475 | postinst_dir = self.d.expand("${IMAGE_ROOTFS}${sysconfdir}/rpm-postinsts") | ||
476 | if os.path.isdir(postinst_dir): | ||
477 | files = os.listdir(postinst_dir) | ||
478 | for f in files: | ||
479 | bb.note('Delayed package scriptlet: %s' % f) | ||
480 | return files | ||
481 | |||
482 | return None | ||
483 | |||
484 | def _save_postinsts(self): | ||
485 | # this is just a stub. For RPM, the failed postinstalls are | ||
486 | # already saved in /etc/rpm-postinsts | ||
487 | pass | ||
488 | |||
489 | def _log_check(self): | ||
490 | self._log_check_warn() | ||
491 | self._log_check_error() | ||
492 | |||
493 | def _cleanup(self): | ||
494 | if bb.utils.contains("IMAGE_FEATURES", "package-management", True, False, self.d): | ||
495 | self.pm._invoke_dnf(["clean", "all"]) | ||
496 | |||
497 | |||
498 | class DpkgOpkgRootfs(Rootfs): | 358 | class DpkgOpkgRootfs(Rootfs): |
499 | def __init__(self, d, progress_reporter=None, logcatcher=None): | 359 | def __init__(self, d, progress_reporter=None, logcatcher=None): |
500 | super(DpkgOpkgRootfs, self).__init__(d, progress_reporter, logcatcher) | 360 | super(DpkgOpkgRootfs, self).__init__(d, progress_reporter, logcatcher) |
@@ -961,6 +821,7 @@ class OpkgRootfs(DpkgOpkgRootfs): | |||
961 | self.pm.remove_lists() | 821 | self.pm.remove_lists() |
962 | 822 | ||
963 | def get_class_for_type(imgtype): | 823 | def get_class_for_type(imgtype): |
824 | from oe.package_manager.rpm.rootfs import RpmRootfs | ||
964 | return {"rpm": RpmRootfs, | 825 | return {"rpm": RpmRootfs, |
965 | "ipk": OpkgRootfs, | 826 | "ipk": OpkgRootfs, |
966 | "deb": DpkgRootfs}[imgtype] | 827 | "deb": DpkgRootfs}[imgtype] |
@@ -973,6 +834,7 @@ def variable_depends(d, manifest_dir=None): | |||
973 | def create_rootfs(d, manifest_dir=None, progress_reporter=None, logcatcher=None): | 834 | def create_rootfs(d, manifest_dir=None, progress_reporter=None, logcatcher=None): |
974 | env_bkp = os.environ.copy() | 835 | env_bkp = os.environ.copy() |
975 | 836 | ||
837 | from oe.package_manager.rpm.rootfs import RpmRootfs | ||
976 | img_type = d.getVar('IMAGE_PKGTYPE') | 838 | img_type = d.getVar('IMAGE_PKGTYPE') |
977 | if img_type == "rpm": | 839 | if img_type == "rpm": |
978 | RpmRootfs(d, manifest_dir, progress_reporter, logcatcher).create() | 840 | RpmRootfs(d, manifest_dir, progress_reporter, logcatcher).create() |