Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | from abc import ABCMeta, abstractmethod |
| 2 | from oe.utils import execute_pre_post_process |
| 3 | from oe.manifest import * |
| 4 | from oe.package_manager import * |
| 5 | import os |
| 6 | import shutil |
| 7 | import glob |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 8 | import traceback |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 9 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 10 | class Sdk(object, metaclass=ABCMeta): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 11 | def __init__(self, d, manifest_dir): |
| 12 | self.d = d |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 13 | self.sdk_output = self.d.getVar('SDK_OUTPUT') |
| 14 | self.sdk_native_path = self.d.getVar('SDKPATHNATIVE').strip('/') |
| 15 | self.target_path = self.d.getVar('SDKTARGETSYSROOT').strip('/') |
| 16 | self.sysconfdir = self.d.getVar('sysconfdir').strip('/') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 17 | |
| 18 | self.sdk_target_sysroot = os.path.join(self.sdk_output, self.target_path) |
| 19 | self.sdk_host_sysroot = self.sdk_output |
| 20 | |
| 21 | if manifest_dir is None: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 22 | self.manifest_dir = self.d.getVar("SDK_DIR") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 23 | else: |
| 24 | self.manifest_dir = manifest_dir |
| 25 | |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 26 | self.remove(self.sdk_output, True) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 27 | |
| 28 | self.install_order = Manifest.INSTALL_ORDER |
| 29 | |
| 30 | @abstractmethod |
| 31 | def _populate(self): |
| 32 | pass |
| 33 | |
| 34 | def populate(self): |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 35 | self.mkdirhier(self.sdk_output) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 36 | |
| 37 | # call backend dependent implementation |
| 38 | self._populate() |
| 39 | |
| 40 | # Don't ship any libGL in the SDK |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 41 | self.remove(os.path.join(self.sdk_output, self.sdk_native_path, |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 42 | self.d.getVar('libdir_nativesdk').strip('/'), |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 43 | "libGL*")) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 44 | |
| 45 | # Fix or remove broken .la files |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 46 | self.remove(os.path.join(self.sdk_output, self.sdk_native_path, |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 47 | self.d.getVar('libdir_nativesdk').strip('/'), |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 48 | "*.la")) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 49 | |
| 50 | # Link the ld.so.cache file into the hosts filesystem |
| 51 | link_name = os.path.join(self.sdk_output, self.sdk_native_path, |
| 52 | self.sysconfdir, "ld.so.cache") |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 53 | self.mkdirhier(os.path.dirname(link_name)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 54 | os.symlink("/etc/ld.so.cache", link_name) |
| 55 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 56 | execute_pre_post_process(self.d, self.d.getVar('SDK_POSTPROCESS_COMMAND')) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 57 | |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 58 | def movefile(self, sourcefile, destdir): |
| 59 | try: |
| 60 | # FIXME: this check of movefile's return code to None should be |
| 61 | # fixed within the function to use only exceptions to signal when |
| 62 | # something goes wrong |
| 63 | if (bb.utils.movefile(sourcefile, destdir) == None): |
| 64 | raise OSError("moving %s to %s failed" |
| 65 | %(sourcefile, destdir)) |
| 66 | #FIXME: using umbrella exc catching because bb.utils method raises it |
| 67 | except Exception as e: |
| 68 | bb.debug(1, "printing the stack trace\n %s" %traceback.format_exc()) |
| 69 | bb.error("unable to place %s in final SDK location" % sourcefile) |
| 70 | |
| 71 | def mkdirhier(self, dirpath): |
| 72 | try: |
| 73 | bb.utils.mkdirhier(dirpath) |
| 74 | except OSError as e: |
| 75 | bb.debug(1, "printing the stack trace\n %s" %traceback.format_exc()) |
| 76 | bb.fatal("cannot make dir for SDK: %s" % dirpath) |
| 77 | |
| 78 | def remove(self, path, recurse=False): |
| 79 | try: |
| 80 | bb.utils.remove(path, recurse) |
| 81 | #FIXME: using umbrella exc catching because bb.utils method raises it |
| 82 | except Exception as e: |
| 83 | bb.debug(1, "printing the stack trace\n %s" %traceback.format_exc()) |
| 84 | bb.warn("cannot remove SDK dir: %s" % path) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 85 | |
Brad Bishop | 0011132 | 2018-04-01 22:23:53 -0400 | [diff] [blame] | 86 | def install_locales(self, pm): |
| 87 | # This is only relevant for glibc |
| 88 | if self.d.getVar("TCLIBC") != "glibc": |
| 89 | return |
| 90 | |
| 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: |
| 98 | for lang in linguas.split(): |
| 99 | pm.install("nativesdk-glibc-binary-localedata-%s.utf-8" % lang) |
| 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 | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 113 | class RpmSdk(Sdk): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 114 | def __init__(self, d, manifest_dir=None, rpm_workdir="oe-sdk-repo"): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 115 | super(RpmSdk, self).__init__(d, manifest_dir) |
| 116 | |
| 117 | self.target_manifest = RpmManifest(d, self.manifest_dir, |
| 118 | Manifest.MANIFEST_TYPE_SDK_TARGET) |
| 119 | self.host_manifest = RpmManifest(d, self.manifest_dir, |
| 120 | Manifest.MANIFEST_TYPE_SDK_HOST) |
| 121 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 122 | rpm_repo_workdir = "oe-sdk-repo" |
| 123 | if "sdk_ext" in d.getVar("BB_RUNTASK"): |
| 124 | rpm_repo_workdir = "oe-sdk-ext-repo" |
| 125 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 126 | self.target_pm = RpmPM(d, |
| 127 | self.sdk_target_sysroot, |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 128 | self.d.getVar('TARGET_VENDOR'), |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 129 | 'target', |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 130 | rpm_repo_workdir=rpm_repo_workdir |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 131 | ) |
| 132 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 133 | self.host_pm = RpmPM(d, |
| 134 | self.sdk_host_sysroot, |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 135 | self.d.getVar('SDK_VENDOR'), |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 136 | 'host', |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 137 | "SDK_PACKAGE_ARCHS", |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 138 | "SDK_OS", |
| 139 | rpm_repo_workdir=rpm_repo_workdir |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 140 | ) |
| 141 | |
| 142 | def _populate_sysroot(self, pm, manifest): |
| 143 | pkgs_to_install = manifest.parse_initial_manifest() |
| 144 | |
| 145 | pm.create_configs() |
| 146 | pm.write_index() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 147 | pm.update() |
| 148 | |
| 149 | pkgs = [] |
| 150 | pkgs_attempt = [] |
| 151 | for pkg_type in pkgs_to_install: |
| 152 | if pkg_type == Manifest.PKG_TYPE_ATTEMPT_ONLY: |
| 153 | pkgs_attempt += pkgs_to_install[pkg_type] |
| 154 | else: |
| 155 | pkgs += pkgs_to_install[pkg_type] |
| 156 | |
| 157 | pm.install(pkgs) |
| 158 | |
| 159 | pm.install(pkgs_attempt, True) |
| 160 | |
| 161 | def _populate(self): |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 162 | execute_pre_post_process(self.d, self.d.getVar("POPULATE_SDK_PRE_TARGET_COMMAND")) |
| 163 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 164 | bb.note("Installing TARGET packages") |
| 165 | self._populate_sysroot(self.target_pm, self.target_manifest) |
| 166 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 167 | self.target_pm.install_complementary(self.d.getVar('SDKIMAGE_INSTALL_COMPLEMENTARY')) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 168 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 169 | self.target_pm.run_intercepts(populate_sdk='target') |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 170 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 171 | 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] | 172 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 173 | if not bb.utils.contains("SDKIMAGE_FEATURES", "package-management", True, False, self.d): |
| 174 | self.target_pm.remove_packaging_data() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 175 | |
| 176 | bb.note("Installing NATIVESDK packages") |
| 177 | self._populate_sysroot(self.host_pm, self.host_manifest) |
Brad Bishop | 0011132 | 2018-04-01 22:23:53 -0400 | [diff] [blame] | 178 | self.install_locales(self.host_pm) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 179 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 180 | self.host_pm.run_intercepts(populate_sdk='host') |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 181 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 182 | 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] | 183 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 184 | if not bb.utils.contains("SDKIMAGE_FEATURES", "package-management", True, False, self.d): |
| 185 | self.host_pm.remove_packaging_data() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 186 | |
| 187 | # Move host RPM library data |
| 188 | native_rpm_state_dir = os.path.join(self.sdk_output, |
| 189 | self.sdk_native_path, |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 190 | self.d.getVar('localstatedir_nativesdk').strip('/'), |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 191 | "lib", |
| 192 | "rpm" |
| 193 | ) |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 194 | self.mkdirhier(native_rpm_state_dir) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 195 | for f in glob.glob(os.path.join(self.sdk_output, |
| 196 | "var", |
| 197 | "lib", |
| 198 | "rpm", |
| 199 | "*")): |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 200 | self.movefile(f, native_rpm_state_dir) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 201 | |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 202 | self.remove(os.path.join(self.sdk_output, "var"), True) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 203 | |
| 204 | # Move host sysconfig data |
| 205 | native_sysconf_dir = os.path.join(self.sdk_output, |
| 206 | self.sdk_native_path, |
| 207 | self.d.getVar('sysconfdir', |
| 208 | True).strip('/'), |
| 209 | ) |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 210 | self.mkdirhier(native_sysconf_dir) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 211 | for f in glob.glob(os.path.join(self.sdk_output, "etc", "rpm*")): |
| 212 | self.movefile(f, native_sysconf_dir) |
| 213 | 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] | 214 | self.movefile(f, native_sysconf_dir) |
| 215 | self.remove(os.path.join(self.sdk_output, "etc"), True) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 216 | |
| 217 | |
| 218 | class OpkgSdk(Sdk): |
| 219 | def __init__(self, d, manifest_dir=None): |
| 220 | super(OpkgSdk, self).__init__(d, manifest_dir) |
| 221 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 222 | self.target_conf = self.d.getVar("IPKGCONF_TARGET") |
| 223 | self.host_conf = self.d.getVar("IPKGCONF_SDK") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 224 | |
| 225 | self.target_manifest = OpkgManifest(d, self.manifest_dir, |
| 226 | Manifest.MANIFEST_TYPE_SDK_TARGET) |
| 227 | self.host_manifest = OpkgManifest(d, self.manifest_dir, |
| 228 | Manifest.MANIFEST_TYPE_SDK_HOST) |
| 229 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 230 | ipk_repo_workdir = "oe-sdk-repo" |
| 231 | if "sdk_ext" in d.getVar("BB_RUNTASK"): |
| 232 | ipk_repo_workdir = "oe-sdk-ext-repo" |
| 233 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 234 | self.target_pm = OpkgPM(d, self.sdk_target_sysroot, self.target_conf, |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 235 | self.d.getVar("ALL_MULTILIB_PACKAGE_ARCHS"), |
| 236 | ipk_repo_workdir=ipk_repo_workdir) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 237 | |
| 238 | self.host_pm = OpkgPM(d, self.sdk_host_sysroot, self.host_conf, |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 239 | self.d.getVar("SDK_PACKAGE_ARCHS"), |
| 240 | ipk_repo_workdir=ipk_repo_workdir) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 241 | |
| 242 | def _populate_sysroot(self, pm, manifest): |
| 243 | pkgs_to_install = manifest.parse_initial_manifest() |
| 244 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 245 | if (self.d.getVar('BUILD_IMAGES_FROM_FEEDS') or "") != "1": |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 246 | pm.write_index() |
| 247 | |
| 248 | pm.update() |
| 249 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 250 | for pkg_type in self.install_order: |
| 251 | if pkg_type in pkgs_to_install: |
| 252 | pm.install(pkgs_to_install[pkg_type], |
| 253 | [False, True][pkg_type == Manifest.PKG_TYPE_ATTEMPT_ONLY]) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 254 | |
| 255 | def _populate(self): |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 256 | execute_pre_post_process(self.d, self.d.getVar("POPULATE_SDK_PRE_TARGET_COMMAND")) |
| 257 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 258 | bb.note("Installing TARGET packages") |
| 259 | self._populate_sysroot(self.target_pm, self.target_manifest) |
| 260 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 261 | self.target_pm.install_complementary(self.d.getVar('SDKIMAGE_INSTALL_COMPLEMENTARY')) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 262 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 263 | self.target_pm.run_intercepts(populate_sdk='target') |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 264 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 265 | 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] | 266 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 267 | if not bb.utils.contains("SDKIMAGE_FEATURES", "package-management", True, False, self.d): |
| 268 | self.target_pm.remove_packaging_data() |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 269 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 270 | bb.note("Installing NATIVESDK packages") |
| 271 | self._populate_sysroot(self.host_pm, self.host_manifest) |
Brad Bishop | 0011132 | 2018-04-01 22:23:53 -0400 | [diff] [blame] | 272 | self.install_locales(self.host_pm) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 273 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 274 | self.host_pm.run_intercepts(populate_sdk='host') |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 275 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 276 | 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] | 277 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 278 | if not bb.utils.contains("SDKIMAGE_FEATURES", "package-management", True, False, self.d): |
| 279 | self.host_pm.remove_packaging_data() |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 280 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 281 | target_sysconfdir = os.path.join(self.sdk_target_sysroot, self.sysconfdir) |
| 282 | host_sysconfdir = os.path.join(self.sdk_host_sysroot, self.sysconfdir) |
| 283 | |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 284 | self.mkdirhier(target_sysconfdir) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 285 | shutil.copy(self.target_conf, target_sysconfdir) |
| 286 | os.chmod(os.path.join(target_sysconfdir, |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 287 | os.path.basename(self.target_conf)), 0o644) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 288 | |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 289 | self.mkdirhier(host_sysconfdir) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 290 | shutil.copy(self.host_conf, host_sysconfdir) |
| 291 | os.chmod(os.path.join(host_sysconfdir, |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 292 | os.path.basename(self.host_conf)), 0o644) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 293 | |
| 294 | 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] | 295 | self.d.getVar('localstatedir_nativesdk').strip('/'), |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 296 | "lib", "opkg") |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 297 | self.mkdirhier(native_opkg_state_dir) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 298 | 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] | 299 | self.movefile(f, native_opkg_state_dir) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 300 | |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 301 | self.remove(os.path.join(self.sdk_output, "var"), True) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 302 | |
| 303 | |
| 304 | class DpkgSdk(Sdk): |
| 305 | def __init__(self, d, manifest_dir=None): |
| 306 | super(DpkgSdk, self).__init__(d, manifest_dir) |
| 307 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 308 | self.target_conf_dir = os.path.join(self.d.getVar("APTCONF_TARGET"), "apt") |
| 309 | 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] | 310 | |
| 311 | self.target_manifest = DpkgManifest(d, self.manifest_dir, |
| 312 | Manifest.MANIFEST_TYPE_SDK_TARGET) |
| 313 | self.host_manifest = DpkgManifest(d, self.manifest_dir, |
| 314 | Manifest.MANIFEST_TYPE_SDK_HOST) |
| 315 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 316 | deb_repo_workdir = "oe-sdk-repo" |
| 317 | if "sdk_ext" in d.getVar("BB_RUNTASK"): |
| 318 | deb_repo_workdir = "oe-sdk-ext-repo" |
| 319 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 320 | self.target_pm = DpkgPM(d, self.sdk_target_sysroot, |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 321 | self.d.getVar("PACKAGE_ARCHS"), |
| 322 | self.d.getVar("DPKG_ARCH"), |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 323 | self.target_conf_dir, |
| 324 | deb_repo_workdir=deb_repo_workdir) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 325 | |
| 326 | self.host_pm = DpkgPM(d, self.sdk_host_sysroot, |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 327 | self.d.getVar("SDK_PACKAGE_ARCHS"), |
| 328 | self.d.getVar("DEB_SDK_ARCH"), |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 329 | self.host_conf_dir, |
| 330 | deb_repo_workdir=deb_repo_workdir) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 331 | |
| 332 | def _copy_apt_dir_to(self, dst_dir): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 333 | staging_etcdir_native = self.d.getVar("STAGING_ETCDIR_NATIVE") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 334 | |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 335 | self.remove(dst_dir, True) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 336 | |
| 337 | shutil.copytree(os.path.join(staging_etcdir_native, "apt"), dst_dir) |
| 338 | |
| 339 | def _populate_sysroot(self, pm, manifest): |
| 340 | pkgs_to_install = manifest.parse_initial_manifest() |
| 341 | |
| 342 | pm.write_index() |
| 343 | pm.update() |
| 344 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 345 | for pkg_type in self.install_order: |
| 346 | if pkg_type in pkgs_to_install: |
| 347 | pm.install(pkgs_to_install[pkg_type], |
| 348 | [False, True][pkg_type == Manifest.PKG_TYPE_ATTEMPT_ONLY]) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 349 | |
| 350 | def _populate(self): |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 351 | execute_pre_post_process(self.d, self.d.getVar("POPULATE_SDK_PRE_TARGET_COMMAND")) |
| 352 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 353 | bb.note("Installing TARGET packages") |
| 354 | self._populate_sysroot(self.target_pm, self.target_manifest) |
| 355 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 356 | self.target_pm.install_complementary(self.d.getVar('SDKIMAGE_INSTALL_COMPLEMENTARY')) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 357 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 358 | self.target_pm.run_intercepts(populate_sdk='target') |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 359 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 360 | 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] | 361 | |
| 362 | self._copy_apt_dir_to(os.path.join(self.sdk_target_sysroot, "etc", "apt")) |
| 363 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 364 | if not bb.utils.contains("SDKIMAGE_FEATURES", "package-management", True, False, self.d): |
| 365 | self.target_pm.remove_packaging_data() |
| 366 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 367 | bb.note("Installing NATIVESDK packages") |
| 368 | self._populate_sysroot(self.host_pm, self.host_manifest) |
Brad Bishop | 0011132 | 2018-04-01 22:23:53 -0400 | [diff] [blame] | 369 | self.install_locales(self.host_pm) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 370 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 371 | self.host_pm.run_intercepts(populate_sdk='host') |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 372 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 373 | 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] | 374 | |
| 375 | self._copy_apt_dir_to(os.path.join(self.sdk_output, self.sdk_native_path, |
| 376 | "etc", "apt")) |
| 377 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 378 | if not bb.utils.contains("SDKIMAGE_FEATURES", "package-management", True, False, self.d): |
| 379 | self.host_pm.remove_packaging_data() |
| 380 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 381 | native_dpkg_state_dir = os.path.join(self.sdk_output, self.sdk_native_path, |
| 382 | "var", "lib", "dpkg") |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 383 | self.mkdirhier(native_dpkg_state_dir) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 384 | 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] | 385 | self.movefile(f, native_dpkg_state_dir) |
| 386 | self.remove(os.path.join(self.sdk_output, "var"), True) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 387 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 388 | |
| 389 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 390 | def sdk_list_installed_packages(d, target, rootfs_dir=None): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 391 | if rootfs_dir is None: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 392 | sdk_output = d.getVar('SDK_OUTPUT') |
| 393 | target_path = d.getVar('SDKTARGETSYSROOT').strip('/') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 394 | |
| 395 | rootfs_dir = [sdk_output, os.path.join(sdk_output, target_path)][target is True] |
| 396 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 397 | img_type = d.getVar('IMAGE_PKGTYPE') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 398 | if img_type == "rpm": |
| 399 | arch_var = ["SDK_PACKAGE_ARCHS", None][target is True] |
| 400 | os_var = ["SDK_OS", None][target is True] |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 401 | return RpmPkgsList(d, rootfs_dir).list_pkgs() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 402 | elif img_type == "ipk": |
| 403 | conf_file_var = ["IPKGCONF_SDK", "IPKGCONF_TARGET"][target is True] |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 404 | return OpkgPkgsList(d, rootfs_dir, d.getVar(conf_file_var)).list_pkgs() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 405 | elif img_type == "deb": |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 406 | return DpkgPkgsList(d, rootfs_dir).list_pkgs() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 407 | |
| 408 | def populate_sdk(d, manifest_dir=None): |
| 409 | env_bkp = os.environ.copy() |
| 410 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 411 | img_type = d.getVar('IMAGE_PKGTYPE') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 412 | if img_type == "rpm": |
| 413 | RpmSdk(d, manifest_dir).populate() |
| 414 | elif img_type == "ipk": |
| 415 | OpkgSdk(d, manifest_dir).populate() |
| 416 | elif img_type == "deb": |
| 417 | DpkgSdk(d, manifest_dir).populate() |
| 418 | |
| 419 | os.environ.clear() |
| 420 | os.environ.update(env_bkp) |
| 421 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 422 | def get_extra_sdkinfo(sstate_dir): |
| 423 | """ |
| 424 | This function is going to be used for generating the target and host manifest files packages of eSDK. |
| 425 | """ |
| 426 | import math |
| 427 | |
| 428 | extra_info = {} |
| 429 | extra_info['tasksizes'] = {} |
| 430 | extra_info['filesizes'] = {} |
| 431 | for root, _, files in os.walk(sstate_dir): |
| 432 | for fn in files: |
| 433 | if fn.endswith('.tgz'): |
| 434 | fsize = int(math.ceil(float(os.path.getsize(os.path.join(root, fn))) / 1024)) |
| 435 | task = fn.rsplit(':',1)[1].split('_',1)[1].split(',')[0] |
| 436 | origtotal = extra_info['tasksizes'].get(task, 0) |
| 437 | extra_info['tasksizes'][task] = origtotal + fsize |
| 438 | extra_info['filesizes'][fn] = fsize |
| 439 | return extra_info |
| 440 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 441 | if __name__ == "__main__": |
| 442 | pass |