blob: a3a6c391720c199739541f0d50f5370195cadc92 [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
10
Patrick Williamsc0f7c042017-02-23 20:41:17 -060011class Sdk(object, metaclass=ABCMeta):
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012 def __init__(self, d, manifest_dir):
13 self.d = d
Brad Bishop6e60e8b2018-02-01 10:27:11 -050014 self.sdk_output = self.d.getVar('SDK_OUTPUT')
15 self.sdk_native_path = self.d.getVar('SDKPATHNATIVE').strip('/')
16 self.target_path = self.d.getVar('SDKTARGETSYSROOT').strip('/')
17 self.sysconfdir = self.d.getVar('sysconfdir').strip('/')
Patrick Williamsc124f4f2015-09-15 14:41:29 -050018
19 self.sdk_target_sysroot = os.path.join(self.sdk_output, self.target_path)
20 self.sdk_host_sysroot = self.sdk_output
21
22 if manifest_dir is None:
Brad Bishop6e60e8b2018-02-01 10:27:11 -050023 self.manifest_dir = self.d.getVar("SDK_DIR")
Patrick Williamsc124f4f2015-09-15 14:41:29 -050024 else:
25 self.manifest_dir = manifest_dir
26
Patrick Williamsf1e5d692016-03-30 15:21:19 -050027 self.remove(self.sdk_output, True)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050028
29 self.install_order = Manifest.INSTALL_ORDER
30
31 @abstractmethod
32 def _populate(self):
33 pass
34
35 def populate(self):
Patrick Williamsf1e5d692016-03-30 15:21:19 -050036 self.mkdirhier(self.sdk_output)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050037
38 # call backend dependent implementation
39 self._populate()
40
41 # Don't ship any libGL in the SDK
Patrick Williamsf1e5d692016-03-30 15:21:19 -050042 self.remove(os.path.join(self.sdk_output, self.sdk_native_path,
Brad Bishop6e60e8b2018-02-01 10:27:11 -050043 self.d.getVar('libdir_nativesdk').strip('/'),
Patrick Williamsf1e5d692016-03-30 15:21:19 -050044 "libGL*"))
Patrick Williamsc124f4f2015-09-15 14:41:29 -050045
46 # Fix or remove broken .la files
Patrick Williamsf1e5d692016-03-30 15:21:19 -050047 self.remove(os.path.join(self.sdk_output, self.sdk_native_path,
Brad Bishop6e60e8b2018-02-01 10:27:11 -050048 self.d.getVar('libdir_nativesdk').strip('/'),
Patrick Williamsf1e5d692016-03-30 15:21:19 -050049 "*.la"))
Patrick Williamsc124f4f2015-09-15 14:41:29 -050050
51 # Link the ld.so.cache file into the hosts filesystem
52 link_name = os.path.join(self.sdk_output, self.sdk_native_path,
53 self.sysconfdir, "ld.so.cache")
Patrick Williamsf1e5d692016-03-30 15:21:19 -050054 self.mkdirhier(os.path.dirname(link_name))
Patrick Williamsc124f4f2015-09-15 14:41:29 -050055 os.symlink("/etc/ld.so.cache", link_name)
56
Brad Bishop6e60e8b2018-02-01 10:27:11 -050057 execute_pre_post_process(self.d, self.d.getVar('SDK_POSTPROCESS_COMMAND'))
Patrick Williamsc124f4f2015-09-15 14:41:29 -050058
Patrick Williamsf1e5d692016-03-30 15:21:19 -050059 def movefile(self, sourcefile, destdir):
60 try:
61 # FIXME: this check of movefile's return code to None should be
62 # fixed within the function to use only exceptions to signal when
63 # something goes wrong
64 if (bb.utils.movefile(sourcefile, destdir) == None):
65 raise OSError("moving %s to %s failed"
66 %(sourcefile, destdir))
67 #FIXME: using umbrella exc catching because bb.utils method raises it
68 except Exception as e:
69 bb.debug(1, "printing the stack trace\n %s" %traceback.format_exc())
70 bb.error("unable to place %s in final SDK location" % sourcefile)
71
72 def mkdirhier(self, dirpath):
73 try:
74 bb.utils.mkdirhier(dirpath)
75 except OSError as e:
76 bb.debug(1, "printing the stack trace\n %s" %traceback.format_exc())
77 bb.fatal("cannot make dir for SDK: %s" % dirpath)
78
79 def remove(self, path, recurse=False):
80 try:
81 bb.utils.remove(path, recurse)
82 #FIXME: using umbrella exc catching because bb.utils method raises it
83 except Exception as e:
84 bb.debug(1, "printing the stack trace\n %s" %traceback.format_exc())
85 bb.warn("cannot remove SDK dir: %s" % path)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050086
87class RpmSdk(Sdk):
Brad Bishop6e60e8b2018-02-01 10:27:11 -050088 def __init__(self, d, manifest_dir=None, rpm_workdir="oe-sdk-repo"):
Patrick Williamsc124f4f2015-09-15 14:41:29 -050089 super(RpmSdk, self).__init__(d, manifest_dir)
90
91 self.target_manifest = RpmManifest(d, self.manifest_dir,
92 Manifest.MANIFEST_TYPE_SDK_TARGET)
93 self.host_manifest = RpmManifest(d, self.manifest_dir,
94 Manifest.MANIFEST_TYPE_SDK_HOST)
95
96 target_providename = ['/bin/sh',
97 '/bin/bash',
98 '/usr/bin/env',
99 '/usr/bin/perl',
100 'pkgconfig'
101 ]
102
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500103 rpm_repo_workdir = "oe-sdk-repo"
104 if "sdk_ext" in d.getVar("BB_RUNTASK"):
105 rpm_repo_workdir = "oe-sdk-ext-repo"
106
107
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500108 self.target_pm = RpmPM(d,
109 self.sdk_target_sysroot,
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500110 self.d.getVar('TARGET_VENDOR'),
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500111 'target',
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500112 target_providename,
113 rpm_repo_workdir=rpm_repo_workdir
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500114 )
115
116 sdk_providename = ['/bin/sh',
117 '/bin/bash',
118 '/usr/bin/env',
119 '/usr/bin/perl',
120 'pkgconfig',
121 'libGL.so()(64bit)',
122 'libGL.so'
123 ]
124
125 self.host_pm = RpmPM(d,
126 self.sdk_host_sysroot,
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500127 self.d.getVar('SDK_VENDOR'),
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500128 'host',
129 sdk_providename,
130 "SDK_PACKAGE_ARCHS",
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500131 "SDK_OS",
132 rpm_repo_workdir=rpm_repo_workdir
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500133 )
134
135 def _populate_sysroot(self, pm, manifest):
136 pkgs_to_install = manifest.parse_initial_manifest()
137
138 pm.create_configs()
139 pm.write_index()
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500140 pm.update()
141
142 pkgs = []
143 pkgs_attempt = []
144 for pkg_type in pkgs_to_install:
145 if pkg_type == Manifest.PKG_TYPE_ATTEMPT_ONLY:
146 pkgs_attempt += pkgs_to_install[pkg_type]
147 else:
148 pkgs += pkgs_to_install[pkg_type]
149
150 pm.install(pkgs)
151
152 pm.install(pkgs_attempt, True)
153
154 def _populate(self):
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500155 execute_pre_post_process(self.d, self.d.getVar("POPULATE_SDK_PRE_TARGET_COMMAND"))
156
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500157 bb.note("Installing TARGET packages")
158 self._populate_sysroot(self.target_pm, self.target_manifest)
159
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500160 self.target_pm.install_complementary(self.d.getVar('SDKIMAGE_INSTALL_COMPLEMENTARY'))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500161
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500162 execute_pre_post_process(self.d, self.d.getVar("POPULATE_SDK_POST_TARGET_COMMAND"))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500163
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600164 if not bb.utils.contains("SDKIMAGE_FEATURES", "package-management", True, False, self.d):
165 self.target_pm.remove_packaging_data()
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500166
167 bb.note("Installing NATIVESDK packages")
168 self._populate_sysroot(self.host_pm, self.host_manifest)
169
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500170 execute_pre_post_process(self.d, self.d.getVar("POPULATE_SDK_POST_HOST_COMMAND"))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500171
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600172 if not bb.utils.contains("SDKIMAGE_FEATURES", "package-management", True, False, self.d):
173 self.host_pm.remove_packaging_data()
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500174
175 # Move host RPM library data
176 native_rpm_state_dir = os.path.join(self.sdk_output,
177 self.sdk_native_path,
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500178 self.d.getVar('localstatedir_nativesdk').strip('/'),
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500179 "lib",
180 "rpm"
181 )
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500182 self.mkdirhier(native_rpm_state_dir)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500183 for f in glob.glob(os.path.join(self.sdk_output,
184 "var",
185 "lib",
186 "rpm",
187 "*")):
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500188 self.movefile(f, native_rpm_state_dir)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500189
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500190 self.remove(os.path.join(self.sdk_output, "var"), True)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500191
192 # Move host sysconfig data
193 native_sysconf_dir = os.path.join(self.sdk_output,
194 self.sdk_native_path,
195 self.d.getVar('sysconfdir',
196 True).strip('/'),
197 )
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500198 self.mkdirhier(native_sysconf_dir)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500199 for f in glob.glob(os.path.join(self.sdk_output, "etc", "rpm*")):
200 self.movefile(f, native_sysconf_dir)
201 for f in glob.glob(os.path.join(self.sdk_output, "etc", "dnf", "*")):
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500202 self.movefile(f, native_sysconf_dir)
203 self.remove(os.path.join(self.sdk_output, "etc"), True)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500204
205
206class OpkgSdk(Sdk):
207 def __init__(self, d, manifest_dir=None):
208 super(OpkgSdk, self).__init__(d, manifest_dir)
209
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500210 self.target_conf = self.d.getVar("IPKGCONF_TARGET")
211 self.host_conf = self.d.getVar("IPKGCONF_SDK")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500212
213 self.target_manifest = OpkgManifest(d, self.manifest_dir,
214 Manifest.MANIFEST_TYPE_SDK_TARGET)
215 self.host_manifest = OpkgManifest(d, self.manifest_dir,
216 Manifest.MANIFEST_TYPE_SDK_HOST)
217
218 self.target_pm = OpkgPM(d, self.sdk_target_sysroot, self.target_conf,
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500219 self.d.getVar("ALL_MULTILIB_PACKAGE_ARCHS"))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500220
221 self.host_pm = OpkgPM(d, self.sdk_host_sysroot, self.host_conf,
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500222 self.d.getVar("SDK_PACKAGE_ARCHS"))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500223
224 def _populate_sysroot(self, pm, manifest):
225 pkgs_to_install = manifest.parse_initial_manifest()
226
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500227 if (self.d.getVar('BUILD_IMAGES_FROM_FEEDS') or "") != "1":
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500228 pm.write_index()
229
230 pm.update()
231
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500232 for pkg_type in self.install_order:
233 if pkg_type in pkgs_to_install:
234 pm.install(pkgs_to_install[pkg_type],
235 [False, True][pkg_type == Manifest.PKG_TYPE_ATTEMPT_ONLY])
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500236
237 def _populate(self):
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500238 execute_pre_post_process(self.d, self.d.getVar("POPULATE_SDK_PRE_TARGET_COMMAND"))
239
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500240 bb.note("Installing TARGET packages")
241 self._populate_sysroot(self.target_pm, self.target_manifest)
242
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500243 self.target_pm.install_complementary(self.d.getVar('SDKIMAGE_INSTALL_COMPLEMENTARY'))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500244
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500245 execute_pre_post_process(self.d, self.d.getVar("POPULATE_SDK_POST_TARGET_COMMAND"))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500246
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600247 if not bb.utils.contains("SDKIMAGE_FEATURES", "package-management", True, False, self.d):
248 self.target_pm.remove_packaging_data()
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500249
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500250 bb.note("Installing NATIVESDK packages")
251 self._populate_sysroot(self.host_pm, self.host_manifest)
252
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500253 execute_pre_post_process(self.d, self.d.getVar("POPULATE_SDK_POST_HOST_COMMAND"))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500254
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600255 if not bb.utils.contains("SDKIMAGE_FEATURES", "package-management", True, False, self.d):
256 self.host_pm.remove_packaging_data()
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500257
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500258 target_sysconfdir = os.path.join(self.sdk_target_sysroot, self.sysconfdir)
259 host_sysconfdir = os.path.join(self.sdk_host_sysroot, self.sysconfdir)
260
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500261 self.mkdirhier(target_sysconfdir)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500262 shutil.copy(self.target_conf, target_sysconfdir)
263 os.chmod(os.path.join(target_sysconfdir,
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600264 os.path.basename(self.target_conf)), 0o644)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500265
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500266 self.mkdirhier(host_sysconfdir)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500267 shutil.copy(self.host_conf, host_sysconfdir)
268 os.chmod(os.path.join(host_sysconfdir,
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600269 os.path.basename(self.host_conf)), 0o644)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500270
271 native_opkg_state_dir = os.path.join(self.sdk_output, self.sdk_native_path,
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500272 self.d.getVar('localstatedir_nativesdk').strip('/'),
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500273 "lib", "opkg")
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500274 self.mkdirhier(native_opkg_state_dir)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500275 for f in glob.glob(os.path.join(self.sdk_output, "var", "lib", "opkg", "*")):
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500276 self.movefile(f, native_opkg_state_dir)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500277
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500278 self.remove(os.path.join(self.sdk_output, "var"), True)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500279
280
281class DpkgSdk(Sdk):
282 def __init__(self, d, manifest_dir=None):
283 super(DpkgSdk, self).__init__(d, manifest_dir)
284
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500285 self.target_conf_dir = os.path.join(self.d.getVar("APTCONF_TARGET"), "apt")
286 self.host_conf_dir = os.path.join(self.d.getVar("APTCONF_TARGET"), "apt-sdk")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500287
288 self.target_manifest = DpkgManifest(d, self.manifest_dir,
289 Manifest.MANIFEST_TYPE_SDK_TARGET)
290 self.host_manifest = DpkgManifest(d, self.manifest_dir,
291 Manifest.MANIFEST_TYPE_SDK_HOST)
292
293 self.target_pm = DpkgPM(d, self.sdk_target_sysroot,
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500294 self.d.getVar("PACKAGE_ARCHS"),
295 self.d.getVar("DPKG_ARCH"),
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500296 self.target_conf_dir)
297
298 self.host_pm = DpkgPM(d, self.sdk_host_sysroot,
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500299 self.d.getVar("SDK_PACKAGE_ARCHS"),
300 self.d.getVar("DEB_SDK_ARCH"),
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500301 self.host_conf_dir)
302
303 def _copy_apt_dir_to(self, dst_dir):
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500304 staging_etcdir_native = self.d.getVar("STAGING_ETCDIR_NATIVE")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500305
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500306 self.remove(dst_dir, True)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500307
308 shutil.copytree(os.path.join(staging_etcdir_native, "apt"), dst_dir)
309
310 def _populate_sysroot(self, pm, manifest):
311 pkgs_to_install = manifest.parse_initial_manifest()
312
313 pm.write_index()
314 pm.update()
315
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500316 for pkg_type in self.install_order:
317 if pkg_type in pkgs_to_install:
318 pm.install(pkgs_to_install[pkg_type],
319 [False, True][pkg_type == Manifest.PKG_TYPE_ATTEMPT_ONLY])
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500320
321 def _populate(self):
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500322 execute_pre_post_process(self.d, self.d.getVar("POPULATE_SDK_PRE_TARGET_COMMAND"))
323
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500324 bb.note("Installing TARGET packages")
325 self._populate_sysroot(self.target_pm, self.target_manifest)
326
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500327 self.target_pm.install_complementary(self.d.getVar('SDKIMAGE_INSTALL_COMPLEMENTARY'))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500328
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500329 execute_pre_post_process(self.d, self.d.getVar("POPULATE_SDK_POST_TARGET_COMMAND"))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500330
331 self._copy_apt_dir_to(os.path.join(self.sdk_target_sysroot, "etc", "apt"))
332
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600333 if not bb.utils.contains("SDKIMAGE_FEATURES", "package-management", True, False, self.d):
334 self.target_pm.remove_packaging_data()
335
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500336 bb.note("Installing NATIVESDK packages")
337 self._populate_sysroot(self.host_pm, self.host_manifest)
338
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500339 execute_pre_post_process(self.d, self.d.getVar("POPULATE_SDK_POST_HOST_COMMAND"))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500340
341 self._copy_apt_dir_to(os.path.join(self.sdk_output, self.sdk_native_path,
342 "etc", "apt"))
343
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600344 if not bb.utils.contains("SDKIMAGE_FEATURES", "package-management", True, False, self.d):
345 self.host_pm.remove_packaging_data()
346
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500347 native_dpkg_state_dir = os.path.join(self.sdk_output, self.sdk_native_path,
348 "var", "lib", "dpkg")
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500349 self.mkdirhier(native_dpkg_state_dir)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500350 for f in glob.glob(os.path.join(self.sdk_output, "var", "lib", "dpkg", "*")):
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500351 self.movefile(f, native_dpkg_state_dir)
352 self.remove(os.path.join(self.sdk_output, "var"), True)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500353
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500354
355
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500356def sdk_list_installed_packages(d, target, rootfs_dir=None):
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500357 if rootfs_dir is None:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500358 sdk_output = d.getVar('SDK_OUTPUT')
359 target_path = d.getVar('SDKTARGETSYSROOT').strip('/')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500360
361 rootfs_dir = [sdk_output, os.path.join(sdk_output, target_path)][target is True]
362
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500363 img_type = d.getVar('IMAGE_PKGTYPE')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500364 if img_type == "rpm":
365 arch_var = ["SDK_PACKAGE_ARCHS", None][target is True]
366 os_var = ["SDK_OS", None][target is True]
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500367 return RpmPkgsList(d, rootfs_dir).list_pkgs()
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500368 elif img_type == "ipk":
369 conf_file_var = ["IPKGCONF_SDK", "IPKGCONF_TARGET"][target is True]
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500370 return OpkgPkgsList(d, rootfs_dir, d.getVar(conf_file_var)).list_pkgs()
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500371 elif img_type == "deb":
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500372 return DpkgPkgsList(d, rootfs_dir).list_pkgs()
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500373
374def populate_sdk(d, manifest_dir=None):
375 env_bkp = os.environ.copy()
376
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500377 img_type = d.getVar('IMAGE_PKGTYPE')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500378 if img_type == "rpm":
379 RpmSdk(d, manifest_dir).populate()
380 elif img_type == "ipk":
381 OpkgSdk(d, manifest_dir).populate()
382 elif img_type == "deb":
383 DpkgSdk(d, manifest_dir).populate()
384
385 os.environ.clear()
386 os.environ.update(env_bkp)
387
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500388def get_extra_sdkinfo(sstate_dir):
389 """
390 This function is going to be used for generating the target and host manifest files packages of eSDK.
391 """
392 import math
393
394 extra_info = {}
395 extra_info['tasksizes'] = {}
396 extra_info['filesizes'] = {}
397 for root, _, files in os.walk(sstate_dir):
398 for fn in files:
399 if fn.endswith('.tgz'):
400 fsize = int(math.ceil(float(os.path.getsize(os.path.join(root, fn))) / 1024))
401 task = fn.rsplit(':',1)[1].split('_',1)[1].split(',')[0]
402 origtotal = extra_info['tasksizes'].get(task, 0)
403 extra_info['tasksizes'][task] = origtotal + fsize
404 extra_info['filesizes'][fn] = fsize
405 return extra_info
406
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500407if __name__ == "__main__":
408 pass