Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 1 | # |
| 2 | # SPDX-License-Identifier: GPL-2.0-only |
| 3 | # |
| 4 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 5 | from abc import ABCMeta, abstractmethod |
| 6 | from oe.utils import execute_pre_post_process |
| 7 | from oe.manifest import * |
| 8 | from oe.package_manager import * |
| 9 | import os |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 10 | import traceback |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 11 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 12 | class Sdk(object, metaclass=ABCMeta): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 13 | def __init__(self, d, manifest_dir): |
| 14 | self.d = d |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 15 | 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 Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 19 | |
| 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 Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 24 | self.manifest_dir = self.d.getVar("SDK_DIR") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 25 | else: |
| 26 | self.manifest_dir = manifest_dir |
| 27 | |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 28 | self.remove(self.sdk_output, True) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 29 | |
| 30 | self.install_order = Manifest.INSTALL_ORDER |
| 31 | |
| 32 | @abstractmethod |
| 33 | def _populate(self): |
| 34 | pass |
| 35 | |
| 36 | def populate(self): |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 37 | self.mkdirhier(self.sdk_output) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 38 | |
| 39 | # call backend dependent implementation |
| 40 | self._populate() |
| 41 | |
| 42 | # Don't ship any libGL in the SDK |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 43 | self.remove(os.path.join(self.sdk_output, self.sdk_native_path, |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 44 | self.d.getVar('libdir_nativesdk').strip('/'), |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 45 | "libGL*")) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 46 | |
| 47 | # Fix or remove broken .la files |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 48 | self.remove(os.path.join(self.sdk_output, self.sdk_native_path, |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 49 | self.d.getVar('libdir_nativesdk').strip('/'), |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 50 | "*.la")) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 51 | |
| 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 Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 55 | self.mkdirhier(os.path.dirname(link_name)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 56 | os.symlink("/etc/ld.so.cache", link_name) |
| 57 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 58 | execute_pre_post_process(self.d, self.d.getVar('SDK_POSTPROCESS_COMMAND')) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 59 | |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 60 | 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 Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 87 | |
Brad Bishop | 0011132 | 2018-04-01 22:23:53 -0400 | [diff] [blame] | 88 | def install_locales(self, pm): |
Brad Bishop | 0011132 | 2018-04-01 22:23:53 -0400 | [diff] [blame] | 89 | 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 Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 96 | pm.install(["nativesdk-glibc-binary-localedata-%s.utf-8" % \ |
| 97 | lang for lang in linguas.split()]) |
Brad Bishop | 0011132 | 2018-04-01 22:23:53 -0400 | [diff] [blame] | 98 | # Generate a locale archive of them |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 99 | 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 Bishop | 0011132 | 2018-04-01 22:23:53 -0400 | [diff] [blame] | 103 | # 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 Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 111 | def sdk_list_installed_packages(d, target, rootfs_dir=None): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 112 | if rootfs_dir is None: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 113 | sdk_output = d.getVar('SDK_OUTPUT') |
| 114 | target_path = d.getVar('SDKTARGETSYSROOT').strip('/') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 115 | |
| 116 | rootfs_dir = [sdk_output, os.path.join(sdk_output, target_path)][target is True] |
| 117 | |
Andrew Geissler | 635e0e4 | 2020-08-21 15:58:33 -0500 | [diff] [blame] | 118 | from oe.package_manager.rpm import RpmPkgsList |
| 119 | from oe.package_manager.ipk import OpkgPkgsList |
| 120 | from oe.package_manager.deb import DpkgPkgsList |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 121 | img_type = d.getVar('IMAGE_PKGTYPE') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 122 | if img_type == "rpm": |
| 123 | arch_var = ["SDK_PACKAGE_ARCHS", None][target is True] |
| 124 | os_var = ["SDK_OS", None][target is True] |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 125 | return RpmPkgsList(d, rootfs_dir).list_pkgs() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 126 | elif img_type == "ipk": |
| 127 | conf_file_var = ["IPKGCONF_SDK", "IPKGCONF_TARGET"][target is True] |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 128 | return OpkgPkgsList(d, rootfs_dir, d.getVar(conf_file_var)).list_pkgs() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 129 | elif img_type == "deb": |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 130 | return DpkgPkgsList(d, rootfs_dir).list_pkgs() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 131 | |
| 132 | def populate_sdk(d, manifest_dir=None): |
| 133 | env_bkp = os.environ.copy() |
| 134 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 135 | img_type = d.getVar('IMAGE_PKGTYPE') |
Andrew Geissler | 635e0e4 | 2020-08-21 15:58:33 -0500 | [diff] [blame] | 136 | from oe.package_manager.rpm.sdk import RpmSdk |
| 137 | from oe.package_manager.ipk.sdk import OpkgSdk |
| 138 | from oe.package_manager.deb.sdk import DpkgSdk |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 139 | if img_type == "rpm": |
| 140 | RpmSdk(d, manifest_dir).populate() |
| 141 | elif img_type == "ipk": |
| 142 | OpkgSdk(d, manifest_dir).populate() |
| 143 | elif img_type == "deb": |
| 144 | DpkgSdk(d, manifest_dir).populate() |
| 145 | |
| 146 | os.environ.clear() |
| 147 | os.environ.update(env_bkp) |
| 148 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 149 | def get_extra_sdkinfo(sstate_dir): |
| 150 | """ |
| 151 | This function is going to be used for generating the target and host manifest files packages of eSDK. |
| 152 | """ |
| 153 | import math |
| 154 | |
| 155 | extra_info = {} |
| 156 | extra_info['tasksizes'] = {} |
| 157 | extra_info['filesizes'] = {} |
| 158 | for root, _, files in os.walk(sstate_dir): |
| 159 | for fn in files: |
| 160 | if fn.endswith('.tgz'): |
| 161 | fsize = int(math.ceil(float(os.path.getsize(os.path.join(root, fn))) / 1024)) |
| 162 | task = fn.rsplit(':',1)[1].split('_',1)[1].split(',')[0] |
| 163 | origtotal = extra_info['tasksizes'].get(task, 0) |
| 164 | extra_info['tasksizes'][task] = origtotal + fsize |
| 165 | extra_info['filesizes'][fn] = fsize |
| 166 | return extra_info |
| 167 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 168 | if __name__ == "__main__": |
| 169 | pass |