Andrew Geissler | 635e0e4 | 2020-08-21 15:58:33 -0500 | [diff] [blame] | 1 | # |
| 2 | # SPDX-License-Identifier: GPL-2.0-only |
| 3 | # |
| 4 | |
| 5 | import glob |
| 6 | import shutil |
| 7 | from oe.utils import execute_pre_post_process |
| 8 | from oe.sdk import Sdk |
Andrew Geissler | 6ce62a2 | 2020-11-30 19:58:47 -0600 | [diff] [blame^] | 9 | from oe.package_manager.ipk.manifest import PkgManifest |
Andrew Geissler | 635e0e4 | 2020-08-21 15:58:33 -0500 | [diff] [blame] | 10 | from oe.manifest import Manifest |
| 11 | from oe.package_manager.ipk import OpkgPM |
| 12 | |
Andrew Geissler | 6ce62a2 | 2020-11-30 19:58:47 -0600 | [diff] [blame^] | 13 | class PkgSdk(Sdk): |
Andrew Geissler | 635e0e4 | 2020-08-21 15:58:33 -0500 | [diff] [blame] | 14 | def __init__(self, d, manifest_dir=None): |
Andrew Geissler | 6ce62a2 | 2020-11-30 19:58:47 -0600 | [diff] [blame^] | 15 | super(PkgSdk, self).__init__(d, manifest_dir) |
Andrew Geissler | 635e0e4 | 2020-08-21 15:58:33 -0500 | [diff] [blame] | 16 | |
| 17 | self.target_conf = self.d.getVar("IPKGCONF_TARGET") |
| 18 | self.host_conf = self.d.getVar("IPKGCONF_SDK") |
| 19 | |
Andrew Geissler | 6ce62a2 | 2020-11-30 19:58:47 -0600 | [diff] [blame^] | 20 | self.target_manifest = PkgManifest(d, self.manifest_dir, |
Andrew Geissler | 635e0e4 | 2020-08-21 15:58:33 -0500 | [diff] [blame] | 21 | Manifest.MANIFEST_TYPE_SDK_TARGET) |
Andrew Geissler | 6ce62a2 | 2020-11-30 19:58:47 -0600 | [diff] [blame^] | 22 | self.host_manifest = PkgManifest(d, self.manifest_dir, |
Andrew Geissler | 635e0e4 | 2020-08-21 15:58:33 -0500 | [diff] [blame] | 23 | Manifest.MANIFEST_TYPE_SDK_HOST) |
| 24 | |
| 25 | ipk_repo_workdir = "oe-sdk-repo" |
| 26 | if "sdk_ext" in d.getVar("BB_RUNTASK"): |
| 27 | ipk_repo_workdir = "oe-sdk-ext-repo" |
| 28 | |
| 29 | self.target_pm = OpkgPM(d, self.sdk_target_sysroot, self.target_conf, |
| 30 | self.d.getVar("ALL_MULTILIB_PACKAGE_ARCHS"), |
| 31 | ipk_repo_workdir=ipk_repo_workdir) |
| 32 | |
| 33 | self.host_pm = OpkgPM(d, self.sdk_host_sysroot, self.host_conf, |
| 34 | self.d.getVar("SDK_PACKAGE_ARCHS"), |
| 35 | ipk_repo_workdir=ipk_repo_workdir) |
| 36 | |
| 37 | def _populate_sysroot(self, pm, manifest): |
| 38 | pkgs_to_install = manifest.parse_initial_manifest() |
| 39 | |
| 40 | if (self.d.getVar('BUILD_IMAGES_FROM_FEEDS') or "") != "1": |
| 41 | pm.write_index() |
| 42 | |
| 43 | pm.update() |
| 44 | |
| 45 | for pkg_type in self.install_order: |
| 46 | if pkg_type in pkgs_to_install: |
| 47 | pm.install(pkgs_to_install[pkg_type], |
| 48 | [False, True][pkg_type == Manifest.PKG_TYPE_ATTEMPT_ONLY]) |
| 49 | |
| 50 | def _populate(self): |
| 51 | execute_pre_post_process(self.d, self.d.getVar("POPULATE_SDK_PRE_TARGET_COMMAND")) |
| 52 | |
| 53 | bb.note("Installing TARGET packages") |
| 54 | self._populate_sysroot(self.target_pm, self.target_manifest) |
| 55 | |
| 56 | self.target_pm.install_complementary(self.d.getVar('SDKIMAGE_INSTALL_COMPLEMENTARY')) |
| 57 | |
| 58 | self.target_pm.run_intercepts(populate_sdk='target') |
| 59 | |
| 60 | execute_pre_post_process(self.d, self.d.getVar("POPULATE_SDK_POST_TARGET_COMMAND")) |
| 61 | |
| 62 | if not bb.utils.contains("SDKIMAGE_FEATURES", "package-management", True, False, self.d): |
| 63 | self.target_pm.remove_packaging_data() |
| 64 | |
| 65 | bb.note("Installing NATIVESDK packages") |
| 66 | self._populate_sysroot(self.host_pm, self.host_manifest) |
| 67 | self.install_locales(self.host_pm) |
| 68 | |
| 69 | self.host_pm.run_intercepts(populate_sdk='host') |
| 70 | |
| 71 | execute_pre_post_process(self.d, self.d.getVar("POPULATE_SDK_POST_HOST_COMMAND")) |
| 72 | |
| 73 | if not bb.utils.contains("SDKIMAGE_FEATURES", "package-management", True, False, self.d): |
| 74 | self.host_pm.remove_packaging_data() |
| 75 | |
| 76 | target_sysconfdir = os.path.join(self.sdk_target_sysroot, self.sysconfdir) |
| 77 | host_sysconfdir = os.path.join(self.sdk_host_sysroot, self.sysconfdir) |
| 78 | |
| 79 | self.mkdirhier(target_sysconfdir) |
| 80 | shutil.copy(self.target_conf, target_sysconfdir) |
| 81 | os.chmod(os.path.join(target_sysconfdir, |
| 82 | os.path.basename(self.target_conf)), 0o644) |
| 83 | |
| 84 | self.mkdirhier(host_sysconfdir) |
| 85 | shutil.copy(self.host_conf, host_sysconfdir) |
| 86 | os.chmod(os.path.join(host_sysconfdir, |
| 87 | os.path.basename(self.host_conf)), 0o644) |
| 88 | |
| 89 | native_opkg_state_dir = os.path.join(self.sdk_output, self.sdk_native_path, |
| 90 | self.d.getVar('localstatedir_nativesdk').strip('/'), |
| 91 | "lib", "opkg") |
| 92 | self.mkdirhier(native_opkg_state_dir) |
| 93 | for f in glob.glob(os.path.join(self.sdk_output, "var", "lib", "opkg", "*")): |
| 94 | self.movefile(f, native_opkg_state_dir) |
| 95 | |
| 96 | self.remove(os.path.join(self.sdk_output, "var"), True) |