diff options
author | Fredrik Gustafsson <fredrik.gustafsson@axis.com> | 2020-07-24 16:42:34 +0200 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2020-07-27 19:58:10 +0100 |
commit | 873aee855f196cba43bed5201e7b30ba74a2b255 (patch) | |
tree | 8fb3ee9cce9f832be590ec08e49b8e3111a81300 /meta/lib/oe/rootfs.py | |
parent | b8d3d22ccdd3c61d9aab8c39ce13afeccb5dea56 (diff) | |
download | poky-873aee855f196cba43bed5201e7b30ba74a2b255.tar.gz |
ipk: 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.
RP: Fixes to parse/build
(From OE-Core rev: 67fa086589bae484a9beca50b627b007766dcb93)
Signed-off-by: Fredrik Gustafsson <fredrigu@axis.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/lib/oe/rootfs.py')
-rw-r--r-- | meta/lib/oe/rootfs.py | 269 |
1 files changed, 2 insertions, 267 deletions
diff --git a/meta/lib/oe/rootfs.py b/meta/lib/oe/rootfs.py index 4895f1ebb9..062ea7f335 100644 --- a/meta/lib/oe/rootfs.py +++ b/meta/lib/oe/rootfs.py | |||
@@ -6,7 +6,6 @@ from oe.utils import execute_pre_post_process | |||
6 | from oe.package_manager import * | 6 | from oe.package_manager import * |
7 | from oe.manifest import * | 7 | from oe.manifest import * |
8 | import oe.path | 8 | import oe.path |
9 | import filecmp | ||
10 | import shutil | 9 | import shutil |
11 | import os | 10 | import os |
12 | import subprocess | 11 | import subprocess |
@@ -554,274 +553,9 @@ class DpkgRootfs(DpkgOpkgRootfs): | |||
554 | def _cleanup(self): | 553 | def _cleanup(self): |
555 | pass | 554 | pass |
556 | 555 | ||
557 | |||
558 | class OpkgRootfs(DpkgOpkgRootfs): | ||
559 | def __init__(self, d, manifest_dir, progress_reporter=None, logcatcher=None): | ||
560 | super(OpkgRootfs, self).__init__(d, progress_reporter, logcatcher) | ||
561 | self.log_check_regex = '(exit 1|Collected errors)' | ||
562 | |||
563 | self.manifest = OpkgManifest(d, manifest_dir) | ||
564 | self.opkg_conf = self.d.getVar("IPKGCONF_TARGET") | ||
565 | self.pkg_archs = self.d.getVar("ALL_MULTILIB_PACKAGE_ARCHS") | ||
566 | |||
567 | self.inc_opkg_image_gen = self.d.getVar('INC_IPK_IMAGE_GEN') or "" | ||
568 | if self._remove_old_rootfs(): | ||
569 | bb.utils.remove(self.image_rootfs, True) | ||
570 | self.pm = OpkgPM(d, | ||
571 | self.image_rootfs, | ||
572 | self.opkg_conf, | ||
573 | self.pkg_archs) | ||
574 | else: | ||
575 | self.pm = OpkgPM(d, | ||
576 | self.image_rootfs, | ||
577 | self.opkg_conf, | ||
578 | self.pkg_archs) | ||
579 | self.pm.recover_packaging_data() | ||
580 | |||
581 | bb.utils.remove(self.d.getVar('MULTILIB_TEMP_ROOTFS'), True) | ||
582 | |||
583 | def _prelink_file(self, root_dir, filename): | ||
584 | bb.note('prelink %s in %s' % (filename, root_dir)) | ||
585 | prelink_cfg = oe.path.join(root_dir, | ||
586 | self.d.expand('${sysconfdir}/prelink.conf')) | ||
587 | if not os.path.exists(prelink_cfg): | ||
588 | shutil.copy(self.d.expand('${STAGING_DIR_NATIVE}${sysconfdir_native}/prelink.conf'), | ||
589 | prelink_cfg) | ||
590 | |||
591 | cmd_prelink = self.d.expand('${STAGING_DIR_NATIVE}${sbindir_native}/prelink') | ||
592 | self._exec_shell_cmd([cmd_prelink, | ||
593 | '--root', | ||
594 | root_dir, | ||
595 | '-amR', | ||
596 | '-N', | ||
597 | '-c', | ||
598 | self.d.expand('${sysconfdir}/prelink.conf')]) | ||
599 | |||
600 | ''' | ||
601 | Compare two files with the same key twice to see if they are equal. | ||
602 | If they are not equal, it means they are duplicated and come from | ||
603 | different packages. | ||
604 | 1st: Comapre them directly; | ||
605 | 2nd: While incremental image creation is enabled, one of the | ||
606 | files could be probaly prelinked in the previous image | ||
607 | creation and the file has been changed, so we need to | ||
608 | prelink the other one and compare them. | ||
609 | ''' | ||
610 | def _file_equal(self, key, f1, f2): | ||
611 | |||
612 | # Both of them are not prelinked | ||
613 | if filecmp.cmp(f1, f2): | ||
614 | return True | ||
615 | |||
616 | if bb.data.inherits_class('image-prelink', self.d): | ||
617 | if self.image_rootfs not in f1: | ||
618 | self._prelink_file(f1.replace(key, ''), f1) | ||
619 | |||
620 | if self.image_rootfs not in f2: | ||
621 | self._prelink_file(f2.replace(key, ''), f2) | ||
622 | |||
623 | # Both of them are prelinked | ||
624 | if filecmp.cmp(f1, f2): | ||
625 | return True | ||
626 | |||
627 | # Not equal | ||
628 | return False | ||
629 | |||
630 | """ | ||
631 | This function was reused from the old implementation. | ||
632 | See commit: "image.bbclass: Added variables for multilib support." by | ||
633 | Lianhao Lu. | ||
634 | """ | ||
635 | def _multilib_sanity_test(self, dirs): | ||
636 | |||
637 | allow_replace = self.d.getVar("MULTILIBRE_ALLOW_REP") | ||
638 | if allow_replace is None: | ||
639 | allow_replace = "" | ||
640 | |||
641 | allow_rep = re.compile(re.sub(r"\|$", r"", allow_replace)) | ||
642 | error_prompt = "Multilib check error:" | ||
643 | |||
644 | files = {} | ||
645 | for dir in dirs: | ||
646 | for root, subfolders, subfiles in os.walk(dir): | ||
647 | for file in subfiles: | ||
648 | item = os.path.join(root, file) | ||
649 | key = str(os.path.join("/", os.path.relpath(item, dir))) | ||
650 | |||
651 | valid = True | ||
652 | if key in files: | ||
653 | #check whether the file is allow to replace | ||
654 | if allow_rep.match(key): | ||
655 | valid = True | ||
656 | else: | ||
657 | if os.path.exists(files[key]) and \ | ||
658 | os.path.exists(item) and \ | ||
659 | not self._file_equal(key, files[key], item): | ||
660 | valid = False | ||
661 | bb.fatal("%s duplicate files %s %s is not the same\n" % | ||
662 | (error_prompt, item, files[key])) | ||
663 | |||
664 | #pass the check, add to list | ||
665 | if valid: | ||
666 | files[key] = item | ||
667 | |||
668 | def _multilib_test_install(self, pkgs): | ||
669 | ml_temp = self.d.getVar("MULTILIB_TEMP_ROOTFS") | ||
670 | bb.utils.mkdirhier(ml_temp) | ||
671 | |||
672 | dirs = [self.image_rootfs] | ||
673 | |||
674 | for variant in self.d.getVar("MULTILIB_VARIANTS").split(): | ||
675 | ml_target_rootfs = os.path.join(ml_temp, variant) | ||
676 | |||
677 | bb.utils.remove(ml_target_rootfs, True) | ||
678 | |||
679 | ml_opkg_conf = os.path.join(ml_temp, | ||
680 | variant + "-" + os.path.basename(self.opkg_conf)) | ||
681 | |||
682 | ml_pm = OpkgPM(self.d, ml_target_rootfs, ml_opkg_conf, self.pkg_archs, prepare_index=False) | ||
683 | |||
684 | ml_pm.update() | ||
685 | ml_pm.install(pkgs) | ||
686 | |||
687 | dirs.append(ml_target_rootfs) | ||
688 | |||
689 | self._multilib_sanity_test(dirs) | ||
690 | |||
691 | ''' | ||
692 | While ipk incremental image generation is enabled, it will remove the | ||
693 | unneeded pkgs by comparing the old full manifest in previous existing | ||
694 | image and the new full manifest in the current image. | ||
695 | ''' | ||
696 | def _remove_extra_packages(self, pkgs_initial_install): | ||
697 | if self.inc_opkg_image_gen == "1": | ||
698 | # Parse full manifest in previous existing image creation session | ||
699 | old_full_manifest = self.manifest.parse_full_manifest() | ||
700 | |||
701 | # Create full manifest for the current image session, the old one | ||
702 | # will be replaced by the new one. | ||
703 | self.manifest.create_full(self.pm) | ||
704 | |||
705 | # Parse full manifest in current image creation session | ||
706 | new_full_manifest = self.manifest.parse_full_manifest() | ||
707 | |||
708 | pkg_to_remove = list() | ||
709 | for pkg in old_full_manifest: | ||
710 | if pkg not in new_full_manifest: | ||
711 | pkg_to_remove.append(pkg) | ||
712 | |||
713 | if pkg_to_remove != []: | ||
714 | bb.note('decremental removed: %s' % ' '.join(pkg_to_remove)) | ||
715 | self.pm.remove(pkg_to_remove) | ||
716 | |||
717 | ''' | ||
718 | Compare with previous existing image creation, if some conditions | ||
719 | triggered, the previous old image should be removed. | ||
720 | The conditions include any of 'PACKAGE_EXCLUDE, NO_RECOMMENDATIONS | ||
721 | and BAD_RECOMMENDATIONS' has been changed. | ||
722 | ''' | ||
723 | def _remove_old_rootfs(self): | ||
724 | if self.inc_opkg_image_gen != "1": | ||
725 | return True | ||
726 | |||
727 | vars_list_file = self.d.expand('${T}/vars_list') | ||
728 | |||
729 | old_vars_list = "" | ||
730 | if os.path.exists(vars_list_file): | ||
731 | old_vars_list = open(vars_list_file, 'r+').read() | ||
732 | |||
733 | new_vars_list = '%s:%s:%s\n' % \ | ||
734 | ((self.d.getVar('BAD_RECOMMENDATIONS') or '').strip(), | ||
735 | (self.d.getVar('NO_RECOMMENDATIONS') or '').strip(), | ||
736 | (self.d.getVar('PACKAGE_EXCLUDE') or '').strip()) | ||
737 | open(vars_list_file, 'w+').write(new_vars_list) | ||
738 | |||
739 | if old_vars_list != new_vars_list: | ||
740 | return True | ||
741 | |||
742 | return False | ||
743 | |||
744 | def _create(self): | ||
745 | pkgs_to_install = self.manifest.parse_initial_manifest() | ||
746 | opkg_pre_process_cmds = self.d.getVar('OPKG_PREPROCESS_COMMANDS') | ||
747 | opkg_post_process_cmds = self.d.getVar('OPKG_POSTPROCESS_COMMANDS') | ||
748 | |||
749 | # update PM index files | ||
750 | self.pm.write_index() | ||
751 | |||
752 | execute_pre_post_process(self.d, opkg_pre_process_cmds) | ||
753 | |||
754 | if self.progress_reporter: | ||
755 | self.progress_reporter.next_stage() | ||
756 | # Steps are a bit different in order, skip next | ||
757 | self.progress_reporter.next_stage() | ||
758 | |||
759 | self.pm.update() | ||
760 | |||
761 | if self.progress_reporter: | ||
762 | self.progress_reporter.next_stage() | ||
763 | |||
764 | if self.inc_opkg_image_gen == "1": | ||
765 | self._remove_extra_packages(pkgs_to_install) | ||
766 | |||
767 | if self.progress_reporter: | ||
768 | self.progress_reporter.next_stage() | ||
769 | |||
770 | for pkg_type in self.install_order: | ||
771 | if pkg_type in pkgs_to_install: | ||
772 | # For multilib, we perform a sanity test before final install | ||
773 | # If sanity test fails, it will automatically do a bb.fatal() | ||
774 | # and the installation will stop | ||
775 | if pkg_type == Manifest.PKG_TYPE_MULTILIB: | ||
776 | self._multilib_test_install(pkgs_to_install[pkg_type]) | ||
777 | |||
778 | self.pm.install(pkgs_to_install[pkg_type], | ||
779 | [False, True][pkg_type == Manifest.PKG_TYPE_ATTEMPT_ONLY]) | ||
780 | |||
781 | if self.progress_reporter: | ||
782 | self.progress_reporter.next_stage() | ||
783 | |||
784 | self.pm.install_complementary() | ||
785 | |||
786 | if self.progress_reporter: | ||
787 | self.progress_reporter.next_stage() | ||
788 | |||
789 | opkg_lib_dir = self.d.getVar('OPKGLIBDIR') | ||
790 | opkg_dir = os.path.join(opkg_lib_dir, 'opkg') | ||
791 | self._setup_dbg_rootfs([opkg_dir]) | ||
792 | |||
793 | execute_pre_post_process(self.d, opkg_post_process_cmds) | ||
794 | |||
795 | if self.inc_opkg_image_gen == "1": | ||
796 | self.pm.backup_packaging_data() | ||
797 | |||
798 | if self.progress_reporter: | ||
799 | self.progress_reporter.next_stage() | ||
800 | |||
801 | @staticmethod | ||
802 | def _depends_list(): | ||
803 | return ['IPKGCONF_SDK', 'IPK_FEED_URIS', 'DEPLOY_DIR_IPK', 'IPKGCONF_TARGET', 'INC_IPK_IMAGE_GEN', 'OPKG_ARGS', 'OPKGLIBDIR', 'OPKG_PREPROCESS_COMMANDS', 'OPKG_POSTPROCESS_COMMANDS', 'OPKGLIBDIR'] | ||
804 | |||
805 | def _get_delayed_postinsts(self): | ||
806 | status_file = os.path.join(self.image_rootfs, | ||
807 | self.d.getVar('OPKGLIBDIR').strip('/'), | ||
808 | "opkg", "status") | ||
809 | return self._get_delayed_postinsts_common(status_file) | ||
810 | |||
811 | def _save_postinsts(self): | ||
812 | dst_postinst_dir = self.d.expand("${IMAGE_ROOTFS}${sysconfdir}/ipk-postinsts") | ||
813 | src_postinst_dir = self.d.expand("${IMAGE_ROOTFS}${OPKGLIBDIR}/opkg/info") | ||
814 | return self._save_postinsts_common(dst_postinst_dir, src_postinst_dir) | ||
815 | |||
816 | def _log_check(self): | ||
817 | self._log_check_warn() | ||
818 | self._log_check_error() | ||
819 | |||
820 | def _cleanup(self): | ||
821 | self.pm.remove_lists() | ||
822 | |||
823 | def get_class_for_type(imgtype): | 556 | def get_class_for_type(imgtype): |
824 | from oe.package_manager.rpm.rootfs import RpmRootfs | 557 | from oe.package_manager.rpm.rootfs import RpmRootfs |
558 | from oe.package_manager.ipk.rootfs import OpkgRootfs | ||
825 | return {"rpm": RpmRootfs, | 559 | return {"rpm": RpmRootfs, |
826 | "ipk": OpkgRootfs, | 560 | "ipk": OpkgRootfs, |
827 | "deb": DpkgRootfs}[imgtype] | 561 | "deb": DpkgRootfs}[imgtype] |
@@ -835,6 +569,7 @@ def create_rootfs(d, manifest_dir=None, progress_reporter=None, logcatcher=None) | |||
835 | env_bkp = os.environ.copy() | 569 | env_bkp = os.environ.copy() |
836 | 570 | ||
837 | from oe.package_manager.rpm.rootfs import RpmRootfs | 571 | from oe.package_manager.rpm.rootfs import RpmRootfs |
572 | from oe.package_manager.ipk.rootfs import OpkgRootfs | ||
838 | img_type = d.getVar('IMAGE_PKGTYPE') | 573 | img_type = d.getVar('IMAGE_PKGTYPE') |
839 | if img_type == "rpm": | 574 | if img_type == "rpm": |
840 | RpmRootfs(d, manifest_dir, progress_reporter, logcatcher).create() | 575 | RpmRootfs(d, manifest_dir, progress_reporter, logcatcher).create() |