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