blob: f15fbdb368187468994c27cd1eda58debff542e4 [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
11class Sdk(object):
12 __metaclass__ = ABCMeta
13
14 def __init__(self, d, manifest_dir):
15 self.d = d
16 self.sdk_output = self.d.getVar('SDK_OUTPUT', True)
17 self.sdk_native_path = self.d.getVar('SDKPATHNATIVE', True).strip('/')
18 self.target_path = self.d.getVar('SDKTARGETSYSROOT', True).strip('/')
19 self.sysconfdir = self.d.getVar('sysconfdir', True).strip('/')
20
21 self.sdk_target_sysroot = os.path.join(self.sdk_output, self.target_path)
22 self.sdk_host_sysroot = self.sdk_output
23
24 if manifest_dir is None:
25 self.manifest_dir = self.d.getVar("SDK_DIR", True)
26 else:
27 self.manifest_dir = manifest_dir
28
Patrick Williamsf1e5d692016-03-30 15:21:19 -050029 self.remove(self.sdk_output, True)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050030
31 self.install_order = Manifest.INSTALL_ORDER
32
33 @abstractmethod
34 def _populate(self):
35 pass
36
37 def populate(self):
Patrick Williamsf1e5d692016-03-30 15:21:19 -050038 self.mkdirhier(self.sdk_output)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050039
40 # call backend dependent implementation
41 self._populate()
42
43 # Don't ship any libGL in the SDK
Patrick Williamsf1e5d692016-03-30 15:21:19 -050044 self.remove(os.path.join(self.sdk_output, self.sdk_native_path,
45 self.d.getVar('libdir_nativesdk', True).strip('/'),
46 "libGL*"))
Patrick Williamsc124f4f2015-09-15 14:41:29 -050047
48 # Fix or remove broken .la files
Patrick Williamsf1e5d692016-03-30 15:21:19 -050049 self.remove(os.path.join(self.sdk_output, self.sdk_native_path,
50 self.d.getVar('libdir_nativesdk', True).strip('/'),
51 "*.la"))
Patrick Williamsc124f4f2015-09-15 14:41:29 -050052
53 # Link the ld.so.cache file into the hosts filesystem
54 link_name = os.path.join(self.sdk_output, self.sdk_native_path,
55 self.sysconfdir, "ld.so.cache")
Patrick Williamsf1e5d692016-03-30 15:21:19 -050056 self.mkdirhier(os.path.dirname(link_name))
Patrick Williamsc124f4f2015-09-15 14:41:29 -050057 os.symlink("/etc/ld.so.cache", link_name)
58
59 execute_pre_post_process(self.d, self.d.getVar('SDK_POSTPROCESS_COMMAND', True))
60
Patrick Williamsf1e5d692016-03-30 15:21:19 -050061 def movefile(self, sourcefile, destdir):
62 try:
63 # FIXME: this check of movefile's return code to None should be
64 # fixed within the function to use only exceptions to signal when
65 # something goes wrong
66 if (bb.utils.movefile(sourcefile, destdir) == None):
67 raise OSError("moving %s to %s failed"
68 %(sourcefile, destdir))
69 #FIXME: using umbrella exc catching because bb.utils method raises it
70 except Exception as e:
71 bb.debug(1, "printing the stack trace\n %s" %traceback.format_exc())
72 bb.error("unable to place %s in final SDK location" % sourcefile)
73
74 def mkdirhier(self, dirpath):
75 try:
76 bb.utils.mkdirhier(dirpath)
77 except OSError as e:
78 bb.debug(1, "printing the stack trace\n %s" %traceback.format_exc())
79 bb.fatal("cannot make dir for SDK: %s" % dirpath)
80
81 def remove(self, path, recurse=False):
82 try:
83 bb.utils.remove(path, recurse)
84 #FIXME: using umbrella exc catching because bb.utils method raises it
85 except Exception as e:
86 bb.debug(1, "printing the stack trace\n %s" %traceback.format_exc())
87 bb.warn("cannot remove SDK dir: %s" % path)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050088
89class RpmSdk(Sdk):
90 def __init__(self, d, manifest_dir=None):
91 super(RpmSdk, self).__init__(d, manifest_dir)
92
93 self.target_manifest = RpmManifest(d, self.manifest_dir,
94 Manifest.MANIFEST_TYPE_SDK_TARGET)
95 self.host_manifest = RpmManifest(d, self.manifest_dir,
96 Manifest.MANIFEST_TYPE_SDK_HOST)
97
98 target_providename = ['/bin/sh',
99 '/bin/bash',
100 '/usr/bin/env',
101 '/usr/bin/perl',
102 'pkgconfig'
103 ]
104
105 self.target_pm = RpmPM(d,
106 self.sdk_target_sysroot,
107 self.d.getVar('TARGET_VENDOR', True),
108 'target',
109 target_providename
110 )
111
112 sdk_providename = ['/bin/sh',
113 '/bin/bash',
114 '/usr/bin/env',
115 '/usr/bin/perl',
116 'pkgconfig',
117 'libGL.so()(64bit)',
118 'libGL.so'
119 ]
120
121 self.host_pm = RpmPM(d,
122 self.sdk_host_sysroot,
123 self.d.getVar('SDK_VENDOR', True),
124 'host',
125 sdk_providename,
126 "SDK_PACKAGE_ARCHS",
127 "SDK_OS"
128 )
129
130 def _populate_sysroot(self, pm, manifest):
131 pkgs_to_install = manifest.parse_initial_manifest()
132
133 pm.create_configs()
134 pm.write_index()
135 pm.dump_all_available_pkgs()
136 pm.update()
137
138 pkgs = []
139 pkgs_attempt = []
140 for pkg_type in pkgs_to_install:
141 if pkg_type == Manifest.PKG_TYPE_ATTEMPT_ONLY:
142 pkgs_attempt += pkgs_to_install[pkg_type]
143 else:
144 pkgs += pkgs_to_install[pkg_type]
145
146 pm.install(pkgs)
147
148 pm.install(pkgs_attempt, True)
149
150 def _populate(self):
151 bb.note("Installing TARGET packages")
152 self._populate_sysroot(self.target_pm, self.target_manifest)
153
154 self.target_pm.install_complementary(self.d.getVar('SDKIMAGE_INSTALL_COMPLEMENTARY', True))
155
156 execute_pre_post_process(self.d, self.d.getVar("POPULATE_SDK_POST_TARGET_COMMAND", True))
157
158 self.target_pm.remove_packaging_data()
159
160 bb.note("Installing NATIVESDK packages")
161 self._populate_sysroot(self.host_pm, self.host_manifest)
162
163 execute_pre_post_process(self.d, self.d.getVar("POPULATE_SDK_POST_HOST_COMMAND", True))
164
165 self.host_pm.remove_packaging_data()
166
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 Williamsd8c66bc2016-06-20 12:57:21 -0500235 self.target_pm.remove_packaging_data()
236
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500237 bb.note("Installing NATIVESDK packages")
238 self._populate_sysroot(self.host_pm, self.host_manifest)
239
240 execute_pre_post_process(self.d, self.d.getVar("POPULATE_SDK_POST_HOST_COMMAND", True))
241
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500242 self.host_pm.remove_packaging_data()
243
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500244 target_sysconfdir = os.path.join(self.sdk_target_sysroot, self.sysconfdir)
245 host_sysconfdir = os.path.join(self.sdk_host_sysroot, self.sysconfdir)
246
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500247 self.mkdirhier(target_sysconfdir)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500248 shutil.copy(self.target_conf, target_sysconfdir)
249 os.chmod(os.path.join(target_sysconfdir,
250 os.path.basename(self.target_conf)), 0644)
251
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500252 self.mkdirhier(host_sysconfdir)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500253 shutil.copy(self.host_conf, host_sysconfdir)
254 os.chmod(os.path.join(host_sysconfdir,
255 os.path.basename(self.host_conf)), 0644)
256
257 native_opkg_state_dir = os.path.join(self.sdk_output, self.sdk_native_path,
258 self.d.getVar('localstatedir_nativesdk', True).strip('/'),
259 "lib", "opkg")
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500260 self.mkdirhier(native_opkg_state_dir)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500261 for f in glob.glob(os.path.join(self.sdk_output, "var", "lib", "opkg", "*")):
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500262 self.movefile(f, native_opkg_state_dir)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500263
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500264 self.remove(os.path.join(self.sdk_output, "var"), True)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500265
266
267class DpkgSdk(Sdk):
268 def __init__(self, d, manifest_dir=None):
269 super(DpkgSdk, self).__init__(d, manifest_dir)
270
271 self.target_conf_dir = os.path.join(self.d.getVar("APTCONF_TARGET", True), "apt")
272 self.host_conf_dir = os.path.join(self.d.getVar("APTCONF_TARGET", True), "apt-sdk")
273
274 self.target_manifest = DpkgManifest(d, self.manifest_dir,
275 Manifest.MANIFEST_TYPE_SDK_TARGET)
276 self.host_manifest = DpkgManifest(d, self.manifest_dir,
277 Manifest.MANIFEST_TYPE_SDK_HOST)
278
279 self.target_pm = DpkgPM(d, self.sdk_target_sysroot,
280 self.d.getVar("PACKAGE_ARCHS", True),
281 self.d.getVar("DPKG_ARCH", True),
282 self.target_conf_dir)
283
284 self.host_pm = DpkgPM(d, self.sdk_host_sysroot,
285 self.d.getVar("SDK_PACKAGE_ARCHS", True),
286 self.d.getVar("DEB_SDK_ARCH", True),
287 self.host_conf_dir)
288
289 def _copy_apt_dir_to(self, dst_dir):
290 staging_etcdir_native = self.d.getVar("STAGING_ETCDIR_NATIVE", True)
291
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500292 self.remove(dst_dir, True)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500293
294 shutil.copytree(os.path.join(staging_etcdir_native, "apt"), dst_dir)
295
296 def _populate_sysroot(self, pm, manifest):
297 pkgs_to_install = manifest.parse_initial_manifest()
298
299 pm.write_index()
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):
308 bb.note("Installing TARGET packages")
309 self._populate_sysroot(self.target_pm, self.target_manifest)
310
311 self.target_pm.install_complementary(self.d.getVar('SDKIMAGE_INSTALL_COMPLEMENTARY', True))
312
313 execute_pre_post_process(self.d, self.d.getVar("POPULATE_SDK_POST_TARGET_COMMAND", True))
314
315 self._copy_apt_dir_to(os.path.join(self.sdk_target_sysroot, "etc", "apt"))
316
317 bb.note("Installing NATIVESDK packages")
318 self._populate_sysroot(self.host_pm, self.host_manifest)
319
320 execute_pre_post_process(self.d, self.d.getVar("POPULATE_SDK_POST_HOST_COMMAND", True))
321
322 self._copy_apt_dir_to(os.path.join(self.sdk_output, self.sdk_native_path,
323 "etc", "apt"))
324
325 native_dpkg_state_dir = os.path.join(self.sdk_output, self.sdk_native_path,
326 "var", "lib", "dpkg")
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500327 self.mkdirhier(native_dpkg_state_dir)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500328 for f in glob.glob(os.path.join(self.sdk_output, "var", "lib", "dpkg", "*")):
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500329 self.movefile(f, native_dpkg_state_dir)
330 self.remove(os.path.join(self.sdk_output, "var"), True)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500331
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500332
333
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500334def sdk_list_installed_packages(d, target, rootfs_dir=None):
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500335 if rootfs_dir is None:
336 sdk_output = d.getVar('SDK_OUTPUT', True)
337 target_path = d.getVar('SDKTARGETSYSROOT', True).strip('/')
338
339 rootfs_dir = [sdk_output, os.path.join(sdk_output, target_path)][target is True]
340
341 img_type = d.getVar('IMAGE_PKGTYPE', True)
342 if img_type == "rpm":
343 arch_var = ["SDK_PACKAGE_ARCHS", None][target is True]
344 os_var = ["SDK_OS", None][target is True]
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500345 return RpmPkgsList(d, rootfs_dir, arch_var, os_var).list_pkgs()
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500346 elif img_type == "ipk":
347 conf_file_var = ["IPKGCONF_SDK", "IPKGCONF_TARGET"][target is True]
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500348 return OpkgPkgsList(d, rootfs_dir, d.getVar(conf_file_var, True)).list_pkgs()
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500349 elif img_type == "deb":
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500350 return DpkgPkgsList(d, rootfs_dir).list_pkgs()
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500351
352def populate_sdk(d, manifest_dir=None):
353 env_bkp = os.environ.copy()
354
355 img_type = d.getVar('IMAGE_PKGTYPE', True)
356 if img_type == "rpm":
357 RpmSdk(d, manifest_dir).populate()
358 elif img_type == "ipk":
359 OpkgSdk(d, manifest_dir).populate()
360 elif img_type == "deb":
361 DpkgSdk(d, manifest_dir).populate()
362
363 os.environ.clear()
364 os.environ.update(env_bkp)
365
366if __name__ == "__main__":
367 pass