blob: c74525f929b6c39551b132cd495370a19e4ce448 [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
14 self.sdk_output = self.d.getVar('SDK_OUTPUT', True)
15 self.sdk_native_path = self.d.getVar('SDKPATHNATIVE', True).strip('/')
16 self.target_path = self.d.getVar('SDKTARGETSYSROOT', True).strip('/')
17 self.sysconfdir = self.d.getVar('sysconfdir', True).strip('/')
18
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:
23 self.manifest_dir = self.d.getVar("SDK_DIR", True)
24 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,
43 self.d.getVar('libdir_nativesdk', True).strip('/'),
44 "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,
48 self.d.getVar('libdir_nativesdk', True).strip('/'),
49 "*.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
57 execute_pre_post_process(self.d, self.d.getVar('SDK_POSTPROCESS_COMMAND', True))
58
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):
88 def __init__(self, d, manifest_dir=None):
89 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
103 self.target_pm = RpmPM(d,
104 self.sdk_target_sysroot,
105 self.d.getVar('TARGET_VENDOR', True),
106 'target',
107 target_providename
108 )
109
110 sdk_providename = ['/bin/sh',
111 '/bin/bash',
112 '/usr/bin/env',
113 '/usr/bin/perl',
114 'pkgconfig',
115 'libGL.so()(64bit)',
116 'libGL.so'
117 ]
118
119 self.host_pm = RpmPM(d,
120 self.sdk_host_sysroot,
121 self.d.getVar('SDK_VENDOR', True),
122 'host',
123 sdk_providename,
124 "SDK_PACKAGE_ARCHS",
125 "SDK_OS"
126 )
127
128 def _populate_sysroot(self, pm, manifest):
129 pkgs_to_install = manifest.parse_initial_manifest()
130
131 pm.create_configs()
132 pm.write_index()
133 pm.dump_all_available_pkgs()
134 pm.update()
135
136 pkgs = []
137 pkgs_attempt = []
138 for pkg_type in pkgs_to_install:
139 if pkg_type == Manifest.PKG_TYPE_ATTEMPT_ONLY:
140 pkgs_attempt += pkgs_to_install[pkg_type]
141 else:
142 pkgs += pkgs_to_install[pkg_type]
143
144 pm.install(pkgs)
145
146 pm.install(pkgs_attempt, True)
147
148 def _populate(self):
149 bb.note("Installing TARGET packages")
150 self._populate_sysroot(self.target_pm, self.target_manifest)
151
152 self.target_pm.install_complementary(self.d.getVar('SDKIMAGE_INSTALL_COMPLEMENTARY', True))
153
154 execute_pre_post_process(self.d, self.d.getVar("POPULATE_SDK_POST_TARGET_COMMAND", True))
155
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600156 if not bb.utils.contains("SDKIMAGE_FEATURES", "package-management", True, False, self.d):
157 self.target_pm.remove_packaging_data()
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500158
159 bb.note("Installing NATIVESDK packages")
160 self._populate_sysroot(self.host_pm, self.host_manifest)
161
162 execute_pre_post_process(self.d, self.d.getVar("POPULATE_SDK_POST_HOST_COMMAND", True))
163
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600164 if not bb.utils.contains("SDKIMAGE_FEATURES", "package-management", True, False, self.d):
165 self.host_pm.remove_packaging_data()
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500166
167 # Move host RPM library data
168 native_rpm_state_dir = os.path.join(self.sdk_output,
169 self.sdk_native_path,
170 self.d.getVar('localstatedir_nativesdk', True).strip('/'),
171 "lib",
172 "rpm"
173 )
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500174 self.mkdirhier(native_rpm_state_dir)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500175 for f in glob.glob(os.path.join(self.sdk_output,
176 "var",
177 "lib",
178 "rpm",
179 "*")):
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500180 self.movefile(f, native_rpm_state_dir)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500181
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500182 self.remove(os.path.join(self.sdk_output, "var"), True)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500183
184 # Move host sysconfig data
185 native_sysconf_dir = os.path.join(self.sdk_output,
186 self.sdk_native_path,
187 self.d.getVar('sysconfdir',
188 True).strip('/'),
189 )
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500190 self.mkdirhier(native_sysconf_dir)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500191 for f in glob.glob(os.path.join(self.sdk_output, "etc", "*")):
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500192 self.movefile(f, native_sysconf_dir)
193 self.remove(os.path.join(self.sdk_output, "etc"), True)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500194
195
196class OpkgSdk(Sdk):
197 def __init__(self, d, manifest_dir=None):
198 super(OpkgSdk, self).__init__(d, manifest_dir)
199
200 self.target_conf = self.d.getVar("IPKGCONF_TARGET", True)
201 self.host_conf = self.d.getVar("IPKGCONF_SDK", True)
202
203 self.target_manifest = OpkgManifest(d, self.manifest_dir,
204 Manifest.MANIFEST_TYPE_SDK_TARGET)
205 self.host_manifest = OpkgManifest(d, self.manifest_dir,
206 Manifest.MANIFEST_TYPE_SDK_HOST)
207
208 self.target_pm = OpkgPM(d, self.sdk_target_sysroot, self.target_conf,
209 self.d.getVar("ALL_MULTILIB_PACKAGE_ARCHS", True))
210
211 self.host_pm = OpkgPM(d, self.sdk_host_sysroot, self.host_conf,
212 self.d.getVar("SDK_PACKAGE_ARCHS", True))
213
214 def _populate_sysroot(self, pm, manifest):
215 pkgs_to_install = manifest.parse_initial_manifest()
216
217 if (self.d.getVar('BUILD_IMAGES_FROM_FEEDS', True) or "") != "1":
218 pm.write_index()
219
220 pm.update()
221
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500222 for pkg_type in self.install_order:
223 if pkg_type in pkgs_to_install:
224 pm.install(pkgs_to_install[pkg_type],
225 [False, True][pkg_type == Manifest.PKG_TYPE_ATTEMPT_ONLY])
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500226
227 def _populate(self):
228 bb.note("Installing TARGET packages")
229 self._populate_sysroot(self.target_pm, self.target_manifest)
230
231 self.target_pm.install_complementary(self.d.getVar('SDKIMAGE_INSTALL_COMPLEMENTARY', True))
232
233 execute_pre_post_process(self.d, self.d.getVar("POPULATE_SDK_POST_TARGET_COMMAND", True))
234
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600235 if not bb.utils.contains("SDKIMAGE_FEATURES", "package-management", True, False, self.d):
236 self.target_pm.remove_packaging_data()
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500237
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500238 bb.note("Installing NATIVESDK packages")
239 self._populate_sysroot(self.host_pm, self.host_manifest)
240
241 execute_pre_post_process(self.d, self.d.getVar("POPULATE_SDK_POST_HOST_COMMAND", True))
242
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600243 if not bb.utils.contains("SDKIMAGE_FEATURES", "package-management", True, False, self.d):
244 self.host_pm.remove_packaging_data()
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500245
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500246 target_sysconfdir = os.path.join(self.sdk_target_sysroot, self.sysconfdir)
247 host_sysconfdir = os.path.join(self.sdk_host_sysroot, self.sysconfdir)
248
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500249 self.mkdirhier(target_sysconfdir)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500250 shutil.copy(self.target_conf, target_sysconfdir)
251 os.chmod(os.path.join(target_sysconfdir,
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600252 os.path.basename(self.target_conf)), 0o644)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500253
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500254 self.mkdirhier(host_sysconfdir)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500255 shutil.copy(self.host_conf, host_sysconfdir)
256 os.chmod(os.path.join(host_sysconfdir,
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600257 os.path.basename(self.host_conf)), 0o644)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500258
259 native_opkg_state_dir = os.path.join(self.sdk_output, self.sdk_native_path,
260 self.d.getVar('localstatedir_nativesdk', True).strip('/'),
261 "lib", "opkg")
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500262 self.mkdirhier(native_opkg_state_dir)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500263 for f in glob.glob(os.path.join(self.sdk_output, "var", "lib", "opkg", "*")):
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500264 self.movefile(f, native_opkg_state_dir)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500265
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500266 self.remove(os.path.join(self.sdk_output, "var"), True)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500267
268
269class DpkgSdk(Sdk):
270 def __init__(self, d, manifest_dir=None):
271 super(DpkgSdk, self).__init__(d, manifest_dir)
272
273 self.target_conf_dir = os.path.join(self.d.getVar("APTCONF_TARGET", True), "apt")
274 self.host_conf_dir = os.path.join(self.d.getVar("APTCONF_TARGET", True), "apt-sdk")
275
276 self.target_manifest = DpkgManifest(d, self.manifest_dir,
277 Manifest.MANIFEST_TYPE_SDK_TARGET)
278 self.host_manifest = DpkgManifest(d, self.manifest_dir,
279 Manifest.MANIFEST_TYPE_SDK_HOST)
280
281 self.target_pm = DpkgPM(d, self.sdk_target_sysroot,
282 self.d.getVar("PACKAGE_ARCHS", True),
283 self.d.getVar("DPKG_ARCH", True),
284 self.target_conf_dir)
285
286 self.host_pm = DpkgPM(d, self.sdk_host_sysroot,
287 self.d.getVar("SDK_PACKAGE_ARCHS", True),
288 self.d.getVar("DEB_SDK_ARCH", True),
289 self.host_conf_dir)
290
291 def _copy_apt_dir_to(self, dst_dir):
292 staging_etcdir_native = self.d.getVar("STAGING_ETCDIR_NATIVE", True)
293
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500294 self.remove(dst_dir, True)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500295
296 shutil.copytree(os.path.join(staging_etcdir_native, "apt"), dst_dir)
297
298 def _populate_sysroot(self, pm, manifest):
299 pkgs_to_install = manifest.parse_initial_manifest()
300
301 pm.write_index()
302 pm.update()
303
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500304 for pkg_type in self.install_order:
305 if pkg_type in pkgs_to_install:
306 pm.install(pkgs_to_install[pkg_type],
307 [False, True][pkg_type == Manifest.PKG_TYPE_ATTEMPT_ONLY])
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500308
309 def _populate(self):
310 bb.note("Installing TARGET packages")
311 self._populate_sysroot(self.target_pm, self.target_manifest)
312
313 self.target_pm.install_complementary(self.d.getVar('SDKIMAGE_INSTALL_COMPLEMENTARY', True))
314
315 execute_pre_post_process(self.d, self.d.getVar("POPULATE_SDK_POST_TARGET_COMMAND", True))
316
317 self._copy_apt_dir_to(os.path.join(self.sdk_target_sysroot, "etc", "apt"))
318
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600319 if not bb.utils.contains("SDKIMAGE_FEATURES", "package-management", True, False, self.d):
320 self.target_pm.remove_packaging_data()
321
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500322 bb.note("Installing NATIVESDK packages")
323 self._populate_sysroot(self.host_pm, self.host_manifest)
324
325 execute_pre_post_process(self.d, self.d.getVar("POPULATE_SDK_POST_HOST_COMMAND", True))
326
327 self._copy_apt_dir_to(os.path.join(self.sdk_output, self.sdk_native_path,
328 "etc", "apt"))
329
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600330 if not bb.utils.contains("SDKIMAGE_FEATURES", "package-management", True, False, self.d):
331 self.host_pm.remove_packaging_data()
332
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500333 native_dpkg_state_dir = os.path.join(self.sdk_output, self.sdk_native_path,
334 "var", "lib", "dpkg")
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500335 self.mkdirhier(native_dpkg_state_dir)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500336 for f in glob.glob(os.path.join(self.sdk_output, "var", "lib", "dpkg", "*")):
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500337 self.movefile(f, native_dpkg_state_dir)
338 self.remove(os.path.join(self.sdk_output, "var"), True)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500339
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500340
341
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500342def sdk_list_installed_packages(d, target, rootfs_dir=None):
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500343 if rootfs_dir is None:
344 sdk_output = d.getVar('SDK_OUTPUT', True)
345 target_path = d.getVar('SDKTARGETSYSROOT', True).strip('/')
346
347 rootfs_dir = [sdk_output, os.path.join(sdk_output, target_path)][target is True]
348
349 img_type = d.getVar('IMAGE_PKGTYPE', True)
350 if img_type == "rpm":
351 arch_var = ["SDK_PACKAGE_ARCHS", None][target is True]
352 os_var = ["SDK_OS", None][target is True]
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500353 return RpmPkgsList(d, rootfs_dir, arch_var, os_var).list_pkgs()
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500354 elif img_type == "ipk":
355 conf_file_var = ["IPKGCONF_SDK", "IPKGCONF_TARGET"][target is True]
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500356 return OpkgPkgsList(d, rootfs_dir, d.getVar(conf_file_var, True)).list_pkgs()
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500357 elif img_type == "deb":
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500358 return DpkgPkgsList(d, rootfs_dir).list_pkgs()
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500359
360def populate_sdk(d, manifest_dir=None):
361 env_bkp = os.environ.copy()
362
363 img_type = d.getVar('IMAGE_PKGTYPE', True)
364 if img_type == "rpm":
365 RpmSdk(d, manifest_dir).populate()
366 elif img_type == "ipk":
367 OpkgSdk(d, manifest_dir).populate()
368 elif img_type == "deb":
369 DpkgSdk(d, manifest_dir).populate()
370
371 os.environ.clear()
372 os.environ.update(env_bkp)
373
374if __name__ == "__main__":
375 pass