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 |
| 10 | import shutil |
| 11 | import glob |
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()) |
| 73 | bb.error("unable to place %s in final SDK location" % sourcefile) |
| 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): |
| 91 | # This is only relevant for glibc |
| 92 | if self.d.getVar("TCLIBC") != "glibc": |
| 93 | return |
| 94 | |
| 95 | linguas = self.d.getVar("SDKIMAGE_LINGUAS") |
| 96 | if linguas: |
| 97 | import fnmatch |
| 98 | # Install the binary locales |
| 99 | if linguas == "all": |
| 100 | pm.install_glob("nativesdk-glibc-binary-localedata-*.utf-8", sdk=True) |
| 101 | else: |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 102 | pm.install(["nativesdk-glibc-binary-localedata-%s.utf-8" % \ |
| 103 | lang for lang in linguas.split()]) |
Brad Bishop | 0011132 | 2018-04-01 22:23:53 -0400 | [diff] [blame] | 104 | # Generate a locale archive of them |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 105 | target_arch = self.d.getVar('SDK_ARCH') |
| 106 | rootfs = oe.path.join(self.sdk_host_sysroot, self.sdk_native_path) |
| 107 | localedir = oe.path.join(rootfs, self.d.getVar("libdir_nativesdk"), "locale") |
| 108 | generate_locale_archive(self.d, rootfs, target_arch, localedir) |
Brad Bishop | 0011132 | 2018-04-01 22:23:53 -0400 | [diff] [blame] | 109 | # And now delete the binary locales |
| 110 | pkgs = fnmatch.filter(pm.list_installed(), "nativesdk-glibc-binary-localedata-*.utf-8") |
| 111 | pm.remove(pkgs) |
| 112 | else: |
| 113 | # No linguas so do nothing |
| 114 | pass |
| 115 | |
| 116 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 117 | class RpmSdk(Sdk): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 118 | def __init__(self, d, manifest_dir=None, rpm_workdir="oe-sdk-repo"): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 119 | super(RpmSdk, self).__init__(d, manifest_dir) |
| 120 | |
| 121 | self.target_manifest = RpmManifest(d, self.manifest_dir, |
| 122 | Manifest.MANIFEST_TYPE_SDK_TARGET) |
| 123 | self.host_manifest = RpmManifest(d, self.manifest_dir, |
| 124 | Manifest.MANIFEST_TYPE_SDK_HOST) |
| 125 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 126 | rpm_repo_workdir = "oe-sdk-repo" |
| 127 | if "sdk_ext" in d.getVar("BB_RUNTASK"): |
| 128 | rpm_repo_workdir = "oe-sdk-ext-repo" |
| 129 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 130 | self.target_pm = RpmPM(d, |
| 131 | self.sdk_target_sysroot, |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 132 | self.d.getVar('TARGET_VENDOR'), |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 133 | 'target', |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 134 | rpm_repo_workdir=rpm_repo_workdir |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 135 | ) |
| 136 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 137 | self.host_pm = RpmPM(d, |
| 138 | self.sdk_host_sysroot, |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 139 | self.d.getVar('SDK_VENDOR'), |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 140 | 'host', |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 141 | "SDK_PACKAGE_ARCHS", |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 142 | "SDK_OS", |
| 143 | rpm_repo_workdir=rpm_repo_workdir |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 144 | ) |
| 145 | |
| 146 | def _populate_sysroot(self, pm, manifest): |
| 147 | pkgs_to_install = manifest.parse_initial_manifest() |
| 148 | |
| 149 | pm.create_configs() |
| 150 | pm.write_index() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 151 | pm.update() |
| 152 | |
| 153 | pkgs = [] |
| 154 | pkgs_attempt = [] |
| 155 | for pkg_type in pkgs_to_install: |
| 156 | if pkg_type == Manifest.PKG_TYPE_ATTEMPT_ONLY: |
| 157 | pkgs_attempt += pkgs_to_install[pkg_type] |
| 158 | else: |
| 159 | pkgs += pkgs_to_install[pkg_type] |
| 160 | |
| 161 | pm.install(pkgs) |
| 162 | |
| 163 | pm.install(pkgs_attempt, True) |
| 164 | |
| 165 | def _populate(self): |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 166 | execute_pre_post_process(self.d, self.d.getVar("POPULATE_SDK_PRE_TARGET_COMMAND")) |
| 167 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 168 | bb.note("Installing TARGET packages") |
| 169 | self._populate_sysroot(self.target_pm, self.target_manifest) |
| 170 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 171 | self.target_pm.install_complementary(self.d.getVar('SDKIMAGE_INSTALL_COMPLEMENTARY')) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 172 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 173 | self.target_pm.run_intercepts(populate_sdk='target') |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 174 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 175 | execute_pre_post_process(self.d, self.d.getVar("POPULATE_SDK_POST_TARGET_COMMAND")) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 176 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 177 | if not bb.utils.contains("SDKIMAGE_FEATURES", "package-management", True, False, self.d): |
| 178 | self.target_pm.remove_packaging_data() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 179 | |
| 180 | bb.note("Installing NATIVESDK packages") |
| 181 | self._populate_sysroot(self.host_pm, self.host_manifest) |
Brad Bishop | 0011132 | 2018-04-01 22:23:53 -0400 | [diff] [blame] | 182 | self.install_locales(self.host_pm) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 183 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 184 | self.host_pm.run_intercepts(populate_sdk='host') |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 185 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 186 | execute_pre_post_process(self.d, self.d.getVar("POPULATE_SDK_POST_HOST_COMMAND")) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 187 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 188 | if not bb.utils.contains("SDKIMAGE_FEATURES", "package-management", True, False, self.d): |
| 189 | self.host_pm.remove_packaging_data() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 190 | |
| 191 | # Move host RPM library data |
| 192 | native_rpm_state_dir = os.path.join(self.sdk_output, |
| 193 | self.sdk_native_path, |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 194 | self.d.getVar('localstatedir_nativesdk').strip('/'), |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 195 | "lib", |
| 196 | "rpm" |
| 197 | ) |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 198 | self.mkdirhier(native_rpm_state_dir) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 199 | for f in glob.glob(os.path.join(self.sdk_output, |
| 200 | "var", |
| 201 | "lib", |
| 202 | "rpm", |
| 203 | "*")): |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 204 | self.movefile(f, native_rpm_state_dir) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 205 | |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 206 | self.remove(os.path.join(self.sdk_output, "var"), True) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 207 | |
| 208 | # Move host sysconfig data |
| 209 | native_sysconf_dir = os.path.join(self.sdk_output, |
| 210 | self.sdk_native_path, |
| 211 | self.d.getVar('sysconfdir', |
| 212 | True).strip('/'), |
| 213 | ) |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 214 | self.mkdirhier(native_sysconf_dir) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 215 | for f in glob.glob(os.path.join(self.sdk_output, "etc", "rpm*")): |
| 216 | self.movefile(f, native_sysconf_dir) |
| 217 | for f in glob.glob(os.path.join(self.sdk_output, "etc", "dnf", "*")): |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 218 | self.movefile(f, native_sysconf_dir) |
| 219 | self.remove(os.path.join(self.sdk_output, "etc"), True) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 220 | |
| 221 | |
| 222 | class OpkgSdk(Sdk): |
| 223 | def __init__(self, d, manifest_dir=None): |
| 224 | super(OpkgSdk, self).__init__(d, manifest_dir) |
| 225 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 226 | self.target_conf = self.d.getVar("IPKGCONF_TARGET") |
| 227 | self.host_conf = self.d.getVar("IPKGCONF_SDK") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 228 | |
| 229 | self.target_manifest = OpkgManifest(d, self.manifest_dir, |
| 230 | Manifest.MANIFEST_TYPE_SDK_TARGET) |
| 231 | self.host_manifest = OpkgManifest(d, self.manifest_dir, |
| 232 | Manifest.MANIFEST_TYPE_SDK_HOST) |
| 233 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 234 | ipk_repo_workdir = "oe-sdk-repo" |
| 235 | if "sdk_ext" in d.getVar("BB_RUNTASK"): |
| 236 | ipk_repo_workdir = "oe-sdk-ext-repo" |
| 237 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 238 | self.target_pm = OpkgPM(d, self.sdk_target_sysroot, self.target_conf, |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 239 | self.d.getVar("ALL_MULTILIB_PACKAGE_ARCHS"), |
| 240 | ipk_repo_workdir=ipk_repo_workdir) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 241 | |
| 242 | self.host_pm = OpkgPM(d, self.sdk_host_sysroot, self.host_conf, |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 243 | self.d.getVar("SDK_PACKAGE_ARCHS"), |
| 244 | ipk_repo_workdir=ipk_repo_workdir) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 245 | |
| 246 | def _populate_sysroot(self, pm, manifest): |
| 247 | pkgs_to_install = manifest.parse_initial_manifest() |
| 248 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 249 | if (self.d.getVar('BUILD_IMAGES_FROM_FEEDS') or "") != "1": |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 250 | pm.write_index() |
| 251 | |
| 252 | pm.update() |
| 253 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 254 | for pkg_type in self.install_order: |
| 255 | if pkg_type in pkgs_to_install: |
| 256 | pm.install(pkgs_to_install[pkg_type], |
| 257 | [False, True][pkg_type == Manifest.PKG_TYPE_ATTEMPT_ONLY]) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 258 | |
| 259 | def _populate(self): |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 260 | execute_pre_post_process(self.d, self.d.getVar("POPULATE_SDK_PRE_TARGET_COMMAND")) |
| 261 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 262 | bb.note("Installing TARGET packages") |
| 263 | self._populate_sysroot(self.target_pm, self.target_manifest) |
| 264 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 265 | self.target_pm.install_complementary(self.d.getVar('SDKIMAGE_INSTALL_COMPLEMENTARY')) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 266 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 267 | self.target_pm.run_intercepts(populate_sdk='target') |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 268 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 269 | execute_pre_post_process(self.d, self.d.getVar("POPULATE_SDK_POST_TARGET_COMMAND")) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 270 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 271 | if not bb.utils.contains("SDKIMAGE_FEATURES", "package-management", True, False, self.d): |
| 272 | self.target_pm.remove_packaging_data() |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 273 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 274 | bb.note("Installing NATIVESDK packages") |
| 275 | self._populate_sysroot(self.host_pm, self.host_manifest) |
Brad Bishop | 0011132 | 2018-04-01 22:23:53 -0400 | [diff] [blame] | 276 | self.install_locales(self.host_pm) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 277 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 278 | self.host_pm.run_intercepts(populate_sdk='host') |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 279 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 280 | execute_pre_post_process(self.d, self.d.getVar("POPULATE_SDK_POST_HOST_COMMAND")) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 281 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 282 | if not bb.utils.contains("SDKIMAGE_FEATURES", "package-management", True, False, self.d): |
| 283 | self.host_pm.remove_packaging_data() |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 284 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 285 | target_sysconfdir = os.path.join(self.sdk_target_sysroot, self.sysconfdir) |
| 286 | host_sysconfdir = os.path.join(self.sdk_host_sysroot, self.sysconfdir) |
| 287 | |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 288 | self.mkdirhier(target_sysconfdir) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 289 | shutil.copy(self.target_conf, target_sysconfdir) |
| 290 | os.chmod(os.path.join(target_sysconfdir, |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 291 | os.path.basename(self.target_conf)), 0o644) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 292 | |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 293 | self.mkdirhier(host_sysconfdir) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 294 | shutil.copy(self.host_conf, host_sysconfdir) |
| 295 | os.chmod(os.path.join(host_sysconfdir, |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 296 | os.path.basename(self.host_conf)), 0o644) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 297 | |
| 298 | native_opkg_state_dir = os.path.join(self.sdk_output, self.sdk_native_path, |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 299 | self.d.getVar('localstatedir_nativesdk').strip('/'), |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 300 | "lib", "opkg") |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 301 | self.mkdirhier(native_opkg_state_dir) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 302 | for f in glob.glob(os.path.join(self.sdk_output, "var", "lib", "opkg", "*")): |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 303 | self.movefile(f, native_opkg_state_dir) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 304 | |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 305 | self.remove(os.path.join(self.sdk_output, "var"), True) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 306 | |
| 307 | |
| 308 | class DpkgSdk(Sdk): |
| 309 | def __init__(self, d, manifest_dir=None): |
| 310 | super(DpkgSdk, self).__init__(d, manifest_dir) |
| 311 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 312 | self.target_conf_dir = os.path.join(self.d.getVar("APTCONF_TARGET"), "apt") |
| 313 | self.host_conf_dir = os.path.join(self.d.getVar("APTCONF_TARGET"), "apt-sdk") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 314 | |
| 315 | self.target_manifest = DpkgManifest(d, self.manifest_dir, |
| 316 | Manifest.MANIFEST_TYPE_SDK_TARGET) |
| 317 | self.host_manifest = DpkgManifest(d, self.manifest_dir, |
| 318 | Manifest.MANIFEST_TYPE_SDK_HOST) |
| 319 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 320 | deb_repo_workdir = "oe-sdk-repo" |
| 321 | if "sdk_ext" in d.getVar("BB_RUNTASK"): |
| 322 | deb_repo_workdir = "oe-sdk-ext-repo" |
| 323 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 324 | self.target_pm = DpkgPM(d, self.sdk_target_sysroot, |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 325 | self.d.getVar("PACKAGE_ARCHS"), |
| 326 | self.d.getVar("DPKG_ARCH"), |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 327 | self.target_conf_dir, |
| 328 | deb_repo_workdir=deb_repo_workdir) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 329 | |
| 330 | self.host_pm = DpkgPM(d, self.sdk_host_sysroot, |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 331 | self.d.getVar("SDK_PACKAGE_ARCHS"), |
| 332 | self.d.getVar("DEB_SDK_ARCH"), |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 333 | self.host_conf_dir, |
| 334 | deb_repo_workdir=deb_repo_workdir) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 335 | |
| 336 | def _copy_apt_dir_to(self, dst_dir): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 337 | staging_etcdir_native = self.d.getVar("STAGING_ETCDIR_NATIVE") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 338 | |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 339 | self.remove(dst_dir, True) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 340 | |
| 341 | shutil.copytree(os.path.join(staging_etcdir_native, "apt"), dst_dir) |
| 342 | |
| 343 | def _populate_sysroot(self, pm, manifest): |
| 344 | pkgs_to_install = manifest.parse_initial_manifest() |
| 345 | |
| 346 | pm.write_index() |
| 347 | pm.update() |
| 348 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 349 | for pkg_type in self.install_order: |
| 350 | if pkg_type in pkgs_to_install: |
| 351 | pm.install(pkgs_to_install[pkg_type], |
| 352 | [False, True][pkg_type == Manifest.PKG_TYPE_ATTEMPT_ONLY]) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 353 | |
| 354 | def _populate(self): |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 355 | execute_pre_post_process(self.d, self.d.getVar("POPULATE_SDK_PRE_TARGET_COMMAND")) |
| 356 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 357 | bb.note("Installing TARGET packages") |
| 358 | self._populate_sysroot(self.target_pm, self.target_manifest) |
| 359 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 360 | self.target_pm.install_complementary(self.d.getVar('SDKIMAGE_INSTALL_COMPLEMENTARY')) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 361 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 362 | self.target_pm.run_intercepts(populate_sdk='target') |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 363 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 364 | execute_pre_post_process(self.d, self.d.getVar("POPULATE_SDK_POST_TARGET_COMMAND")) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 365 | |
| 366 | self._copy_apt_dir_to(os.path.join(self.sdk_target_sysroot, "etc", "apt")) |
| 367 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 368 | if not bb.utils.contains("SDKIMAGE_FEATURES", "package-management", True, False, self.d): |
| 369 | self.target_pm.remove_packaging_data() |
| 370 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 371 | bb.note("Installing NATIVESDK packages") |
| 372 | self._populate_sysroot(self.host_pm, self.host_manifest) |
Brad Bishop | 0011132 | 2018-04-01 22:23:53 -0400 | [diff] [blame] | 373 | self.install_locales(self.host_pm) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 374 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 375 | self.host_pm.run_intercepts(populate_sdk='host') |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 376 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 377 | execute_pre_post_process(self.d, self.d.getVar("POPULATE_SDK_POST_HOST_COMMAND")) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 378 | |
| 379 | self._copy_apt_dir_to(os.path.join(self.sdk_output, self.sdk_native_path, |
| 380 | "etc", "apt")) |
| 381 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 382 | if not bb.utils.contains("SDKIMAGE_FEATURES", "package-management", True, False, self.d): |
| 383 | self.host_pm.remove_packaging_data() |
| 384 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 385 | native_dpkg_state_dir = os.path.join(self.sdk_output, self.sdk_native_path, |
| 386 | "var", "lib", "dpkg") |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 387 | self.mkdirhier(native_dpkg_state_dir) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 388 | for f in glob.glob(os.path.join(self.sdk_output, "var", "lib", "dpkg", "*")): |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 389 | self.movefile(f, native_dpkg_state_dir) |
| 390 | self.remove(os.path.join(self.sdk_output, "var"), True) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 391 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 392 | |
| 393 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 394 | def sdk_list_installed_packages(d, target, rootfs_dir=None): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 395 | if rootfs_dir is None: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 396 | sdk_output = d.getVar('SDK_OUTPUT') |
| 397 | target_path = d.getVar('SDKTARGETSYSROOT').strip('/') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 398 | |
| 399 | rootfs_dir = [sdk_output, os.path.join(sdk_output, target_path)][target is True] |
| 400 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 401 | img_type = d.getVar('IMAGE_PKGTYPE') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 402 | if img_type == "rpm": |
| 403 | arch_var = ["SDK_PACKAGE_ARCHS", None][target is True] |
| 404 | os_var = ["SDK_OS", None][target is True] |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 405 | return RpmPkgsList(d, rootfs_dir).list_pkgs() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 406 | elif img_type == "ipk": |
| 407 | conf_file_var = ["IPKGCONF_SDK", "IPKGCONF_TARGET"][target is True] |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 408 | return OpkgPkgsList(d, rootfs_dir, d.getVar(conf_file_var)).list_pkgs() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 409 | elif img_type == "deb": |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 410 | return DpkgPkgsList(d, rootfs_dir).list_pkgs() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 411 | |
| 412 | def populate_sdk(d, manifest_dir=None): |
| 413 | env_bkp = os.environ.copy() |
| 414 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 415 | img_type = d.getVar('IMAGE_PKGTYPE') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 416 | if img_type == "rpm": |
| 417 | RpmSdk(d, manifest_dir).populate() |
| 418 | elif img_type == "ipk": |
| 419 | OpkgSdk(d, manifest_dir).populate() |
| 420 | elif img_type == "deb": |
| 421 | DpkgSdk(d, manifest_dir).populate() |
| 422 | |
| 423 | os.environ.clear() |
| 424 | os.environ.update(env_bkp) |
| 425 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 426 | def get_extra_sdkinfo(sstate_dir): |
| 427 | """ |
| 428 | This function is going to be used for generating the target and host manifest files packages of eSDK. |
| 429 | """ |
| 430 | import math |
| 431 | |
| 432 | extra_info = {} |
| 433 | extra_info['tasksizes'] = {} |
| 434 | extra_info['filesizes'] = {} |
| 435 | for root, _, files in os.walk(sstate_dir): |
| 436 | for fn in files: |
| 437 | if fn.endswith('.tgz'): |
| 438 | fsize = int(math.ceil(float(os.path.getsize(os.path.join(root, fn))) / 1024)) |
| 439 | task = fn.rsplit(':',1)[1].split('_',1)[1].split(',')[0] |
| 440 | origtotal = extra_info['tasksizes'].get(task, 0) |
| 441 | extra_info['tasksizes'][task] = origtotal + fsize |
| 442 | extra_info['filesizes'][fn] = fsize |
| 443 | return extra_info |
| 444 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 445 | if __name__ == "__main__": |
| 446 | pass |