blob: e2ca415c8ecc4b4cdb3f56dd67d8f4e549f1bc47 [file] [log] [blame]
Andrew Geissler635e0e42020-08-21 15:58:33 -05001#
2# SPDX-License-Identifier: GPL-2.0-only
3#
4
5import glob
6import shutil
7from oe.utils import execute_pre_post_process
8from oe.sdk import Sdk
Andrew Geissler6ce62a22020-11-30 19:58:47 -06009from oe.package_manager.ipk.manifest import PkgManifest
Andrew Geissler635e0e42020-08-21 15:58:33 -050010from oe.manifest import Manifest
11from oe.package_manager.ipk import OpkgPM
12
Andrew Geissler6ce62a22020-11-30 19:58:47 -060013class PkgSdk(Sdk):
Andrew Geissler635e0e42020-08-21 15:58:33 -050014 def __init__(self, d, manifest_dir=None):
Andrew Geissler6ce62a22020-11-30 19:58:47 -060015 super(PkgSdk, self).__init__(d, manifest_dir)
Andrew Geissler635e0e42020-08-21 15:58:33 -050016
Andrew Geisslerd1e89492021-02-12 15:35:20 -060017 # In sdk_list_installed_packages the call to opkg is hardcoded to
18 # always use IPKGCONF_TARGET and there's no exposed API to change this
19 # so simply override IPKGCONF_TARGET to use this separated config file.
20 ipkgconf_sdk_target = d.getVar("IPKGCONF_SDK_TARGET")
21 d.setVar("IPKGCONF_TARGET", ipkgconf_sdk_target)
22
Andrew Geissler635e0e42020-08-21 15:58:33 -050023 self.target_conf = self.d.getVar("IPKGCONF_TARGET")
24 self.host_conf = self.d.getVar("IPKGCONF_SDK")
25
Andrew Geissler6ce62a22020-11-30 19:58:47 -060026 self.target_manifest = PkgManifest(d, self.manifest_dir,
Andrew Geissler635e0e42020-08-21 15:58:33 -050027 Manifest.MANIFEST_TYPE_SDK_TARGET)
Andrew Geissler6ce62a22020-11-30 19:58:47 -060028 self.host_manifest = PkgManifest(d, self.manifest_dir,
Andrew Geissler635e0e42020-08-21 15:58:33 -050029 Manifest.MANIFEST_TYPE_SDK_HOST)
30
31 ipk_repo_workdir = "oe-sdk-repo"
32 if "sdk_ext" in d.getVar("BB_RUNTASK"):
33 ipk_repo_workdir = "oe-sdk-ext-repo"
34
35 self.target_pm = OpkgPM(d, self.sdk_target_sysroot, self.target_conf,
36 self.d.getVar("ALL_MULTILIB_PACKAGE_ARCHS"),
37 ipk_repo_workdir=ipk_repo_workdir)
38
39 self.host_pm = OpkgPM(d, self.sdk_host_sysroot, self.host_conf,
40 self.d.getVar("SDK_PACKAGE_ARCHS"),
41 ipk_repo_workdir=ipk_repo_workdir)
42
43 def _populate_sysroot(self, pm, manifest):
44 pkgs_to_install = manifest.parse_initial_manifest()
45
46 if (self.d.getVar('BUILD_IMAGES_FROM_FEEDS') or "") != "1":
47 pm.write_index()
48
49 pm.update()
50
51 for pkg_type in self.install_order:
52 if pkg_type in pkgs_to_install:
53 pm.install(pkgs_to_install[pkg_type],
54 [False, True][pkg_type == Manifest.PKG_TYPE_ATTEMPT_ONLY])
55
56 def _populate(self):
57 execute_pre_post_process(self.d, self.d.getVar("POPULATE_SDK_PRE_TARGET_COMMAND"))
58
59 bb.note("Installing TARGET packages")
60 self._populate_sysroot(self.target_pm, self.target_manifest)
61
62 self.target_pm.install_complementary(self.d.getVar('SDKIMAGE_INSTALL_COMPLEMENTARY'))
63
64 self.target_pm.run_intercepts(populate_sdk='target')
65
66 execute_pre_post_process(self.d, self.d.getVar("POPULATE_SDK_POST_TARGET_COMMAND"))
67
68 if not bb.utils.contains("SDKIMAGE_FEATURES", "package-management", True, False, self.d):
69 self.target_pm.remove_packaging_data()
70
71 bb.note("Installing NATIVESDK packages")
72 self._populate_sysroot(self.host_pm, self.host_manifest)
73 self.install_locales(self.host_pm)
74
75 self.host_pm.run_intercepts(populate_sdk='host')
76
77 execute_pre_post_process(self.d, self.d.getVar("POPULATE_SDK_POST_HOST_COMMAND"))
78
79 if not bb.utils.contains("SDKIMAGE_FEATURES", "package-management", True, False, self.d):
80 self.host_pm.remove_packaging_data()
81
82 target_sysconfdir = os.path.join(self.sdk_target_sysroot, self.sysconfdir)
83 host_sysconfdir = os.path.join(self.sdk_host_sysroot, self.sysconfdir)
84
85 self.mkdirhier(target_sysconfdir)
86 shutil.copy(self.target_conf, target_sysconfdir)
87 os.chmod(os.path.join(target_sysconfdir,
88 os.path.basename(self.target_conf)), 0o644)
89
90 self.mkdirhier(host_sysconfdir)
91 shutil.copy(self.host_conf, host_sysconfdir)
92 os.chmod(os.path.join(host_sysconfdir,
93 os.path.basename(self.host_conf)), 0o644)
94
95 native_opkg_state_dir = os.path.join(self.sdk_output, self.sdk_native_path,
96 self.d.getVar('localstatedir_nativesdk').strip('/'),
97 "lib", "opkg")
98 self.mkdirhier(native_opkg_state_dir)
99 for f in glob.glob(os.path.join(self.sdk_output, "var", "lib", "opkg", "*")):
100 self.movefile(f, native_opkg_state_dir)
101
102 self.remove(os.path.join(self.sdk_output, "var"), True)