blob: b4fbdb799ef12c39ea67a9caa8276d32c9f327a6 [file] [log] [blame]
Brad Bishopc342db32019-05-15 21:57:59 -04001#
2# SPDX-License-Identifier: GPL-2.0-only
3#
4
Patrick Williamsc124f4f2015-09-15 14:41:29 -05005from abc import ABCMeta, abstractmethod
6from oe.utils import execute_pre_post_process
7from oe.manifest import *
8from oe.package_manager import *
9import os
10import shutil
11import glob
Patrick Williamsf1e5d692016-03-30 15:21:19 -050012import traceback
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013
Patrick Williamsc0f7c042017-02-23 20:41:17 -060014class Sdk(object, metaclass=ABCMeta):
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015 def __init__(self, d, manifest_dir):
16 self.d = d
Brad Bishop6e60e8b2018-02-01 10:27:11 -050017 self.sdk_output = self.d.getVar('SDK_OUTPUT')
18 self.sdk_native_path = self.d.getVar('SDKPATHNATIVE').strip('/')
19 self.target_path = self.d.getVar('SDKTARGETSYSROOT').strip('/')
20 self.sysconfdir = self.d.getVar('sysconfdir').strip('/')
Patrick Williamsc124f4f2015-09-15 14:41:29 -050021
22 self.sdk_target_sysroot = os.path.join(self.sdk_output, self.target_path)
23 self.sdk_host_sysroot = self.sdk_output
24
25 if manifest_dir is None:
Brad Bishop6e60e8b2018-02-01 10:27:11 -050026 self.manifest_dir = self.d.getVar("SDK_DIR")
Patrick Williamsc124f4f2015-09-15 14:41:29 -050027 else:
28 self.manifest_dir = manifest_dir
29
Patrick Williamsf1e5d692016-03-30 15:21:19 -050030 self.remove(self.sdk_output, True)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050031
32 self.install_order = Manifest.INSTALL_ORDER
33
34 @abstractmethod
35 def _populate(self):
36 pass
37
38 def populate(self):
Patrick Williamsf1e5d692016-03-30 15:21:19 -050039 self.mkdirhier(self.sdk_output)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050040
41 # call backend dependent implementation
42 self._populate()
43
44 # Don't ship any libGL in the SDK
Patrick Williamsf1e5d692016-03-30 15:21:19 -050045 self.remove(os.path.join(self.sdk_output, self.sdk_native_path,
Brad Bishop6e60e8b2018-02-01 10:27:11 -050046 self.d.getVar('libdir_nativesdk').strip('/'),
Patrick Williamsf1e5d692016-03-30 15:21:19 -050047 "libGL*"))
Patrick Williamsc124f4f2015-09-15 14:41:29 -050048
49 # Fix or remove broken .la files
Patrick Williamsf1e5d692016-03-30 15:21:19 -050050 self.remove(os.path.join(self.sdk_output, self.sdk_native_path,
Brad Bishop6e60e8b2018-02-01 10:27:11 -050051 self.d.getVar('libdir_nativesdk').strip('/'),
Patrick Williamsf1e5d692016-03-30 15:21:19 -050052 "*.la"))
Patrick Williamsc124f4f2015-09-15 14:41:29 -050053
54 # Link the ld.so.cache file into the hosts filesystem
55 link_name = os.path.join(self.sdk_output, self.sdk_native_path,
56 self.sysconfdir, "ld.so.cache")
Patrick Williamsf1e5d692016-03-30 15:21:19 -050057 self.mkdirhier(os.path.dirname(link_name))
Patrick Williamsc124f4f2015-09-15 14:41:29 -050058 os.symlink("/etc/ld.so.cache", link_name)
59
Brad Bishop6e60e8b2018-02-01 10:27:11 -050060 execute_pre_post_process(self.d, self.d.getVar('SDK_POSTPROCESS_COMMAND'))
Patrick Williamsc124f4f2015-09-15 14:41:29 -050061
Patrick Williamsf1e5d692016-03-30 15:21:19 -050062 def movefile(self, sourcefile, destdir):
63 try:
64 # FIXME: this check of movefile's return code to None should be
65 # fixed within the function to use only exceptions to signal when
66 # something goes wrong
67 if (bb.utils.movefile(sourcefile, destdir) == None):
68 raise OSError("moving %s to %s failed"
69 %(sourcefile, destdir))
70 #FIXME: using umbrella exc catching because bb.utils method raises it
71 except Exception as e:
72 bb.debug(1, "printing the stack trace\n %s" %traceback.format_exc())
73 bb.error("unable to place %s in final SDK location" % sourcefile)
74
75 def mkdirhier(self, dirpath):
76 try:
77 bb.utils.mkdirhier(dirpath)
78 except OSError as e:
79 bb.debug(1, "printing the stack trace\n %s" %traceback.format_exc())
80 bb.fatal("cannot make dir for SDK: %s" % dirpath)
81
82 def remove(self, path, recurse=False):
83 try:
84 bb.utils.remove(path, recurse)
85 #FIXME: using umbrella exc catching because bb.utils method raises it
86 except Exception as e:
87 bb.debug(1, "printing the stack trace\n %s" %traceback.format_exc())
88 bb.warn("cannot remove SDK dir: %s" % path)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050089
Brad Bishop00111322018-04-01 22:23:53 -040090 def install_locales(self, pm):
91 # This is only relevant for glibc
92 if self.d.getVar("TCLIBC") != "glibc":
93 return
94
95 linguas = self.d.getVar("SDKIMAGE_LINGUAS")
96 if linguas:
97 import fnmatch
98 # Install the binary locales
99 if linguas == "all":
100 pm.install_glob("nativesdk-glibc-binary-localedata-*.utf-8", sdk=True)
101 else:
Brad Bishop19323692019-04-05 15:28:33 -0400102 pm.install(["nativesdk-glibc-binary-localedata-%s.utf-8" % \
103 lang for lang in linguas.split()])
Brad Bishop00111322018-04-01 22:23:53 -0400104 # Generate a locale archive of them
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800105 target_arch = self.d.getVar('SDK_ARCH')
106 rootfs = oe.path.join(self.sdk_host_sysroot, self.sdk_native_path)
107 localedir = oe.path.join(rootfs, self.d.getVar("libdir_nativesdk"), "locale")
108 generate_locale_archive(self.d, rootfs, target_arch, localedir)
Brad Bishop00111322018-04-01 22:23:53 -0400109 # And now delete the binary locales
110 pkgs = fnmatch.filter(pm.list_installed(), "nativesdk-glibc-binary-localedata-*.utf-8")
111 pm.remove(pkgs)
112 else:
113 # No linguas so do nothing
114 pass
115
116
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500117class RpmSdk(Sdk):
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500118 def __init__(self, d, manifest_dir=None, rpm_workdir="oe-sdk-repo"):
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500119 super(RpmSdk, self).__init__(d, manifest_dir)
120
121 self.target_manifest = RpmManifest(d, self.manifest_dir,
122 Manifest.MANIFEST_TYPE_SDK_TARGET)
123 self.host_manifest = RpmManifest(d, self.manifest_dir,
124 Manifest.MANIFEST_TYPE_SDK_HOST)
125
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500126 rpm_repo_workdir = "oe-sdk-repo"
127 if "sdk_ext" in d.getVar("BB_RUNTASK"):
128 rpm_repo_workdir = "oe-sdk-ext-repo"
129
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500130 self.target_pm = RpmPM(d,
131 self.sdk_target_sysroot,
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500132 self.d.getVar('TARGET_VENDOR'),
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500133 'target',
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500134 rpm_repo_workdir=rpm_repo_workdir
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500135 )
136
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500137 self.host_pm = RpmPM(d,
138 self.sdk_host_sysroot,
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500139 self.d.getVar('SDK_VENDOR'),
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500140 'host',
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500141 "SDK_PACKAGE_ARCHS",
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500142 "SDK_OS",
143 rpm_repo_workdir=rpm_repo_workdir
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500144 )
145
146 def _populate_sysroot(self, pm, manifest):
147 pkgs_to_install = manifest.parse_initial_manifest()
148
149 pm.create_configs()
150 pm.write_index()
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500151 pm.update()
152
153 pkgs = []
154 pkgs_attempt = []
155 for pkg_type in pkgs_to_install:
156 if pkg_type == Manifest.PKG_TYPE_ATTEMPT_ONLY:
157 pkgs_attempt += pkgs_to_install[pkg_type]
158 else:
159 pkgs += pkgs_to_install[pkg_type]
160
161 pm.install(pkgs)
162
163 pm.install(pkgs_attempt, True)
164
165 def _populate(self):
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500166 execute_pre_post_process(self.d, self.d.getVar("POPULATE_SDK_PRE_TARGET_COMMAND"))
167
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500168 bb.note("Installing TARGET packages")
169 self._populate_sysroot(self.target_pm, self.target_manifest)
170
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500171 self.target_pm.install_complementary(self.d.getVar('SDKIMAGE_INSTALL_COMPLEMENTARY'))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500172
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800173 self.target_pm.run_intercepts(populate_sdk='target')
Brad Bishop316dfdd2018-06-25 12:45:53 -0400174
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500175 execute_pre_post_process(self.d, self.d.getVar("POPULATE_SDK_POST_TARGET_COMMAND"))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500176
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600177 if not bb.utils.contains("SDKIMAGE_FEATURES", "package-management", True, False, self.d):
178 self.target_pm.remove_packaging_data()
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500179
180 bb.note("Installing NATIVESDK packages")
181 self._populate_sysroot(self.host_pm, self.host_manifest)
Brad Bishop00111322018-04-01 22:23:53 -0400182 self.install_locales(self.host_pm)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500183
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800184 self.host_pm.run_intercepts(populate_sdk='host')
Brad Bishop316dfdd2018-06-25 12:45:53 -0400185
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500186 execute_pre_post_process(self.d, self.d.getVar("POPULATE_SDK_POST_HOST_COMMAND"))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500187
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600188 if not bb.utils.contains("SDKIMAGE_FEATURES", "package-management", True, False, self.d):
189 self.host_pm.remove_packaging_data()
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500190
191 # Move host RPM library data
192 native_rpm_state_dir = os.path.join(self.sdk_output,
193 self.sdk_native_path,
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500194 self.d.getVar('localstatedir_nativesdk').strip('/'),
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500195 "lib",
196 "rpm"
197 )
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500198 self.mkdirhier(native_rpm_state_dir)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500199 for f in glob.glob(os.path.join(self.sdk_output,
200 "var",
201 "lib",
202 "rpm",
203 "*")):
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500204 self.movefile(f, native_rpm_state_dir)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500205
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500206 self.remove(os.path.join(self.sdk_output, "var"), True)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500207
208 # Move host sysconfig data
209 native_sysconf_dir = os.path.join(self.sdk_output,
210 self.sdk_native_path,
211 self.d.getVar('sysconfdir',
212 True).strip('/'),
213 )
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500214 self.mkdirhier(native_sysconf_dir)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500215 for f in glob.glob(os.path.join(self.sdk_output, "etc", "rpm*")):
216 self.movefile(f, native_sysconf_dir)
217 for f in glob.glob(os.path.join(self.sdk_output, "etc", "dnf", "*")):
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500218 self.movefile(f, native_sysconf_dir)
219 self.remove(os.path.join(self.sdk_output, "etc"), True)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500220
221
222class OpkgSdk(Sdk):
223 def __init__(self, d, manifest_dir=None):
224 super(OpkgSdk, self).__init__(d, manifest_dir)
225
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500226 self.target_conf = self.d.getVar("IPKGCONF_TARGET")
227 self.host_conf = self.d.getVar("IPKGCONF_SDK")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500228
229 self.target_manifest = OpkgManifest(d, self.manifest_dir,
230 Manifest.MANIFEST_TYPE_SDK_TARGET)
231 self.host_manifest = OpkgManifest(d, self.manifest_dir,
232 Manifest.MANIFEST_TYPE_SDK_HOST)
233
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800234 ipk_repo_workdir = "oe-sdk-repo"
235 if "sdk_ext" in d.getVar("BB_RUNTASK"):
236 ipk_repo_workdir = "oe-sdk-ext-repo"
237
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500238 self.target_pm = OpkgPM(d, self.sdk_target_sysroot, self.target_conf,
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800239 self.d.getVar("ALL_MULTILIB_PACKAGE_ARCHS"),
240 ipk_repo_workdir=ipk_repo_workdir)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500241
242 self.host_pm = OpkgPM(d, self.sdk_host_sysroot, self.host_conf,
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800243 self.d.getVar("SDK_PACKAGE_ARCHS"),
244 ipk_repo_workdir=ipk_repo_workdir)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500245
246 def _populate_sysroot(self, pm, manifest):
247 pkgs_to_install = manifest.parse_initial_manifest()
248
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500249 if (self.d.getVar('BUILD_IMAGES_FROM_FEEDS') or "") != "1":
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500250 pm.write_index()
251
252 pm.update()
253
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500254 for pkg_type in self.install_order:
255 if pkg_type in pkgs_to_install:
256 pm.install(pkgs_to_install[pkg_type],
257 [False, True][pkg_type == Manifest.PKG_TYPE_ATTEMPT_ONLY])
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500258
259 def _populate(self):
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500260 execute_pre_post_process(self.d, self.d.getVar("POPULATE_SDK_PRE_TARGET_COMMAND"))
261
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500262 bb.note("Installing TARGET packages")
263 self._populate_sysroot(self.target_pm, self.target_manifest)
264
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500265 self.target_pm.install_complementary(self.d.getVar('SDKIMAGE_INSTALL_COMPLEMENTARY'))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500266
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800267 self.target_pm.run_intercepts(populate_sdk='target')
Brad Bishop316dfdd2018-06-25 12:45:53 -0400268
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500269 execute_pre_post_process(self.d, self.d.getVar("POPULATE_SDK_POST_TARGET_COMMAND"))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500270
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600271 if not bb.utils.contains("SDKIMAGE_FEATURES", "package-management", True, False, self.d):
272 self.target_pm.remove_packaging_data()
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500273
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500274 bb.note("Installing NATIVESDK packages")
275 self._populate_sysroot(self.host_pm, self.host_manifest)
Brad Bishop00111322018-04-01 22:23:53 -0400276 self.install_locales(self.host_pm)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500277
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800278 self.host_pm.run_intercepts(populate_sdk='host')
Brad Bishop316dfdd2018-06-25 12:45:53 -0400279
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500280 execute_pre_post_process(self.d, self.d.getVar("POPULATE_SDK_POST_HOST_COMMAND"))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500281
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600282 if not bb.utils.contains("SDKIMAGE_FEATURES", "package-management", True, False, self.d):
283 self.host_pm.remove_packaging_data()
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500284
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500285 target_sysconfdir = os.path.join(self.sdk_target_sysroot, self.sysconfdir)
286 host_sysconfdir = os.path.join(self.sdk_host_sysroot, self.sysconfdir)
287
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500288 self.mkdirhier(target_sysconfdir)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500289 shutil.copy(self.target_conf, target_sysconfdir)
290 os.chmod(os.path.join(target_sysconfdir,
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600291 os.path.basename(self.target_conf)), 0o644)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500292
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500293 self.mkdirhier(host_sysconfdir)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500294 shutil.copy(self.host_conf, host_sysconfdir)
295 os.chmod(os.path.join(host_sysconfdir,
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600296 os.path.basename(self.host_conf)), 0o644)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500297
298 native_opkg_state_dir = os.path.join(self.sdk_output, self.sdk_native_path,
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500299 self.d.getVar('localstatedir_nativesdk').strip('/'),
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500300 "lib", "opkg")
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500301 self.mkdirhier(native_opkg_state_dir)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500302 for f in glob.glob(os.path.join(self.sdk_output, "var", "lib", "opkg", "*")):
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500303 self.movefile(f, native_opkg_state_dir)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500304
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500305 self.remove(os.path.join(self.sdk_output, "var"), True)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500306
307
308class DpkgSdk(Sdk):
309 def __init__(self, d, manifest_dir=None):
310 super(DpkgSdk, self).__init__(d, manifest_dir)
311
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500312 self.target_conf_dir = os.path.join(self.d.getVar("APTCONF_TARGET"), "apt")
313 self.host_conf_dir = os.path.join(self.d.getVar("APTCONF_TARGET"), "apt-sdk")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500314
315 self.target_manifest = DpkgManifest(d, self.manifest_dir,
316 Manifest.MANIFEST_TYPE_SDK_TARGET)
317 self.host_manifest = DpkgManifest(d, self.manifest_dir,
318 Manifest.MANIFEST_TYPE_SDK_HOST)
319
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800320 deb_repo_workdir = "oe-sdk-repo"
321 if "sdk_ext" in d.getVar("BB_RUNTASK"):
322 deb_repo_workdir = "oe-sdk-ext-repo"
323
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500324 self.target_pm = DpkgPM(d, self.sdk_target_sysroot,
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500325 self.d.getVar("PACKAGE_ARCHS"),
326 self.d.getVar("DPKG_ARCH"),
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800327 self.target_conf_dir,
328 deb_repo_workdir=deb_repo_workdir)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500329
330 self.host_pm = DpkgPM(d, self.sdk_host_sysroot,
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500331 self.d.getVar("SDK_PACKAGE_ARCHS"),
332 self.d.getVar("DEB_SDK_ARCH"),
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800333 self.host_conf_dir,
334 deb_repo_workdir=deb_repo_workdir)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500335
336 def _copy_apt_dir_to(self, dst_dir):
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500337 staging_etcdir_native = self.d.getVar("STAGING_ETCDIR_NATIVE")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500338
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500339 self.remove(dst_dir, True)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500340
341 shutil.copytree(os.path.join(staging_etcdir_native, "apt"), dst_dir)
342
343 def _populate_sysroot(self, pm, manifest):
344 pkgs_to_install = manifest.parse_initial_manifest()
345
346 pm.write_index()
347 pm.update()
348
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500349 for pkg_type in self.install_order:
350 if pkg_type in pkgs_to_install:
351 pm.install(pkgs_to_install[pkg_type],
352 [False, True][pkg_type == Manifest.PKG_TYPE_ATTEMPT_ONLY])
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500353
354 def _populate(self):
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500355 execute_pre_post_process(self.d, self.d.getVar("POPULATE_SDK_PRE_TARGET_COMMAND"))
356
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500357 bb.note("Installing TARGET packages")
358 self._populate_sysroot(self.target_pm, self.target_manifest)
359
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500360 self.target_pm.install_complementary(self.d.getVar('SDKIMAGE_INSTALL_COMPLEMENTARY'))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500361
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800362 self.target_pm.run_intercepts(populate_sdk='target')
Brad Bishop316dfdd2018-06-25 12:45:53 -0400363
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500364 execute_pre_post_process(self.d, self.d.getVar("POPULATE_SDK_POST_TARGET_COMMAND"))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500365
366 self._copy_apt_dir_to(os.path.join(self.sdk_target_sysroot, "etc", "apt"))
367
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600368 if not bb.utils.contains("SDKIMAGE_FEATURES", "package-management", True, False, self.d):
369 self.target_pm.remove_packaging_data()
370
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500371 bb.note("Installing NATIVESDK packages")
372 self._populate_sysroot(self.host_pm, self.host_manifest)
Brad Bishop00111322018-04-01 22:23:53 -0400373 self.install_locales(self.host_pm)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500374
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800375 self.host_pm.run_intercepts(populate_sdk='host')
Brad Bishop316dfdd2018-06-25 12:45:53 -0400376
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500377 execute_pre_post_process(self.d, self.d.getVar("POPULATE_SDK_POST_HOST_COMMAND"))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500378
379 self._copy_apt_dir_to(os.path.join(self.sdk_output, self.sdk_native_path,
380 "etc", "apt"))
381
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600382 if not bb.utils.contains("SDKIMAGE_FEATURES", "package-management", True, False, self.d):
383 self.host_pm.remove_packaging_data()
384
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500385 native_dpkg_state_dir = os.path.join(self.sdk_output, self.sdk_native_path,
386 "var", "lib", "dpkg")
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500387 self.mkdirhier(native_dpkg_state_dir)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500388 for f in glob.glob(os.path.join(self.sdk_output, "var", "lib", "dpkg", "*")):
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500389 self.movefile(f, native_dpkg_state_dir)
390 self.remove(os.path.join(self.sdk_output, "var"), True)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500391
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500392
393
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500394def sdk_list_installed_packages(d, target, rootfs_dir=None):
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500395 if rootfs_dir is None:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500396 sdk_output = d.getVar('SDK_OUTPUT')
397 target_path = d.getVar('SDKTARGETSYSROOT').strip('/')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500398
399 rootfs_dir = [sdk_output, os.path.join(sdk_output, target_path)][target is True]
400
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500401 img_type = d.getVar('IMAGE_PKGTYPE')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500402 if img_type == "rpm":
403 arch_var = ["SDK_PACKAGE_ARCHS", None][target is True]
404 os_var = ["SDK_OS", None][target is True]
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500405 return RpmPkgsList(d, rootfs_dir).list_pkgs()
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500406 elif img_type == "ipk":
407 conf_file_var = ["IPKGCONF_SDK", "IPKGCONF_TARGET"][target is True]
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500408 return OpkgPkgsList(d, rootfs_dir, d.getVar(conf_file_var)).list_pkgs()
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500409 elif img_type == "deb":
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500410 return DpkgPkgsList(d, rootfs_dir).list_pkgs()
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500411
412def populate_sdk(d, manifest_dir=None):
413 env_bkp = os.environ.copy()
414
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500415 img_type = d.getVar('IMAGE_PKGTYPE')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500416 if img_type == "rpm":
417 RpmSdk(d, manifest_dir).populate()
418 elif img_type == "ipk":
419 OpkgSdk(d, manifest_dir).populate()
420 elif img_type == "deb":
421 DpkgSdk(d, manifest_dir).populate()
422
423 os.environ.clear()
424 os.environ.update(env_bkp)
425
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500426def get_extra_sdkinfo(sstate_dir):
427 """
428 This function is going to be used for generating the target and host manifest files packages of eSDK.
429 """
430 import math
431
432 extra_info = {}
433 extra_info['tasksizes'] = {}
434 extra_info['filesizes'] = {}
435 for root, _, files in os.walk(sstate_dir):
436 for fn in files:
437 if fn.endswith('.tgz'):
438 fsize = int(math.ceil(float(os.path.getsize(os.path.join(root, fn))) / 1024))
439 task = fn.rsplit(':',1)[1].split('_',1)[1].split(',')[0]
440 origtotal = extra_info['tasksizes'].get(task, 0)
441 extra_info['tasksizes'][task] = origtotal + fsize
442 extra_info['filesizes'][fn] = fsize
443 return extra_info
444
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500445if __name__ == "__main__":
446 pass