Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 1 | # |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 2 | # Copyright OpenEmbedded Contributors |
| 3 | # |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 4 | # SPDX-License-Identifier: GPL-2.0-only |
| 5 | # |
| 6 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 7 | from abc import ABCMeta, abstractmethod |
| 8 | from oe.utils import execute_pre_post_process |
| 9 | from oe.manifest import * |
| 10 | from oe.package_manager import * |
| 11 | import os |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 12 | import traceback |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 13 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 14 | class Sdk(object, metaclass=ABCMeta): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 15 | def __init__(self, d, manifest_dir): |
| 16 | self.d = d |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 17 | self.sdk_output = self.d.getVar('SDK_OUTPUT') |
| 18 | self.sdk_native_path = self.d.getVar('SDKPATHNATIVE').strip('/') |
| 19 | self.target_path = self.d.getVar('SDKTARGETSYSROOT').strip('/') |
| 20 | self.sysconfdir = self.d.getVar('sysconfdir').strip('/') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 21 | |
| 22 | self.sdk_target_sysroot = os.path.join(self.sdk_output, self.target_path) |
| 23 | self.sdk_host_sysroot = self.sdk_output |
| 24 | |
| 25 | if manifest_dir is None: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 26 | self.manifest_dir = self.d.getVar("SDK_DIR") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 27 | else: |
| 28 | self.manifest_dir = manifest_dir |
| 29 | |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 30 | self.remove(self.sdk_output, True) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 31 | |
| 32 | self.install_order = Manifest.INSTALL_ORDER |
| 33 | |
| 34 | @abstractmethod |
| 35 | def _populate(self): |
| 36 | pass |
| 37 | |
| 38 | def populate(self): |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 39 | self.mkdirhier(self.sdk_output) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 40 | |
| 41 | # call backend dependent implementation |
| 42 | self._populate() |
| 43 | |
| 44 | # Don't ship any libGL in the SDK |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 45 | self.remove(os.path.join(self.sdk_output, self.sdk_native_path, |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 46 | self.d.getVar('libdir_nativesdk').strip('/'), |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 47 | "libGL*")) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 48 | |
| 49 | # Fix or remove broken .la files |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 50 | self.remove(os.path.join(self.sdk_output, self.sdk_native_path, |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 51 | self.d.getVar('libdir_nativesdk').strip('/'), |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 52 | "*.la")) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 53 | |
| 54 | # Link the ld.so.cache file into the hosts filesystem |
| 55 | link_name = os.path.join(self.sdk_output, self.sdk_native_path, |
| 56 | self.sysconfdir, "ld.so.cache") |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 57 | self.mkdirhier(os.path.dirname(link_name)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 58 | os.symlink("/etc/ld.so.cache", link_name) |
| 59 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 60 | execute_pre_post_process(self.d, self.d.getVar('SDK_POSTPROCESS_COMMAND')) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 61 | |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 62 | def movefile(self, sourcefile, destdir): |
| 63 | try: |
| 64 | # FIXME: this check of movefile's return code to None should be |
| 65 | # fixed within the function to use only exceptions to signal when |
| 66 | # something goes wrong |
| 67 | if (bb.utils.movefile(sourcefile, destdir) == None): |
| 68 | raise OSError("moving %s to %s failed" |
| 69 | %(sourcefile, destdir)) |
| 70 | #FIXME: using umbrella exc catching because bb.utils method raises it |
| 71 | except Exception as e: |
| 72 | bb.debug(1, "printing the stack trace\n %s" %traceback.format_exc()) |
Patrick Williams | 520786c | 2023-06-25 16:20:36 -0500 | [diff] [blame] | 73 | bb.fatal("unable to place %s in final SDK location" % sourcefile) |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 74 | |
| 75 | def mkdirhier(self, dirpath): |
| 76 | try: |
| 77 | bb.utils.mkdirhier(dirpath) |
| 78 | except OSError as e: |
| 79 | bb.debug(1, "printing the stack trace\n %s" %traceback.format_exc()) |
| 80 | bb.fatal("cannot make dir for SDK: %s" % dirpath) |
| 81 | |
| 82 | def remove(self, path, recurse=False): |
| 83 | try: |
| 84 | bb.utils.remove(path, recurse) |
| 85 | #FIXME: using umbrella exc catching because bb.utils method raises it |
| 86 | except Exception as e: |
| 87 | bb.debug(1, "printing the stack trace\n %s" %traceback.format_exc()) |
| 88 | bb.warn("cannot remove SDK dir: %s" % path) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 89 | |
Brad Bishop | 0011132 | 2018-04-01 22:23:53 -0400 | [diff] [blame] | 90 | def install_locales(self, pm): |
Brad Bishop | 0011132 | 2018-04-01 22:23:53 -0400 | [diff] [blame] | 91 | linguas = self.d.getVar("SDKIMAGE_LINGUAS") |
| 92 | if linguas: |
| 93 | import fnmatch |
| 94 | # Install the binary locales |
| 95 | if linguas == "all": |
| 96 | pm.install_glob("nativesdk-glibc-binary-localedata-*.utf-8", sdk=True) |
| 97 | else: |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 98 | pm.install(["nativesdk-glibc-binary-localedata-%s.utf-8" % \ |
| 99 | lang for lang in linguas.split()]) |
Brad Bishop | 0011132 | 2018-04-01 22:23:53 -0400 | [diff] [blame] | 100 | # Generate a locale archive of them |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 101 | target_arch = self.d.getVar('SDK_ARCH') |
| 102 | rootfs = oe.path.join(self.sdk_host_sysroot, self.sdk_native_path) |
| 103 | localedir = oe.path.join(rootfs, self.d.getVar("libdir_nativesdk"), "locale") |
| 104 | generate_locale_archive(self.d, rootfs, target_arch, localedir) |
Brad Bishop | 0011132 | 2018-04-01 22:23:53 -0400 | [diff] [blame] | 105 | # And now delete the binary locales |
| 106 | pkgs = fnmatch.filter(pm.list_installed(), "nativesdk-glibc-binary-localedata-*.utf-8") |
| 107 | pm.remove(pkgs) |
| 108 | else: |
| 109 | # No linguas so do nothing |
| 110 | pass |
| 111 | |
| 112 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 113 | def sdk_list_installed_packages(d, target, rootfs_dir=None): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 114 | if rootfs_dir is None: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 115 | sdk_output = d.getVar('SDK_OUTPUT') |
| 116 | target_path = d.getVar('SDKTARGETSYSROOT').strip('/') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 117 | |
| 118 | rootfs_dir = [sdk_output, os.path.join(sdk_output, target_path)][target is True] |
| 119 | |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 120 | if target is False: |
| 121 | ipkgconf_sdk_target = d.getVar("IPKGCONF_SDK") |
| 122 | d.setVar("IPKGCONF_TARGET", ipkgconf_sdk_target) |
| 123 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 124 | img_type = d.getVar('IMAGE_PKGTYPE') |
Andrew Geissler | 6ce62a2 | 2020-11-30 19:58:47 -0600 | [diff] [blame] | 125 | import importlib |
| 126 | cls = importlib.import_module('oe.package_manager.' + img_type) |
| 127 | return cls.PMPkgsList(d, rootfs_dir).list_pkgs() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 128 | |
| 129 | def populate_sdk(d, manifest_dir=None): |
| 130 | env_bkp = os.environ.copy() |
| 131 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 132 | img_type = d.getVar('IMAGE_PKGTYPE') |
Andrew Geissler | 6ce62a2 | 2020-11-30 19:58:47 -0600 | [diff] [blame] | 133 | import importlib |
| 134 | cls = importlib.import_module('oe.package_manager.' + img_type + '.sdk') |
| 135 | cls.PkgSdk(d, manifest_dir).populate() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 136 | |
| 137 | os.environ.clear() |
| 138 | os.environ.update(env_bkp) |
| 139 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 140 | def get_extra_sdkinfo(sstate_dir): |
| 141 | """ |
| 142 | This function is going to be used for generating the target and host manifest files packages of eSDK. |
| 143 | """ |
| 144 | import math |
| 145 | |
| 146 | extra_info = {} |
| 147 | extra_info['tasksizes'] = {} |
| 148 | extra_info['filesizes'] = {} |
| 149 | for root, _, files in os.walk(sstate_dir): |
| 150 | for fn in files: |
| 151 | if fn.endswith('.tgz'): |
| 152 | fsize = int(math.ceil(float(os.path.getsize(os.path.join(root, fn))) / 1024)) |
| 153 | task = fn.rsplit(':',1)[1].split('_',1)[1].split(',')[0] |
| 154 | origtotal = extra_info['tasksizes'].get(task, 0) |
| 155 | extra_info['tasksizes'][task] = origtotal + fsize |
| 156 | extra_info['filesizes'][fn] = fsize |
| 157 | return extra_info |
| 158 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 159 | if __name__ == "__main__": |
| 160 | pass |