blob: d6a503372a3c8026df37469249e7b69932904d20 [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
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500165 rpm_repo_workdir = "oe-sdk-repo"
166 if "sdk_ext" in d.getVar("BB_RUNTASK"):
167 rpm_repo_workdir = "oe-sdk-ext-repo"
168
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500169 self.target_pm = RpmPM(d,
170 self.sdk_target_sysroot,
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500171 self.d.getVar('TARGET_VENDOR'),
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500172 'target',
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500173 rpm_repo_workdir=rpm_repo_workdir
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500174 )
175
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500176 self.host_pm = RpmPM(d,
177 self.sdk_host_sysroot,
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500178 self.d.getVar('SDK_VENDOR'),
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500179 'host',
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500180 "SDK_PACKAGE_ARCHS",
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500181 "SDK_OS",
182 rpm_repo_workdir=rpm_repo_workdir
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500183 )
184
185 def _populate_sysroot(self, pm, manifest):
186 pkgs_to_install = manifest.parse_initial_manifest()
187
188 pm.create_configs()
189 pm.write_index()
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500190 pm.update()
191
192 pkgs = []
193 pkgs_attempt = []
194 for pkg_type in pkgs_to_install:
195 if pkg_type == Manifest.PKG_TYPE_ATTEMPT_ONLY:
196 pkgs_attempt += pkgs_to_install[pkg_type]
197 else:
198 pkgs += pkgs_to_install[pkg_type]
199
200 pm.install(pkgs)
201
202 pm.install(pkgs_attempt, True)
203
204 def _populate(self):
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500205 execute_pre_post_process(self.d, self.d.getVar("POPULATE_SDK_PRE_TARGET_COMMAND"))
206
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500207 bb.note("Installing TARGET packages")
208 self._populate_sysroot(self.target_pm, self.target_manifest)
209
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500210 self.target_pm.install_complementary(self.d.getVar('SDKIMAGE_INSTALL_COMPLEMENTARY'))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500211
Brad Bishop316dfdd2018-06-25 12:45:53 -0400212 self.target_pm.run_intercepts()
213
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500214 execute_pre_post_process(self.d, self.d.getVar("POPULATE_SDK_POST_TARGET_COMMAND"))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500215
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600216 if not bb.utils.contains("SDKIMAGE_FEATURES", "package-management", True, False, self.d):
217 self.target_pm.remove_packaging_data()
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500218
219 bb.note("Installing NATIVESDK packages")
220 self._populate_sysroot(self.host_pm, self.host_manifest)
Brad Bishop00111322018-04-01 22:23:53 -0400221 self.install_locales(self.host_pm)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500222
Brad Bishop316dfdd2018-06-25 12:45:53 -0400223 self.host_pm.run_intercepts()
224
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500225 execute_pre_post_process(self.d, self.d.getVar("POPULATE_SDK_POST_HOST_COMMAND"))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500226
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600227 if not bb.utils.contains("SDKIMAGE_FEATURES", "package-management", True, False, self.d):
228 self.host_pm.remove_packaging_data()
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500229
230 # Move host RPM library data
231 native_rpm_state_dir = os.path.join(self.sdk_output,
232 self.sdk_native_path,
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500233 self.d.getVar('localstatedir_nativesdk').strip('/'),
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500234 "lib",
235 "rpm"
236 )
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500237 self.mkdirhier(native_rpm_state_dir)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500238 for f in glob.glob(os.path.join(self.sdk_output,
239 "var",
240 "lib",
241 "rpm",
242 "*")):
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500243 self.movefile(f, native_rpm_state_dir)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500244
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500245 self.remove(os.path.join(self.sdk_output, "var"), True)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500246
247 # Move host sysconfig data
248 native_sysconf_dir = os.path.join(self.sdk_output,
249 self.sdk_native_path,
250 self.d.getVar('sysconfdir',
251 True).strip('/'),
252 )
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500253 self.mkdirhier(native_sysconf_dir)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500254 for f in glob.glob(os.path.join(self.sdk_output, "etc", "rpm*")):
255 self.movefile(f, native_sysconf_dir)
256 for f in glob.glob(os.path.join(self.sdk_output, "etc", "dnf", "*")):
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500257 self.movefile(f, native_sysconf_dir)
258 self.remove(os.path.join(self.sdk_output, "etc"), True)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500259
260
261class OpkgSdk(Sdk):
262 def __init__(self, d, manifest_dir=None):
263 super(OpkgSdk, self).__init__(d, manifest_dir)
264
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500265 self.target_conf = self.d.getVar("IPKGCONF_TARGET")
266 self.host_conf = self.d.getVar("IPKGCONF_SDK")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500267
268 self.target_manifest = OpkgManifest(d, self.manifest_dir,
269 Manifest.MANIFEST_TYPE_SDK_TARGET)
270 self.host_manifest = OpkgManifest(d, self.manifest_dir,
271 Manifest.MANIFEST_TYPE_SDK_HOST)
272
273 self.target_pm = OpkgPM(d, self.sdk_target_sysroot, self.target_conf,
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500274 self.d.getVar("ALL_MULTILIB_PACKAGE_ARCHS"))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500275
276 self.host_pm = OpkgPM(d, self.sdk_host_sysroot, self.host_conf,
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500277 self.d.getVar("SDK_PACKAGE_ARCHS"))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500278
279 def _populate_sysroot(self, pm, manifest):
280 pkgs_to_install = manifest.parse_initial_manifest()
281
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500282 if (self.d.getVar('BUILD_IMAGES_FROM_FEEDS') or "") != "1":
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500283 pm.write_index()
284
285 pm.update()
286
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500287 for pkg_type in self.install_order:
288 if pkg_type in pkgs_to_install:
289 pm.install(pkgs_to_install[pkg_type],
290 [False, True][pkg_type == Manifest.PKG_TYPE_ATTEMPT_ONLY])
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500291
292 def _populate(self):
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500293 execute_pre_post_process(self.d, self.d.getVar("POPULATE_SDK_PRE_TARGET_COMMAND"))
294
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500295 bb.note("Installing TARGET packages")
296 self._populate_sysroot(self.target_pm, self.target_manifest)
297
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500298 self.target_pm.install_complementary(self.d.getVar('SDKIMAGE_INSTALL_COMPLEMENTARY'))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500299
Brad Bishop316dfdd2018-06-25 12:45:53 -0400300 self.target_pm.run_intercepts()
301
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500302 execute_pre_post_process(self.d, self.d.getVar("POPULATE_SDK_POST_TARGET_COMMAND"))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500303
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600304 if not bb.utils.contains("SDKIMAGE_FEATURES", "package-management", True, False, self.d):
305 self.target_pm.remove_packaging_data()
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500306
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500307 bb.note("Installing NATIVESDK packages")
308 self._populate_sysroot(self.host_pm, self.host_manifest)
Brad Bishop00111322018-04-01 22:23:53 -0400309 self.install_locales(self.host_pm)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500310
Brad Bishop316dfdd2018-06-25 12:45:53 -0400311 self.host_pm.run_intercepts()
312
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500313 execute_pre_post_process(self.d, self.d.getVar("POPULATE_SDK_POST_HOST_COMMAND"))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500314
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600315 if not bb.utils.contains("SDKIMAGE_FEATURES", "package-management", True, False, self.d):
316 self.host_pm.remove_packaging_data()
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500317
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500318 target_sysconfdir = os.path.join(self.sdk_target_sysroot, self.sysconfdir)
319 host_sysconfdir = os.path.join(self.sdk_host_sysroot, self.sysconfdir)
320
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500321 self.mkdirhier(target_sysconfdir)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500322 shutil.copy(self.target_conf, target_sysconfdir)
323 os.chmod(os.path.join(target_sysconfdir,
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600324 os.path.basename(self.target_conf)), 0o644)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500325
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500326 self.mkdirhier(host_sysconfdir)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500327 shutil.copy(self.host_conf, host_sysconfdir)
328 os.chmod(os.path.join(host_sysconfdir,
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600329 os.path.basename(self.host_conf)), 0o644)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500330
331 native_opkg_state_dir = os.path.join(self.sdk_output, self.sdk_native_path,
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500332 self.d.getVar('localstatedir_nativesdk').strip('/'),
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500333 "lib", "opkg")
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500334 self.mkdirhier(native_opkg_state_dir)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500335 for f in glob.glob(os.path.join(self.sdk_output, "var", "lib", "opkg", "*")):
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500336 self.movefile(f, native_opkg_state_dir)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500337
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500338 self.remove(os.path.join(self.sdk_output, "var"), True)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500339
340
341class DpkgSdk(Sdk):
342 def __init__(self, d, manifest_dir=None):
343 super(DpkgSdk, self).__init__(d, manifest_dir)
344
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500345 self.target_conf_dir = os.path.join(self.d.getVar("APTCONF_TARGET"), "apt")
346 self.host_conf_dir = os.path.join(self.d.getVar("APTCONF_TARGET"), "apt-sdk")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500347
348 self.target_manifest = DpkgManifest(d, self.manifest_dir,
349 Manifest.MANIFEST_TYPE_SDK_TARGET)
350 self.host_manifest = DpkgManifest(d, self.manifest_dir,
351 Manifest.MANIFEST_TYPE_SDK_HOST)
352
353 self.target_pm = DpkgPM(d, self.sdk_target_sysroot,
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500354 self.d.getVar("PACKAGE_ARCHS"),
355 self.d.getVar("DPKG_ARCH"),
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500356 self.target_conf_dir)
357
358 self.host_pm = DpkgPM(d, self.sdk_host_sysroot,
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500359 self.d.getVar("SDK_PACKAGE_ARCHS"),
360 self.d.getVar("DEB_SDK_ARCH"),
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500361 self.host_conf_dir)
362
363 def _copy_apt_dir_to(self, dst_dir):
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500364 staging_etcdir_native = self.d.getVar("STAGING_ETCDIR_NATIVE")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500365
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500366 self.remove(dst_dir, True)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500367
368 shutil.copytree(os.path.join(staging_etcdir_native, "apt"), dst_dir)
369
370 def _populate_sysroot(self, pm, manifest):
371 pkgs_to_install = manifest.parse_initial_manifest()
372
373 pm.write_index()
374 pm.update()
375
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500376 for pkg_type in self.install_order:
377 if pkg_type in pkgs_to_install:
378 pm.install(pkgs_to_install[pkg_type],
379 [False, True][pkg_type == Manifest.PKG_TYPE_ATTEMPT_ONLY])
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500380
381 def _populate(self):
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500382 execute_pre_post_process(self.d, self.d.getVar("POPULATE_SDK_PRE_TARGET_COMMAND"))
383
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500384 bb.note("Installing TARGET packages")
385 self._populate_sysroot(self.target_pm, self.target_manifest)
386
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500387 self.target_pm.install_complementary(self.d.getVar('SDKIMAGE_INSTALL_COMPLEMENTARY'))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500388
Brad Bishop316dfdd2018-06-25 12:45:53 -0400389 self.target_pm.run_intercepts()
390
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500391 execute_pre_post_process(self.d, self.d.getVar("POPULATE_SDK_POST_TARGET_COMMAND"))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500392
393 self._copy_apt_dir_to(os.path.join(self.sdk_target_sysroot, "etc", "apt"))
394
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600395 if not bb.utils.contains("SDKIMAGE_FEATURES", "package-management", True, False, self.d):
396 self.target_pm.remove_packaging_data()
397
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500398 bb.note("Installing NATIVESDK packages")
399 self._populate_sysroot(self.host_pm, self.host_manifest)
Brad Bishop00111322018-04-01 22:23:53 -0400400 self.install_locales(self.host_pm)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500401
Brad Bishop316dfdd2018-06-25 12:45:53 -0400402 self.host_pm.run_intercepts()
403
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500404 execute_pre_post_process(self.d, self.d.getVar("POPULATE_SDK_POST_HOST_COMMAND"))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500405
406 self._copy_apt_dir_to(os.path.join(self.sdk_output, self.sdk_native_path,
407 "etc", "apt"))
408
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600409 if not bb.utils.contains("SDKIMAGE_FEATURES", "package-management", True, False, self.d):
410 self.host_pm.remove_packaging_data()
411
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500412 native_dpkg_state_dir = os.path.join(self.sdk_output, self.sdk_native_path,
413 "var", "lib", "dpkg")
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500414 self.mkdirhier(native_dpkg_state_dir)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500415 for f in glob.glob(os.path.join(self.sdk_output, "var", "lib", "dpkg", "*")):
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500416 self.movefile(f, native_dpkg_state_dir)
417 self.remove(os.path.join(self.sdk_output, "var"), True)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500418
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500419
420
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500421def sdk_list_installed_packages(d, target, rootfs_dir=None):
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500422 if rootfs_dir is None:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500423 sdk_output = d.getVar('SDK_OUTPUT')
424 target_path = d.getVar('SDKTARGETSYSROOT').strip('/')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500425
426 rootfs_dir = [sdk_output, os.path.join(sdk_output, target_path)][target is True]
427
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500428 img_type = d.getVar('IMAGE_PKGTYPE')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500429 if img_type == "rpm":
430 arch_var = ["SDK_PACKAGE_ARCHS", None][target is True]
431 os_var = ["SDK_OS", None][target is True]
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500432 return RpmPkgsList(d, rootfs_dir).list_pkgs()
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500433 elif img_type == "ipk":
434 conf_file_var = ["IPKGCONF_SDK", "IPKGCONF_TARGET"][target is True]
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500435 return OpkgPkgsList(d, rootfs_dir, d.getVar(conf_file_var)).list_pkgs()
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500436 elif img_type == "deb":
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500437 return DpkgPkgsList(d, rootfs_dir).list_pkgs()
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500438
439def populate_sdk(d, manifest_dir=None):
440 env_bkp = os.environ.copy()
441
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500442 img_type = d.getVar('IMAGE_PKGTYPE')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500443 if img_type == "rpm":
444 RpmSdk(d, manifest_dir).populate()
445 elif img_type == "ipk":
446 OpkgSdk(d, manifest_dir).populate()
447 elif img_type == "deb":
448 DpkgSdk(d, manifest_dir).populate()
449
450 os.environ.clear()
451 os.environ.update(env_bkp)
452
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500453def get_extra_sdkinfo(sstate_dir):
454 """
455 This function is going to be used for generating the target and host manifest files packages of eSDK.
456 """
457 import math
458
459 extra_info = {}
460 extra_info['tasksizes'] = {}
461 extra_info['filesizes'] = {}
462 for root, _, files in os.walk(sstate_dir):
463 for fn in files:
464 if fn.endswith('.tgz'):
465 fsize = int(math.ceil(float(os.path.getsize(os.path.join(root, fn))) / 1024))
466 task = fn.rsplit(':',1)[1].split('_',1)[1].split(',')[0]
467 origtotal = extra_info['tasksizes'].get(task, 0)
468 extra_info['tasksizes'][task] = origtotal + fsize
469 extra_info['filesizes'][fn] = fsize
470 return extra_info
471
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500472if __name__ == "__main__":
473 pass