blob: 37b59afd1a9990c3c29d169e260c8d2ea3f75315 [file] [log] [blame]
Brad Bishopc342db32019-05-15 21:57:59 -04001#
2# SPDX-License-Identifier: GPL-2.0-only
3#
4
Patrick Williamsc124f4f2015-09-15 14:41:29 -05005from abc import ABCMeta, abstractmethod
6from oe.utils import execute_pre_post_process
7from oe.manifest import *
8from oe.package_manager import *
9import os
Patrick Williamsf1e5d692016-03-30 15:21:19 -050010import traceback
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011
Patrick Williamsc0f7c042017-02-23 20:41:17 -060012class Sdk(object, metaclass=ABCMeta):
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013 def __init__(self, d, manifest_dir):
14 self.d = d
Brad Bishop6e60e8b2018-02-01 10:27:11 -050015 self.sdk_output = self.d.getVar('SDK_OUTPUT')
16 self.sdk_native_path = self.d.getVar('SDKPATHNATIVE').strip('/')
17 self.target_path = self.d.getVar('SDKTARGETSYSROOT').strip('/')
18 self.sysconfdir = self.d.getVar('sysconfdir').strip('/')
Patrick Williamsc124f4f2015-09-15 14:41:29 -050019
20 self.sdk_target_sysroot = os.path.join(self.sdk_output, self.target_path)
21 self.sdk_host_sysroot = self.sdk_output
22
23 if manifest_dir is None:
Brad Bishop6e60e8b2018-02-01 10:27:11 -050024 self.manifest_dir = self.d.getVar("SDK_DIR")
Patrick Williamsc124f4f2015-09-15 14:41:29 -050025 else:
26 self.manifest_dir = manifest_dir
27
Patrick Williamsf1e5d692016-03-30 15:21:19 -050028 self.remove(self.sdk_output, True)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050029
30 self.install_order = Manifest.INSTALL_ORDER
31
32 @abstractmethod
33 def _populate(self):
34 pass
35
36 def populate(self):
Patrick Williamsf1e5d692016-03-30 15:21:19 -050037 self.mkdirhier(self.sdk_output)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050038
39 # call backend dependent implementation
40 self._populate()
41
42 # Don't ship any libGL in the SDK
Patrick Williamsf1e5d692016-03-30 15:21:19 -050043 self.remove(os.path.join(self.sdk_output, self.sdk_native_path,
Brad Bishop6e60e8b2018-02-01 10:27:11 -050044 self.d.getVar('libdir_nativesdk').strip('/'),
Patrick Williamsf1e5d692016-03-30 15:21:19 -050045 "libGL*"))
Patrick Williamsc124f4f2015-09-15 14:41:29 -050046
47 # Fix or remove broken .la files
Patrick Williamsf1e5d692016-03-30 15:21:19 -050048 self.remove(os.path.join(self.sdk_output, self.sdk_native_path,
Brad Bishop6e60e8b2018-02-01 10:27:11 -050049 self.d.getVar('libdir_nativesdk').strip('/'),
Patrick Williamsf1e5d692016-03-30 15:21:19 -050050 "*.la"))
Patrick Williamsc124f4f2015-09-15 14:41:29 -050051
52 # Link the ld.so.cache file into the hosts filesystem
53 link_name = os.path.join(self.sdk_output, self.sdk_native_path,
54 self.sysconfdir, "ld.so.cache")
Patrick Williamsf1e5d692016-03-30 15:21:19 -050055 self.mkdirhier(os.path.dirname(link_name))
Patrick Williamsc124f4f2015-09-15 14:41:29 -050056 os.symlink("/etc/ld.so.cache", link_name)
57
Brad Bishop6e60e8b2018-02-01 10:27:11 -050058 execute_pre_post_process(self.d, self.d.getVar('SDK_POSTPROCESS_COMMAND'))
Patrick Williamsc124f4f2015-09-15 14:41:29 -050059
Patrick Williamsf1e5d692016-03-30 15:21:19 -050060 def movefile(self, sourcefile, destdir):
61 try:
62 # FIXME: this check of movefile's return code to None should be
63 # fixed within the function to use only exceptions to signal when
64 # something goes wrong
65 if (bb.utils.movefile(sourcefile, destdir) == None):
66 raise OSError("moving %s to %s failed"
67 %(sourcefile, destdir))
68 #FIXME: using umbrella exc catching because bb.utils method raises it
69 except Exception as e:
70 bb.debug(1, "printing the stack trace\n %s" %traceback.format_exc())
71 bb.error("unable to place %s in final SDK location" % sourcefile)
72
73 def mkdirhier(self, dirpath):
74 try:
75 bb.utils.mkdirhier(dirpath)
76 except OSError as e:
77 bb.debug(1, "printing the stack trace\n %s" %traceback.format_exc())
78 bb.fatal("cannot make dir for SDK: %s" % dirpath)
79
80 def remove(self, path, recurse=False):
81 try:
82 bb.utils.remove(path, recurse)
83 #FIXME: using umbrella exc catching because bb.utils method raises it
84 except Exception as e:
85 bb.debug(1, "printing the stack trace\n %s" %traceback.format_exc())
86 bb.warn("cannot remove SDK dir: %s" % path)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050087
Brad Bishop00111322018-04-01 22:23:53 -040088 def install_locales(self, pm):
Brad Bishop00111322018-04-01 22:23:53 -040089 linguas = self.d.getVar("SDKIMAGE_LINGUAS")
90 if linguas:
91 import fnmatch
92 # Install the binary locales
93 if linguas == "all":
94 pm.install_glob("nativesdk-glibc-binary-localedata-*.utf-8", sdk=True)
95 else:
Brad Bishop19323692019-04-05 15:28:33 -040096 pm.install(["nativesdk-glibc-binary-localedata-%s.utf-8" % \
97 lang for lang in linguas.split()])
Brad Bishop00111322018-04-01 22:23:53 -040098 # Generate a locale archive of them
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080099 target_arch = self.d.getVar('SDK_ARCH')
100 rootfs = oe.path.join(self.sdk_host_sysroot, self.sdk_native_path)
101 localedir = oe.path.join(rootfs, self.d.getVar("libdir_nativesdk"), "locale")
102 generate_locale_archive(self.d, rootfs, target_arch, localedir)
Brad Bishop00111322018-04-01 22:23:53 -0400103 # And now delete the binary locales
104 pkgs = fnmatch.filter(pm.list_installed(), "nativesdk-glibc-binary-localedata-*.utf-8")
105 pm.remove(pkgs)
106 else:
107 # No linguas so do nothing
108 pass
109
110
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500111def sdk_list_installed_packages(d, target, rootfs_dir=None):
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500112 if rootfs_dir is None:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500113 sdk_output = d.getVar('SDK_OUTPUT')
114 target_path = d.getVar('SDKTARGETSYSROOT').strip('/')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500115
116 rootfs_dir = [sdk_output, os.path.join(sdk_output, target_path)][target is True]
117
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500118 img_type = d.getVar('IMAGE_PKGTYPE')
Andrew Geissler6ce62a22020-11-30 19:58:47 -0600119 import importlib
120 cls = importlib.import_module('oe.package_manager.' + img_type)
121 return cls.PMPkgsList(d, rootfs_dir).list_pkgs()
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500122
123def populate_sdk(d, manifest_dir=None):
124 env_bkp = os.environ.copy()
125
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500126 img_type = d.getVar('IMAGE_PKGTYPE')
Andrew Geissler6ce62a22020-11-30 19:58:47 -0600127 import importlib
128 cls = importlib.import_module('oe.package_manager.' + img_type + '.sdk')
129 cls.PkgSdk(d, manifest_dir).populate()
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500130
131 os.environ.clear()
132 os.environ.update(env_bkp)
133
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500134def get_extra_sdkinfo(sstate_dir):
135 """
136 This function is going to be used for generating the target and host manifest files packages of eSDK.
137 """
138 import math
139
140 extra_info = {}
141 extra_info['tasksizes'] = {}
142 extra_info['filesizes'] = {}
143 for root, _, files in os.walk(sstate_dir):
144 for fn in files:
145 if fn.endswith('.tgz'):
146 fsize = int(math.ceil(float(os.path.getsize(os.path.join(root, fn))) / 1024))
147 task = fn.rsplit(':',1)[1].split('_',1)[1].split(',')[0]
148 origtotal = extra_info['tasksizes'].get(task, 0)
149 extra_info['tasksizes'][task] = origtotal + fsize
150 extra_info['filesizes'][fn] = fsize
151 return extra_info
152
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500153if __name__ == "__main__":
154 pass