blob: 153b07d76b40c19d86eb9ccfab844ce15d8e0716 [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001from abc import ABCMeta, abstractmethod
2from oe.utils import execute_pre_post_process
3from oe.manifest import *
4from oe.package_manager import *
5import os
6import shutil
7import glob
Patrick Williamsf1e5d692016-03-30 15:21:19 -05008import traceback
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009
Patrick Williamsc0f7c042017-02-23 20:41:17 -060010class Sdk(object, metaclass=ABCMeta):
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011 def __init__(self, d, manifest_dir):
12 self.d = d
Brad Bishop6e60e8b2018-02-01 10:27:11 -050013 self.sdk_output = self.d.getVar('SDK_OUTPUT')
14 self.sdk_native_path = self.d.getVar('SDKPATHNATIVE').strip('/')
15 self.target_path = self.d.getVar('SDKTARGETSYSROOT').strip('/')
16 self.sysconfdir = self.d.getVar('sysconfdir').strip('/')
Patrick Williamsc124f4f2015-09-15 14:41:29 -050017
18 self.sdk_target_sysroot = os.path.join(self.sdk_output, self.target_path)
19 self.sdk_host_sysroot = self.sdk_output
20
21 if manifest_dir is None:
Brad Bishop6e60e8b2018-02-01 10:27:11 -050022 self.manifest_dir = self.d.getVar("SDK_DIR")
Patrick Williamsc124f4f2015-09-15 14:41:29 -050023 else:
24 self.manifest_dir = manifest_dir
25
Patrick Williamsf1e5d692016-03-30 15:21:19 -050026 self.remove(self.sdk_output, True)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050027
28 self.install_order = Manifest.INSTALL_ORDER
29
30 @abstractmethod
31 def _populate(self):
32 pass
33
34 def populate(self):
Patrick Williamsf1e5d692016-03-30 15:21:19 -050035 self.mkdirhier(self.sdk_output)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050036
37 # call backend dependent implementation
38 self._populate()
39
40 # Don't ship any libGL in the SDK
Patrick Williamsf1e5d692016-03-30 15:21:19 -050041 self.remove(os.path.join(self.sdk_output, self.sdk_native_path,
Brad Bishop6e60e8b2018-02-01 10:27:11 -050042 self.d.getVar('libdir_nativesdk').strip('/'),
Patrick Williamsf1e5d692016-03-30 15:21:19 -050043 "libGL*"))
Patrick Williamsc124f4f2015-09-15 14:41:29 -050044
45 # Fix or remove broken .la files
Patrick Williamsf1e5d692016-03-30 15:21:19 -050046 self.remove(os.path.join(self.sdk_output, self.sdk_native_path,
Brad Bishop6e60e8b2018-02-01 10:27:11 -050047 self.d.getVar('libdir_nativesdk').strip('/'),
Patrick Williamsf1e5d692016-03-30 15:21:19 -050048 "*.la"))
Patrick Williamsc124f4f2015-09-15 14:41:29 -050049
50 # Link the ld.so.cache file into the hosts filesystem
51 link_name = os.path.join(self.sdk_output, self.sdk_native_path,
52 self.sysconfdir, "ld.so.cache")
Patrick Williamsf1e5d692016-03-30 15:21:19 -050053 self.mkdirhier(os.path.dirname(link_name))
Patrick Williamsc124f4f2015-09-15 14:41:29 -050054 os.symlink("/etc/ld.so.cache", link_name)
55
Brad Bishop6e60e8b2018-02-01 10:27:11 -050056 execute_pre_post_process(self.d, self.d.getVar('SDK_POSTPROCESS_COMMAND'))
Patrick Williamsc124f4f2015-09-15 14:41:29 -050057
Patrick Williamsf1e5d692016-03-30 15:21:19 -050058 def movefile(self, sourcefile, destdir):
59 try:
60 # FIXME: this check of movefile's return code to None should be
61 # fixed within the function to use only exceptions to signal when
62 # something goes wrong
63 if (bb.utils.movefile(sourcefile, destdir) == None):
64 raise OSError("moving %s to %s failed"
65 %(sourcefile, destdir))
66 #FIXME: using umbrella exc catching because bb.utils method raises it
67 except Exception as e:
68 bb.debug(1, "printing the stack trace\n %s" %traceback.format_exc())
69 bb.error("unable to place %s in final SDK location" % sourcefile)
70
71 def mkdirhier(self, dirpath):
72 try:
73 bb.utils.mkdirhier(dirpath)
74 except OSError as e:
75 bb.debug(1, "printing the stack trace\n %s" %traceback.format_exc())
76 bb.fatal("cannot make dir for SDK: %s" % dirpath)
77
78 def remove(self, path, recurse=False):
79 try:
80 bb.utils.remove(path, recurse)
81 #FIXME: using umbrella exc catching because bb.utils method raises it
82 except Exception as e:
83 bb.debug(1, "printing the stack trace\n %s" %traceback.format_exc())
84 bb.warn("cannot remove SDK dir: %s" % path)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050085
Brad Bishop00111322018-04-01 22:23:53 -040086 def install_locales(self, pm):
87 # This is only relevant for glibc
88 if self.d.getVar("TCLIBC") != "glibc":
89 return
90
91 linguas = self.d.getVar("SDKIMAGE_LINGUAS")
92 if linguas:
93 import fnmatch
94 # Install the binary locales
95 if linguas == "all":
96 pm.install_glob("nativesdk-glibc-binary-localedata-*.utf-8", sdk=True)
97 else:
98 for lang in linguas.split():
99 pm.install("nativesdk-glibc-binary-localedata-%s.utf-8" % lang)
100 # Generate a locale archive of them
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800101 target_arch = self.d.getVar('SDK_ARCH')
102 rootfs = oe.path.join(self.sdk_host_sysroot, self.sdk_native_path)
103 localedir = oe.path.join(rootfs, self.d.getVar("libdir_nativesdk"), "locale")
104 generate_locale_archive(self.d, rootfs, target_arch, localedir)
Brad Bishop00111322018-04-01 22:23:53 -0400105 # And now delete the binary locales
106 pkgs = fnmatch.filter(pm.list_installed(), "nativesdk-glibc-binary-localedata-*.utf-8")
107 pm.remove(pkgs)
108 else:
109 # No linguas so do nothing
110 pass
111
112
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500113class RpmSdk(Sdk):
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500114 def __init__(self, d, manifest_dir=None, rpm_workdir="oe-sdk-repo"):
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500115 super(RpmSdk, self).__init__(d, manifest_dir)
116
117 self.target_manifest = RpmManifest(d, self.manifest_dir,
118 Manifest.MANIFEST_TYPE_SDK_TARGET)
119 self.host_manifest = RpmManifest(d, self.manifest_dir,
120 Manifest.MANIFEST_TYPE_SDK_HOST)
121
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500122 rpm_repo_workdir = "oe-sdk-repo"
123 if "sdk_ext" in d.getVar("BB_RUNTASK"):
124 rpm_repo_workdir = "oe-sdk-ext-repo"
125
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500126 self.target_pm = RpmPM(d,
127 self.sdk_target_sysroot,
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500128 self.d.getVar('TARGET_VENDOR'),
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500129 'target',
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500130 rpm_repo_workdir=rpm_repo_workdir
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500131 )
132
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500133 self.host_pm = RpmPM(d,
134 self.sdk_host_sysroot,
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500135 self.d.getVar('SDK_VENDOR'),
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500136 'host',
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500137 "SDK_PACKAGE_ARCHS",
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500138 "SDK_OS",
139 rpm_repo_workdir=rpm_repo_workdir
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500140 )
141
142 def _populate_sysroot(self, pm, manifest):
143 pkgs_to_install = manifest.parse_initial_manifest()
144
145 pm.create_configs()
146 pm.write_index()
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500147 pm.update()
148
149 pkgs = []
150 pkgs_attempt = []
151 for pkg_type in pkgs_to_install:
152 if pkg_type == Manifest.PKG_TYPE_ATTEMPT_ONLY:
153 pkgs_attempt += pkgs_to_install[pkg_type]
154 else:
155 pkgs += pkgs_to_install[pkg_type]
156
157 pm.install(pkgs)
158
159 pm.install(pkgs_attempt, True)
160
161 def _populate(self):
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500162 execute_pre_post_process(self.d, self.d.getVar("POPULATE_SDK_PRE_TARGET_COMMAND"))
163
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500164 bb.note("Installing TARGET packages")
165 self._populate_sysroot(self.target_pm, self.target_manifest)
166
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500167 self.target_pm.install_complementary(self.d.getVar('SDKIMAGE_INSTALL_COMPLEMENTARY'))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500168
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800169 self.target_pm.run_intercepts(populate_sdk='target')
Brad Bishop316dfdd2018-06-25 12:45:53 -0400170
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500171 execute_pre_post_process(self.d, self.d.getVar("POPULATE_SDK_POST_TARGET_COMMAND"))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500172
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600173 if not bb.utils.contains("SDKIMAGE_FEATURES", "package-management", True, False, self.d):
174 self.target_pm.remove_packaging_data()
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500175
176 bb.note("Installing NATIVESDK packages")
177 self._populate_sysroot(self.host_pm, self.host_manifest)
Brad Bishop00111322018-04-01 22:23:53 -0400178 self.install_locales(self.host_pm)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500179
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800180 self.host_pm.run_intercepts(populate_sdk='host')
Brad Bishop316dfdd2018-06-25 12:45:53 -0400181
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500182 execute_pre_post_process(self.d, self.d.getVar("POPULATE_SDK_POST_HOST_COMMAND"))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500183
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600184 if not bb.utils.contains("SDKIMAGE_FEATURES", "package-management", True, False, self.d):
185 self.host_pm.remove_packaging_data()
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500186
187 # Move host RPM library data
188 native_rpm_state_dir = os.path.join(self.sdk_output,
189 self.sdk_native_path,
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500190 self.d.getVar('localstatedir_nativesdk').strip('/'),
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500191 "lib",
192 "rpm"
193 )
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500194 self.mkdirhier(native_rpm_state_dir)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500195 for f in glob.glob(os.path.join(self.sdk_output,
196 "var",
197 "lib",
198 "rpm",
199 "*")):
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500200 self.movefile(f, native_rpm_state_dir)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500201
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500202 self.remove(os.path.join(self.sdk_output, "var"), True)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500203
204 # Move host sysconfig data
205 native_sysconf_dir = os.path.join(self.sdk_output,
206 self.sdk_native_path,
207 self.d.getVar('sysconfdir',
208 True).strip('/'),
209 )
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500210 self.mkdirhier(native_sysconf_dir)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500211 for f in glob.glob(os.path.join(self.sdk_output, "etc", "rpm*")):
212 self.movefile(f, native_sysconf_dir)
213 for f in glob.glob(os.path.join(self.sdk_output, "etc", "dnf", "*")):
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500214 self.movefile(f, native_sysconf_dir)
215 self.remove(os.path.join(self.sdk_output, "etc"), True)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500216
217
218class OpkgSdk(Sdk):
219 def __init__(self, d, manifest_dir=None):
220 super(OpkgSdk, self).__init__(d, manifest_dir)
221
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500222 self.target_conf = self.d.getVar("IPKGCONF_TARGET")
223 self.host_conf = self.d.getVar("IPKGCONF_SDK")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500224
225 self.target_manifest = OpkgManifest(d, self.manifest_dir,
226 Manifest.MANIFEST_TYPE_SDK_TARGET)
227 self.host_manifest = OpkgManifest(d, self.manifest_dir,
228 Manifest.MANIFEST_TYPE_SDK_HOST)
229
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800230 ipk_repo_workdir = "oe-sdk-repo"
231 if "sdk_ext" in d.getVar("BB_RUNTASK"):
232 ipk_repo_workdir = "oe-sdk-ext-repo"
233
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500234 self.target_pm = OpkgPM(d, self.sdk_target_sysroot, self.target_conf,
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800235 self.d.getVar("ALL_MULTILIB_PACKAGE_ARCHS"),
236 ipk_repo_workdir=ipk_repo_workdir)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500237
238 self.host_pm = OpkgPM(d, self.sdk_host_sysroot, self.host_conf,
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800239 self.d.getVar("SDK_PACKAGE_ARCHS"),
240 ipk_repo_workdir=ipk_repo_workdir)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500241
242 def _populate_sysroot(self, pm, manifest):
243 pkgs_to_install = manifest.parse_initial_manifest()
244
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500245 if (self.d.getVar('BUILD_IMAGES_FROM_FEEDS') or "") != "1":
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500246 pm.write_index()
247
248 pm.update()
249
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500250 for pkg_type in self.install_order:
251 if pkg_type in pkgs_to_install:
252 pm.install(pkgs_to_install[pkg_type],
253 [False, True][pkg_type == Manifest.PKG_TYPE_ATTEMPT_ONLY])
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500254
255 def _populate(self):
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500256 execute_pre_post_process(self.d, self.d.getVar("POPULATE_SDK_PRE_TARGET_COMMAND"))
257
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500258 bb.note("Installing TARGET packages")
259 self._populate_sysroot(self.target_pm, self.target_manifest)
260
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500261 self.target_pm.install_complementary(self.d.getVar('SDKIMAGE_INSTALL_COMPLEMENTARY'))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500262
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800263 self.target_pm.run_intercepts(populate_sdk='target')
Brad Bishop316dfdd2018-06-25 12:45:53 -0400264
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500265 execute_pre_post_process(self.d, self.d.getVar("POPULATE_SDK_POST_TARGET_COMMAND"))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500266
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600267 if not bb.utils.contains("SDKIMAGE_FEATURES", "package-management", True, False, self.d):
268 self.target_pm.remove_packaging_data()
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500269
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500270 bb.note("Installing NATIVESDK packages")
271 self._populate_sysroot(self.host_pm, self.host_manifest)
Brad Bishop00111322018-04-01 22:23:53 -0400272 self.install_locales(self.host_pm)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500273
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800274 self.host_pm.run_intercepts(populate_sdk='host')
Brad Bishop316dfdd2018-06-25 12:45:53 -0400275
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500276 execute_pre_post_process(self.d, self.d.getVar("POPULATE_SDK_POST_HOST_COMMAND"))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500277
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600278 if not bb.utils.contains("SDKIMAGE_FEATURES", "package-management", True, False, self.d):
279 self.host_pm.remove_packaging_data()
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500280
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500281 target_sysconfdir = os.path.join(self.sdk_target_sysroot, self.sysconfdir)
282 host_sysconfdir = os.path.join(self.sdk_host_sysroot, self.sysconfdir)
283
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500284 self.mkdirhier(target_sysconfdir)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500285 shutil.copy(self.target_conf, target_sysconfdir)
286 os.chmod(os.path.join(target_sysconfdir,
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600287 os.path.basename(self.target_conf)), 0o644)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500288
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500289 self.mkdirhier(host_sysconfdir)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500290 shutil.copy(self.host_conf, host_sysconfdir)
291 os.chmod(os.path.join(host_sysconfdir,
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600292 os.path.basename(self.host_conf)), 0o644)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500293
294 native_opkg_state_dir = os.path.join(self.sdk_output, self.sdk_native_path,
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500295 self.d.getVar('localstatedir_nativesdk').strip('/'),
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500296 "lib", "opkg")
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500297 self.mkdirhier(native_opkg_state_dir)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500298 for f in glob.glob(os.path.join(self.sdk_output, "var", "lib", "opkg", "*")):
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500299 self.movefile(f, native_opkg_state_dir)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500300
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500301 self.remove(os.path.join(self.sdk_output, "var"), True)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500302
303
304class DpkgSdk(Sdk):
305 def __init__(self, d, manifest_dir=None):
306 super(DpkgSdk, self).__init__(d, manifest_dir)
307
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500308 self.target_conf_dir = os.path.join(self.d.getVar("APTCONF_TARGET"), "apt")
309 self.host_conf_dir = os.path.join(self.d.getVar("APTCONF_TARGET"), "apt-sdk")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500310
311 self.target_manifest = DpkgManifest(d, self.manifest_dir,
312 Manifest.MANIFEST_TYPE_SDK_TARGET)
313 self.host_manifest = DpkgManifest(d, self.manifest_dir,
314 Manifest.MANIFEST_TYPE_SDK_HOST)
315
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800316 deb_repo_workdir = "oe-sdk-repo"
317 if "sdk_ext" in d.getVar("BB_RUNTASK"):
318 deb_repo_workdir = "oe-sdk-ext-repo"
319
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500320 self.target_pm = DpkgPM(d, self.sdk_target_sysroot,
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500321 self.d.getVar("PACKAGE_ARCHS"),
322 self.d.getVar("DPKG_ARCH"),
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800323 self.target_conf_dir,
324 deb_repo_workdir=deb_repo_workdir)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500325
326 self.host_pm = DpkgPM(d, self.sdk_host_sysroot,
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500327 self.d.getVar("SDK_PACKAGE_ARCHS"),
328 self.d.getVar("DEB_SDK_ARCH"),
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800329 self.host_conf_dir,
330 deb_repo_workdir=deb_repo_workdir)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500331
332 def _copy_apt_dir_to(self, dst_dir):
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500333 staging_etcdir_native = self.d.getVar("STAGING_ETCDIR_NATIVE")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500334
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500335 self.remove(dst_dir, True)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500336
337 shutil.copytree(os.path.join(staging_etcdir_native, "apt"), dst_dir)
338
339 def _populate_sysroot(self, pm, manifest):
340 pkgs_to_install = manifest.parse_initial_manifest()
341
342 pm.write_index()
343 pm.update()
344
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500345 for pkg_type in self.install_order:
346 if pkg_type in pkgs_to_install:
347 pm.install(pkgs_to_install[pkg_type],
348 [False, True][pkg_type == Manifest.PKG_TYPE_ATTEMPT_ONLY])
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500349
350 def _populate(self):
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500351 execute_pre_post_process(self.d, self.d.getVar("POPULATE_SDK_PRE_TARGET_COMMAND"))
352
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500353 bb.note("Installing TARGET packages")
354 self._populate_sysroot(self.target_pm, self.target_manifest)
355
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500356 self.target_pm.install_complementary(self.d.getVar('SDKIMAGE_INSTALL_COMPLEMENTARY'))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500357
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800358 self.target_pm.run_intercepts(populate_sdk='target')
Brad Bishop316dfdd2018-06-25 12:45:53 -0400359
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500360 execute_pre_post_process(self.d, self.d.getVar("POPULATE_SDK_POST_TARGET_COMMAND"))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500361
362 self._copy_apt_dir_to(os.path.join(self.sdk_target_sysroot, "etc", "apt"))
363
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600364 if not bb.utils.contains("SDKIMAGE_FEATURES", "package-management", True, False, self.d):
365 self.target_pm.remove_packaging_data()
366
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500367 bb.note("Installing NATIVESDK packages")
368 self._populate_sysroot(self.host_pm, self.host_manifest)
Brad Bishop00111322018-04-01 22:23:53 -0400369 self.install_locales(self.host_pm)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500370
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800371 self.host_pm.run_intercepts(populate_sdk='host')
Brad Bishop316dfdd2018-06-25 12:45:53 -0400372
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500373 execute_pre_post_process(self.d, self.d.getVar("POPULATE_SDK_POST_HOST_COMMAND"))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500374
375 self._copy_apt_dir_to(os.path.join(self.sdk_output, self.sdk_native_path,
376 "etc", "apt"))
377
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600378 if not bb.utils.contains("SDKIMAGE_FEATURES", "package-management", True, False, self.d):
379 self.host_pm.remove_packaging_data()
380
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500381 native_dpkg_state_dir = os.path.join(self.sdk_output, self.sdk_native_path,
382 "var", "lib", "dpkg")
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500383 self.mkdirhier(native_dpkg_state_dir)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500384 for f in glob.glob(os.path.join(self.sdk_output, "var", "lib", "dpkg", "*")):
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500385 self.movefile(f, native_dpkg_state_dir)
386 self.remove(os.path.join(self.sdk_output, "var"), True)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500387
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500388
389
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500390def sdk_list_installed_packages(d, target, rootfs_dir=None):
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500391 if rootfs_dir is None:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500392 sdk_output = d.getVar('SDK_OUTPUT')
393 target_path = d.getVar('SDKTARGETSYSROOT').strip('/')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500394
395 rootfs_dir = [sdk_output, os.path.join(sdk_output, target_path)][target is True]
396
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500397 img_type = d.getVar('IMAGE_PKGTYPE')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500398 if img_type == "rpm":
399 arch_var = ["SDK_PACKAGE_ARCHS", None][target is True]
400 os_var = ["SDK_OS", None][target is True]
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500401 return RpmPkgsList(d, rootfs_dir).list_pkgs()
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500402 elif img_type == "ipk":
403 conf_file_var = ["IPKGCONF_SDK", "IPKGCONF_TARGET"][target is True]
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500404 return OpkgPkgsList(d, rootfs_dir, d.getVar(conf_file_var)).list_pkgs()
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500405 elif img_type == "deb":
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500406 return DpkgPkgsList(d, rootfs_dir).list_pkgs()
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500407
408def populate_sdk(d, manifest_dir=None):
409 env_bkp = os.environ.copy()
410
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500411 img_type = d.getVar('IMAGE_PKGTYPE')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500412 if img_type == "rpm":
413 RpmSdk(d, manifest_dir).populate()
414 elif img_type == "ipk":
415 OpkgSdk(d, manifest_dir).populate()
416 elif img_type == "deb":
417 DpkgSdk(d, manifest_dir).populate()
418
419 os.environ.clear()
420 os.environ.update(env_bkp)
421
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500422def get_extra_sdkinfo(sstate_dir):
423 """
424 This function is going to be used for generating the target and host manifest files packages of eSDK.
425 """
426 import math
427
428 extra_info = {}
429 extra_info['tasksizes'] = {}
430 extra_info['filesizes'] = {}
431 for root, _, files in os.walk(sstate_dir):
432 for fn in files:
433 if fn.endswith('.tgz'):
434 fsize = int(math.ceil(float(os.path.getsize(os.path.join(root, fn))) / 1024))
435 task = fn.rsplit(':',1)[1].split('_',1)[1].split(',')[0]
436 origtotal = extra_info['tasksizes'].get(task, 0)
437 extra_info['tasksizes'][task] = origtotal + fsize
438 extra_info['filesizes'][fn] = fsize
439 return extra_info
440
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500441if __name__ == "__main__":
442 pass