blob: 7f71cfba6ace35761b6548f0345ced379718b61d [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
Brad Bishop00111322018-04-01 22:23:53 -040010def generate_locale_archive(d, rootfs):
11 # Pretty sure we don't need this for SDK archive generation but
12 # keeping it to be safe...
13 target_arch = d.getVar('SDK_ARCH')
14 locale_arch_options = { \
15 "arm": ["--uint32-align=4", "--little-endian"],
16 "armeb": ["--uint32-align=4", "--big-endian"],
17 "aarch64": ["--uint32-align=4", "--little-endian"],
18 "aarch64_be": ["--uint32-align=4", "--big-endian"],
19 "sh4": ["--uint32-align=4", "--big-endian"],
20 "powerpc": ["--uint32-align=4", "--big-endian"],
21 "powerpc64": ["--uint32-align=4", "--big-endian"],
22 "mips": ["--uint32-align=4", "--big-endian"],
23 "mipsisa32r6": ["--uint32-align=4", "--big-endian"],
24 "mips64": ["--uint32-align=4", "--big-endian"],
25 "mipsisa64r6": ["--uint32-align=4", "--big-endian"],
26 "mipsel": ["--uint32-align=4", "--little-endian"],
27 "mipsisa32r6el": ["--uint32-align=4", "--little-endian"],
28 "mips64el": ["--uint32-align=4", "--little-endian"],
29 "mipsisa64r6el": ["--uint32-align=4", "--little-endian"],
30 "i586": ["--uint32-align=4", "--little-endian"],
31 "i686": ["--uint32-align=4", "--little-endian"],
32 "x86_64": ["--uint32-align=4", "--little-endian"]
33 }
34 if target_arch in locale_arch_options:
35 arch_options = locale_arch_options[target_arch]
36 else:
37 bb.error("locale_arch_options not found for target_arch=" + target_arch)
38 bb.fatal("unknown arch:" + target_arch + " for locale_arch_options")
39
40 localedir = oe.path.join(rootfs, d.getVar("libdir_nativesdk"), "locale")
41 # Need to set this so cross-localedef knows where the archive is
42 env = dict(os.environ)
43 env["LOCALEARCHIVE"] = oe.path.join(localedir, "locale-archive")
44
45 for name in os.listdir(localedir):
46 path = os.path.join(localedir, name)
47 if os.path.isdir(path):
48 try:
49 cmd = ["cross-localedef", "--verbose"]
50 cmd += arch_options
51 cmd += ["--add-to-archive", path]
52 subprocess.check_output(cmd, env=env, stderr=subprocess.STDOUT)
53 except Exception as e:
54 bb.fatal("Cannot create locale archive: %s" % e.output)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050055
Patrick Williamsc0f7c042017-02-23 20:41:17 -060056class Sdk(object, metaclass=ABCMeta):
Patrick Williamsc124f4f2015-09-15 14:41:29 -050057 def __init__(self, d, manifest_dir):
58 self.d = d
Brad Bishop6e60e8b2018-02-01 10:27:11 -050059 self.sdk_output = self.d.getVar('SDK_OUTPUT')
60 self.sdk_native_path = self.d.getVar('SDKPATHNATIVE').strip('/')
61 self.target_path = self.d.getVar('SDKTARGETSYSROOT').strip('/')
62 self.sysconfdir = self.d.getVar('sysconfdir').strip('/')
Patrick Williamsc124f4f2015-09-15 14:41:29 -050063
64 self.sdk_target_sysroot = os.path.join(self.sdk_output, self.target_path)
65 self.sdk_host_sysroot = self.sdk_output
66
67 if manifest_dir is None:
Brad Bishop6e60e8b2018-02-01 10:27:11 -050068 self.manifest_dir = self.d.getVar("SDK_DIR")
Patrick Williamsc124f4f2015-09-15 14:41:29 -050069 else:
70 self.manifest_dir = manifest_dir
71
Patrick Williamsf1e5d692016-03-30 15:21:19 -050072 self.remove(self.sdk_output, True)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050073
74 self.install_order = Manifest.INSTALL_ORDER
75
76 @abstractmethod
77 def _populate(self):
78 pass
79
80 def populate(self):
Patrick Williamsf1e5d692016-03-30 15:21:19 -050081 self.mkdirhier(self.sdk_output)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050082
83 # call backend dependent implementation
84 self._populate()
85
86 # Don't ship any libGL in the SDK
Patrick Williamsf1e5d692016-03-30 15:21:19 -050087 self.remove(os.path.join(self.sdk_output, self.sdk_native_path,
Brad Bishop6e60e8b2018-02-01 10:27:11 -050088 self.d.getVar('libdir_nativesdk').strip('/'),
Patrick Williamsf1e5d692016-03-30 15:21:19 -050089 "libGL*"))
Patrick Williamsc124f4f2015-09-15 14:41:29 -050090
91 # Fix or remove broken .la files
Patrick Williamsf1e5d692016-03-30 15:21:19 -050092 self.remove(os.path.join(self.sdk_output, self.sdk_native_path,
Brad Bishop6e60e8b2018-02-01 10:27:11 -050093 self.d.getVar('libdir_nativesdk').strip('/'),
Patrick Williamsf1e5d692016-03-30 15:21:19 -050094 "*.la"))
Patrick Williamsc124f4f2015-09-15 14:41:29 -050095
96 # Link the ld.so.cache file into the hosts filesystem
97 link_name = os.path.join(self.sdk_output, self.sdk_native_path,
98 self.sysconfdir, "ld.so.cache")
Patrick Williamsf1e5d692016-03-30 15:21:19 -050099 self.mkdirhier(os.path.dirname(link_name))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500100 os.symlink("/etc/ld.so.cache", link_name)
101
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500102 execute_pre_post_process(self.d, self.d.getVar('SDK_POSTPROCESS_COMMAND'))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500103
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500104 def movefile(self, sourcefile, destdir):
105 try:
106 # FIXME: this check of movefile's return code to None should be
107 # fixed within the function to use only exceptions to signal when
108 # something goes wrong
109 if (bb.utils.movefile(sourcefile, destdir) == None):
110 raise OSError("moving %s to %s failed"
111 %(sourcefile, destdir))
112 #FIXME: using umbrella exc catching because bb.utils method raises it
113 except Exception as e:
114 bb.debug(1, "printing the stack trace\n %s" %traceback.format_exc())
115 bb.error("unable to place %s in final SDK location" % sourcefile)
116
117 def mkdirhier(self, dirpath):
118 try:
119 bb.utils.mkdirhier(dirpath)
120 except OSError as e:
121 bb.debug(1, "printing the stack trace\n %s" %traceback.format_exc())
122 bb.fatal("cannot make dir for SDK: %s" % dirpath)
123
124 def remove(self, path, recurse=False):
125 try:
126 bb.utils.remove(path, recurse)
127 #FIXME: using umbrella exc catching because bb.utils method raises it
128 except Exception as e:
129 bb.debug(1, "printing the stack trace\n %s" %traceback.format_exc())
130 bb.warn("cannot remove SDK dir: %s" % path)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500131
Brad Bishop00111322018-04-01 22:23:53 -0400132 def install_locales(self, pm):
133 # This is only relevant for glibc
134 if self.d.getVar("TCLIBC") != "glibc":
135 return
136
137 linguas = self.d.getVar("SDKIMAGE_LINGUAS")
138 if linguas:
139 import fnmatch
140 # Install the binary locales
141 if linguas == "all":
142 pm.install_glob("nativesdk-glibc-binary-localedata-*.utf-8", sdk=True)
143 else:
144 for lang in linguas.split():
145 pm.install("nativesdk-glibc-binary-localedata-%s.utf-8" % lang)
146 # Generate a locale archive of them
147 generate_locale_archive(self.d, oe.path.join(self.sdk_host_sysroot, self.sdk_native_path))
148 # And now delete the binary locales
149 pkgs = fnmatch.filter(pm.list_installed(), "nativesdk-glibc-binary-localedata-*.utf-8")
150 pm.remove(pkgs)
151 else:
152 # No linguas so do nothing
153 pass
154
155
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500156class RpmSdk(Sdk):
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500157 def __init__(self, d, manifest_dir=None, rpm_workdir="oe-sdk-repo"):
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500158 super(RpmSdk, self).__init__(d, manifest_dir)
159
160 self.target_manifest = RpmManifest(d, self.manifest_dir,
161 Manifest.MANIFEST_TYPE_SDK_TARGET)
162 self.host_manifest = RpmManifest(d, self.manifest_dir,
163 Manifest.MANIFEST_TYPE_SDK_HOST)
164
165 target_providename = ['/bin/sh',
166 '/bin/bash',
167 '/usr/bin/env',
168 '/usr/bin/perl',
169 'pkgconfig'
170 ]
171
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500172 rpm_repo_workdir = "oe-sdk-repo"
173 if "sdk_ext" in d.getVar("BB_RUNTASK"):
174 rpm_repo_workdir = "oe-sdk-ext-repo"
175
176
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500177 self.target_pm = RpmPM(d,
178 self.sdk_target_sysroot,
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500179 self.d.getVar('TARGET_VENDOR'),
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500180 'target',
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500181 target_providename,
182 rpm_repo_workdir=rpm_repo_workdir
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500183 )
184
185 sdk_providename = ['/bin/sh',
186 '/bin/bash',
187 '/usr/bin/env',
188 '/usr/bin/perl',
189 'pkgconfig',
190 'libGL.so()(64bit)',
191 'libGL.so'
192 ]
193
194 self.host_pm = RpmPM(d,
195 self.sdk_host_sysroot,
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500196 self.d.getVar('SDK_VENDOR'),
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500197 'host',
198 sdk_providename,
199 "SDK_PACKAGE_ARCHS",
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500200 "SDK_OS",
201 rpm_repo_workdir=rpm_repo_workdir
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500202 )
203
204 def _populate_sysroot(self, pm, manifest):
205 pkgs_to_install = manifest.parse_initial_manifest()
206
207 pm.create_configs()
208 pm.write_index()
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500209 pm.update()
210
211 pkgs = []
212 pkgs_attempt = []
213 for pkg_type in pkgs_to_install:
214 if pkg_type == Manifest.PKG_TYPE_ATTEMPT_ONLY:
215 pkgs_attempt += pkgs_to_install[pkg_type]
216 else:
217 pkgs += pkgs_to_install[pkg_type]
218
219 pm.install(pkgs)
220
221 pm.install(pkgs_attempt, True)
222
223 def _populate(self):
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500224 execute_pre_post_process(self.d, self.d.getVar("POPULATE_SDK_PRE_TARGET_COMMAND"))
225
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500226 bb.note("Installing TARGET packages")
227 self._populate_sysroot(self.target_pm, self.target_manifest)
228
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500229 self.target_pm.install_complementary(self.d.getVar('SDKIMAGE_INSTALL_COMPLEMENTARY'))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500230
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500231 execute_pre_post_process(self.d, self.d.getVar("POPULATE_SDK_POST_TARGET_COMMAND"))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500232
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600233 if not bb.utils.contains("SDKIMAGE_FEATURES", "package-management", True, False, self.d):
234 self.target_pm.remove_packaging_data()
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500235
236 bb.note("Installing NATIVESDK packages")
237 self._populate_sysroot(self.host_pm, self.host_manifest)
Brad Bishop00111322018-04-01 22:23:53 -0400238 self.install_locales(self.host_pm)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500239
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500240 execute_pre_post_process(self.d, self.d.getVar("POPULATE_SDK_POST_HOST_COMMAND"))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500241
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600242 if not bb.utils.contains("SDKIMAGE_FEATURES", "package-management", True, False, self.d):
243 self.host_pm.remove_packaging_data()
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500244
245 # Move host RPM library data
246 native_rpm_state_dir = os.path.join(self.sdk_output,
247 self.sdk_native_path,
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500248 self.d.getVar('localstatedir_nativesdk').strip('/'),
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500249 "lib",
250 "rpm"
251 )
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500252 self.mkdirhier(native_rpm_state_dir)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500253 for f in glob.glob(os.path.join(self.sdk_output,
254 "var",
255 "lib",
256 "rpm",
257 "*")):
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500258 self.movefile(f, native_rpm_state_dir)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500259
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500260 self.remove(os.path.join(self.sdk_output, "var"), True)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500261
262 # Move host sysconfig data
263 native_sysconf_dir = os.path.join(self.sdk_output,
264 self.sdk_native_path,
265 self.d.getVar('sysconfdir',
266 True).strip('/'),
267 )
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500268 self.mkdirhier(native_sysconf_dir)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500269 for f in glob.glob(os.path.join(self.sdk_output, "etc", "rpm*")):
270 self.movefile(f, native_sysconf_dir)
271 for f in glob.glob(os.path.join(self.sdk_output, "etc", "dnf", "*")):
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500272 self.movefile(f, native_sysconf_dir)
273 self.remove(os.path.join(self.sdk_output, "etc"), True)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500274
275
276class OpkgSdk(Sdk):
277 def __init__(self, d, manifest_dir=None):
278 super(OpkgSdk, self).__init__(d, manifest_dir)
279
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500280 self.target_conf = self.d.getVar("IPKGCONF_TARGET")
281 self.host_conf = self.d.getVar("IPKGCONF_SDK")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500282
283 self.target_manifest = OpkgManifest(d, self.manifest_dir,
284 Manifest.MANIFEST_TYPE_SDK_TARGET)
285 self.host_manifest = OpkgManifest(d, self.manifest_dir,
286 Manifest.MANIFEST_TYPE_SDK_HOST)
287
288 self.target_pm = OpkgPM(d, self.sdk_target_sysroot, self.target_conf,
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500289 self.d.getVar("ALL_MULTILIB_PACKAGE_ARCHS"))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500290
291 self.host_pm = OpkgPM(d, self.sdk_host_sysroot, self.host_conf,
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500292 self.d.getVar("SDK_PACKAGE_ARCHS"))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500293
294 def _populate_sysroot(self, pm, manifest):
295 pkgs_to_install = manifest.parse_initial_manifest()
296
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500297 if (self.d.getVar('BUILD_IMAGES_FROM_FEEDS') or "") != "1":
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500298 pm.write_index()
299
300 pm.update()
301
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500302 for pkg_type in self.install_order:
303 if pkg_type in pkgs_to_install:
304 pm.install(pkgs_to_install[pkg_type],
305 [False, True][pkg_type == Manifest.PKG_TYPE_ATTEMPT_ONLY])
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500306
307 def _populate(self):
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500308 execute_pre_post_process(self.d, self.d.getVar("POPULATE_SDK_PRE_TARGET_COMMAND"))
309
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500310 bb.note("Installing TARGET packages")
311 self._populate_sysroot(self.target_pm, self.target_manifest)
312
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500313 self.target_pm.install_complementary(self.d.getVar('SDKIMAGE_INSTALL_COMPLEMENTARY'))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500314
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500315 execute_pre_post_process(self.d, self.d.getVar("POPULATE_SDK_POST_TARGET_COMMAND"))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500316
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600317 if not bb.utils.contains("SDKIMAGE_FEATURES", "package-management", True, False, self.d):
318 self.target_pm.remove_packaging_data()
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500319
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500320 bb.note("Installing NATIVESDK packages")
321 self._populate_sysroot(self.host_pm, self.host_manifest)
Brad Bishop00111322018-04-01 22:23:53 -0400322 self.install_locales(self.host_pm)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500323
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500324 execute_pre_post_process(self.d, self.d.getVar("POPULATE_SDK_POST_HOST_COMMAND"))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500325
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600326 if not bb.utils.contains("SDKIMAGE_FEATURES", "package-management", True, False, self.d):
327 self.host_pm.remove_packaging_data()
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500328
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500329 target_sysconfdir = os.path.join(self.sdk_target_sysroot, self.sysconfdir)
330 host_sysconfdir = os.path.join(self.sdk_host_sysroot, self.sysconfdir)
331
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500332 self.mkdirhier(target_sysconfdir)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500333 shutil.copy(self.target_conf, target_sysconfdir)
334 os.chmod(os.path.join(target_sysconfdir,
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600335 os.path.basename(self.target_conf)), 0o644)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500336
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500337 self.mkdirhier(host_sysconfdir)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500338 shutil.copy(self.host_conf, host_sysconfdir)
339 os.chmod(os.path.join(host_sysconfdir,
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600340 os.path.basename(self.host_conf)), 0o644)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500341
342 native_opkg_state_dir = os.path.join(self.sdk_output, self.sdk_native_path,
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500343 self.d.getVar('localstatedir_nativesdk').strip('/'),
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500344 "lib", "opkg")
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500345 self.mkdirhier(native_opkg_state_dir)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500346 for f in glob.glob(os.path.join(self.sdk_output, "var", "lib", "opkg", "*")):
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500347 self.movefile(f, native_opkg_state_dir)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500348
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500349 self.remove(os.path.join(self.sdk_output, "var"), True)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500350
351
352class DpkgSdk(Sdk):
353 def __init__(self, d, manifest_dir=None):
354 super(DpkgSdk, self).__init__(d, manifest_dir)
355
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500356 self.target_conf_dir = os.path.join(self.d.getVar("APTCONF_TARGET"), "apt")
357 self.host_conf_dir = os.path.join(self.d.getVar("APTCONF_TARGET"), "apt-sdk")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500358
359 self.target_manifest = DpkgManifest(d, self.manifest_dir,
360 Manifest.MANIFEST_TYPE_SDK_TARGET)
361 self.host_manifest = DpkgManifest(d, self.manifest_dir,
362 Manifest.MANIFEST_TYPE_SDK_HOST)
363
364 self.target_pm = DpkgPM(d, self.sdk_target_sysroot,
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500365 self.d.getVar("PACKAGE_ARCHS"),
366 self.d.getVar("DPKG_ARCH"),
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500367 self.target_conf_dir)
368
369 self.host_pm = DpkgPM(d, self.sdk_host_sysroot,
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500370 self.d.getVar("SDK_PACKAGE_ARCHS"),
371 self.d.getVar("DEB_SDK_ARCH"),
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500372 self.host_conf_dir)
373
374 def _copy_apt_dir_to(self, dst_dir):
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500375 staging_etcdir_native = self.d.getVar("STAGING_ETCDIR_NATIVE")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500376
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500377 self.remove(dst_dir, True)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500378
379 shutil.copytree(os.path.join(staging_etcdir_native, "apt"), dst_dir)
380
381 def _populate_sysroot(self, pm, manifest):
382 pkgs_to_install = manifest.parse_initial_manifest()
383
384 pm.write_index()
385 pm.update()
386
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500387 for pkg_type in self.install_order:
388 if pkg_type in pkgs_to_install:
389 pm.install(pkgs_to_install[pkg_type],
390 [False, True][pkg_type == Manifest.PKG_TYPE_ATTEMPT_ONLY])
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500391
392 def _populate(self):
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500393 execute_pre_post_process(self.d, self.d.getVar("POPULATE_SDK_PRE_TARGET_COMMAND"))
394
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500395 bb.note("Installing TARGET packages")
396 self._populate_sysroot(self.target_pm, self.target_manifest)
397
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500398 self.target_pm.install_complementary(self.d.getVar('SDKIMAGE_INSTALL_COMPLEMENTARY'))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500399
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500400 execute_pre_post_process(self.d, self.d.getVar("POPULATE_SDK_POST_TARGET_COMMAND"))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500401
402 self._copy_apt_dir_to(os.path.join(self.sdk_target_sysroot, "etc", "apt"))
403
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600404 if not bb.utils.contains("SDKIMAGE_FEATURES", "package-management", True, False, self.d):
405 self.target_pm.remove_packaging_data()
406
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500407 bb.note("Installing NATIVESDK packages")
408 self._populate_sysroot(self.host_pm, self.host_manifest)
Brad Bishop00111322018-04-01 22:23:53 -0400409 self.install_locales(self.host_pm)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500410
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500411 execute_pre_post_process(self.d, self.d.getVar("POPULATE_SDK_POST_HOST_COMMAND"))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500412
413 self._copy_apt_dir_to(os.path.join(self.sdk_output, self.sdk_native_path,
414 "etc", "apt"))
415
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600416 if not bb.utils.contains("SDKIMAGE_FEATURES", "package-management", True, False, self.d):
417 self.host_pm.remove_packaging_data()
418
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500419 native_dpkg_state_dir = os.path.join(self.sdk_output, self.sdk_native_path,
420 "var", "lib", "dpkg")
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500421 self.mkdirhier(native_dpkg_state_dir)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500422 for f in glob.glob(os.path.join(self.sdk_output, "var", "lib", "dpkg", "*")):
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500423 self.movefile(f, native_dpkg_state_dir)
424 self.remove(os.path.join(self.sdk_output, "var"), True)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500425
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500426
427
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500428def sdk_list_installed_packages(d, target, rootfs_dir=None):
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500429 if rootfs_dir is None:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500430 sdk_output = d.getVar('SDK_OUTPUT')
431 target_path = d.getVar('SDKTARGETSYSROOT').strip('/')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500432
433 rootfs_dir = [sdk_output, os.path.join(sdk_output, target_path)][target is True]
434
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500435 img_type = d.getVar('IMAGE_PKGTYPE')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500436 if img_type == "rpm":
437 arch_var = ["SDK_PACKAGE_ARCHS", None][target is True]
438 os_var = ["SDK_OS", None][target is True]
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500439 return RpmPkgsList(d, rootfs_dir).list_pkgs()
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500440 elif img_type == "ipk":
441 conf_file_var = ["IPKGCONF_SDK", "IPKGCONF_TARGET"][target is True]
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500442 return OpkgPkgsList(d, rootfs_dir, d.getVar(conf_file_var)).list_pkgs()
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500443 elif img_type == "deb":
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500444 return DpkgPkgsList(d, rootfs_dir).list_pkgs()
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500445
446def populate_sdk(d, manifest_dir=None):
447 env_bkp = os.environ.copy()
448
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500449 img_type = d.getVar('IMAGE_PKGTYPE')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500450 if img_type == "rpm":
451 RpmSdk(d, manifest_dir).populate()
452 elif img_type == "ipk":
453 OpkgSdk(d, manifest_dir).populate()
454 elif img_type == "deb":
455 DpkgSdk(d, manifest_dir).populate()
456
457 os.environ.clear()
458 os.environ.update(env_bkp)
459
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500460def get_extra_sdkinfo(sstate_dir):
461 """
462 This function is going to be used for generating the target and host manifest files packages of eSDK.
463 """
464 import math
465
466 extra_info = {}
467 extra_info['tasksizes'] = {}
468 extra_info['filesizes'] = {}
469 for root, _, files in os.walk(sstate_dir):
470 for fn in files:
471 if fn.endswith('.tgz'):
472 fsize = int(math.ceil(float(os.path.getsize(os.path.join(root, fn))) / 1024))
473 task = fn.rsplit(':',1)[1].split('_',1)[1].split(',')[0]
474 origtotal = extra_info['tasksizes'].get(task, 0)
475 extra_info['tasksizes'][task] = origtotal + fsize
476 extra_info['filesizes'][fn] = fsize
477 return extra_info
478
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500479if __name__ == "__main__":
480 pass