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 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 165 | rpm_repo_workdir = "oe-sdk-repo" |
| 166 | if "sdk_ext" in d.getVar("BB_RUNTASK"): |
| 167 | rpm_repo_workdir = "oe-sdk-ext-repo" |
| 168 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 169 | self.target_pm = RpmPM(d, |
| 170 | self.sdk_target_sysroot, |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 171 | self.d.getVar('TARGET_VENDOR'), |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 172 | 'target', |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 173 | rpm_repo_workdir=rpm_repo_workdir |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 174 | ) |
| 175 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 176 | self.host_pm = RpmPM(d, |
| 177 | self.sdk_host_sysroot, |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 178 | self.d.getVar('SDK_VENDOR'), |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 179 | 'host', |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 180 | "SDK_PACKAGE_ARCHS", |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 181 | "SDK_OS", |
| 182 | rpm_repo_workdir=rpm_repo_workdir |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 183 | ) |
| 184 | |
| 185 | def _populate_sysroot(self, pm, manifest): |
| 186 | pkgs_to_install = manifest.parse_initial_manifest() |
| 187 | |
| 188 | pm.create_configs() |
| 189 | pm.write_index() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 190 | pm.update() |
| 191 | |
| 192 | pkgs = [] |
| 193 | pkgs_attempt = [] |
| 194 | for pkg_type in pkgs_to_install: |
| 195 | if pkg_type == Manifest.PKG_TYPE_ATTEMPT_ONLY: |
| 196 | pkgs_attempt += pkgs_to_install[pkg_type] |
| 197 | else: |
| 198 | pkgs += pkgs_to_install[pkg_type] |
| 199 | |
| 200 | pm.install(pkgs) |
| 201 | |
| 202 | pm.install(pkgs_attempt, True) |
| 203 | |
| 204 | def _populate(self): |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 205 | execute_pre_post_process(self.d, self.d.getVar("POPULATE_SDK_PRE_TARGET_COMMAND")) |
| 206 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 207 | bb.note("Installing TARGET packages") |
| 208 | self._populate_sysroot(self.target_pm, self.target_manifest) |
| 209 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 210 | self.target_pm.install_complementary(self.d.getVar('SDKIMAGE_INSTALL_COMPLEMENTARY')) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 211 | |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 212 | self.target_pm.run_intercepts() |
| 213 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 214 | 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] | 215 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 216 | if not bb.utils.contains("SDKIMAGE_FEATURES", "package-management", True, False, self.d): |
| 217 | self.target_pm.remove_packaging_data() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 218 | |
| 219 | bb.note("Installing NATIVESDK packages") |
| 220 | self._populate_sysroot(self.host_pm, self.host_manifest) |
Brad Bishop | 0011132 | 2018-04-01 22:23:53 -0400 | [diff] [blame] | 221 | self.install_locales(self.host_pm) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 222 | |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 223 | self.host_pm.run_intercepts() |
| 224 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 225 | 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] | 226 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 227 | if not bb.utils.contains("SDKIMAGE_FEATURES", "package-management", True, False, self.d): |
| 228 | self.host_pm.remove_packaging_data() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 229 | |
| 230 | # Move host RPM library data |
| 231 | native_rpm_state_dir = os.path.join(self.sdk_output, |
| 232 | self.sdk_native_path, |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 233 | self.d.getVar('localstatedir_nativesdk').strip('/'), |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 234 | "lib", |
| 235 | "rpm" |
| 236 | ) |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 237 | self.mkdirhier(native_rpm_state_dir) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 238 | for f in glob.glob(os.path.join(self.sdk_output, |
| 239 | "var", |
| 240 | "lib", |
| 241 | "rpm", |
| 242 | "*")): |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 243 | self.movefile(f, native_rpm_state_dir) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 244 | |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 245 | self.remove(os.path.join(self.sdk_output, "var"), True) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 246 | |
| 247 | # Move host sysconfig data |
| 248 | native_sysconf_dir = os.path.join(self.sdk_output, |
| 249 | self.sdk_native_path, |
| 250 | self.d.getVar('sysconfdir', |
| 251 | True).strip('/'), |
| 252 | ) |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 253 | self.mkdirhier(native_sysconf_dir) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 254 | for f in glob.glob(os.path.join(self.sdk_output, "etc", "rpm*")): |
| 255 | self.movefile(f, native_sysconf_dir) |
| 256 | 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] | 257 | self.movefile(f, native_sysconf_dir) |
| 258 | self.remove(os.path.join(self.sdk_output, "etc"), True) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 259 | |
| 260 | |
| 261 | class OpkgSdk(Sdk): |
| 262 | def __init__(self, d, manifest_dir=None): |
| 263 | super(OpkgSdk, self).__init__(d, manifest_dir) |
| 264 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 265 | self.target_conf = self.d.getVar("IPKGCONF_TARGET") |
| 266 | self.host_conf = self.d.getVar("IPKGCONF_SDK") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 267 | |
| 268 | self.target_manifest = OpkgManifest(d, self.manifest_dir, |
| 269 | Manifest.MANIFEST_TYPE_SDK_TARGET) |
| 270 | self.host_manifest = OpkgManifest(d, self.manifest_dir, |
| 271 | Manifest.MANIFEST_TYPE_SDK_HOST) |
| 272 | |
| 273 | self.target_pm = OpkgPM(d, self.sdk_target_sysroot, self.target_conf, |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 274 | self.d.getVar("ALL_MULTILIB_PACKAGE_ARCHS")) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 275 | |
| 276 | self.host_pm = OpkgPM(d, self.sdk_host_sysroot, self.host_conf, |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 277 | self.d.getVar("SDK_PACKAGE_ARCHS")) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 278 | |
| 279 | def _populate_sysroot(self, pm, manifest): |
| 280 | pkgs_to_install = manifest.parse_initial_manifest() |
| 281 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 282 | if (self.d.getVar('BUILD_IMAGES_FROM_FEEDS') or "") != "1": |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 283 | pm.write_index() |
| 284 | |
| 285 | pm.update() |
| 286 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 287 | for pkg_type in self.install_order: |
| 288 | if pkg_type in pkgs_to_install: |
| 289 | pm.install(pkgs_to_install[pkg_type], |
| 290 | [False, True][pkg_type == Manifest.PKG_TYPE_ATTEMPT_ONLY]) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 291 | |
| 292 | def _populate(self): |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 293 | execute_pre_post_process(self.d, self.d.getVar("POPULATE_SDK_PRE_TARGET_COMMAND")) |
| 294 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 295 | bb.note("Installing TARGET packages") |
| 296 | self._populate_sysroot(self.target_pm, self.target_manifest) |
| 297 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 298 | self.target_pm.install_complementary(self.d.getVar('SDKIMAGE_INSTALL_COMPLEMENTARY')) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 299 | |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 300 | self.target_pm.run_intercepts() |
| 301 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 302 | 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] | 303 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 304 | if not bb.utils.contains("SDKIMAGE_FEATURES", "package-management", True, False, self.d): |
| 305 | self.target_pm.remove_packaging_data() |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 306 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 307 | bb.note("Installing NATIVESDK packages") |
| 308 | self._populate_sysroot(self.host_pm, self.host_manifest) |
Brad Bishop | 0011132 | 2018-04-01 22:23:53 -0400 | [diff] [blame] | 309 | self.install_locales(self.host_pm) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 310 | |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 311 | self.host_pm.run_intercepts() |
| 312 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 313 | 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] | 314 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 315 | if not bb.utils.contains("SDKIMAGE_FEATURES", "package-management", True, False, self.d): |
| 316 | self.host_pm.remove_packaging_data() |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 317 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 318 | target_sysconfdir = os.path.join(self.sdk_target_sysroot, self.sysconfdir) |
| 319 | host_sysconfdir = os.path.join(self.sdk_host_sysroot, self.sysconfdir) |
| 320 | |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 321 | self.mkdirhier(target_sysconfdir) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 322 | shutil.copy(self.target_conf, target_sysconfdir) |
| 323 | os.chmod(os.path.join(target_sysconfdir, |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 324 | os.path.basename(self.target_conf)), 0o644) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 325 | |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 326 | self.mkdirhier(host_sysconfdir) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 327 | shutil.copy(self.host_conf, host_sysconfdir) |
| 328 | os.chmod(os.path.join(host_sysconfdir, |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 329 | os.path.basename(self.host_conf)), 0o644) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 330 | |
| 331 | 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] | 332 | self.d.getVar('localstatedir_nativesdk').strip('/'), |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 333 | "lib", "opkg") |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 334 | self.mkdirhier(native_opkg_state_dir) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 335 | 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] | 336 | self.movefile(f, native_opkg_state_dir) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 337 | |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 338 | self.remove(os.path.join(self.sdk_output, "var"), True) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 339 | |
| 340 | |
| 341 | class DpkgSdk(Sdk): |
| 342 | def __init__(self, d, manifest_dir=None): |
| 343 | super(DpkgSdk, self).__init__(d, manifest_dir) |
| 344 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 345 | self.target_conf_dir = os.path.join(self.d.getVar("APTCONF_TARGET"), "apt") |
| 346 | 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] | 347 | |
| 348 | self.target_manifest = DpkgManifest(d, self.manifest_dir, |
| 349 | Manifest.MANIFEST_TYPE_SDK_TARGET) |
| 350 | self.host_manifest = DpkgManifest(d, self.manifest_dir, |
| 351 | Manifest.MANIFEST_TYPE_SDK_HOST) |
| 352 | |
| 353 | self.target_pm = DpkgPM(d, self.sdk_target_sysroot, |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 354 | self.d.getVar("PACKAGE_ARCHS"), |
| 355 | self.d.getVar("DPKG_ARCH"), |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 356 | self.target_conf_dir) |
| 357 | |
| 358 | self.host_pm = DpkgPM(d, self.sdk_host_sysroot, |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 359 | self.d.getVar("SDK_PACKAGE_ARCHS"), |
| 360 | self.d.getVar("DEB_SDK_ARCH"), |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 361 | self.host_conf_dir) |
| 362 | |
| 363 | def _copy_apt_dir_to(self, dst_dir): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 364 | staging_etcdir_native = self.d.getVar("STAGING_ETCDIR_NATIVE") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 365 | |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 366 | self.remove(dst_dir, True) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 367 | |
| 368 | shutil.copytree(os.path.join(staging_etcdir_native, "apt"), dst_dir) |
| 369 | |
| 370 | def _populate_sysroot(self, pm, manifest): |
| 371 | pkgs_to_install = manifest.parse_initial_manifest() |
| 372 | |
| 373 | pm.write_index() |
| 374 | pm.update() |
| 375 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 376 | for pkg_type in self.install_order: |
| 377 | if pkg_type in pkgs_to_install: |
| 378 | pm.install(pkgs_to_install[pkg_type], |
| 379 | [False, True][pkg_type == Manifest.PKG_TYPE_ATTEMPT_ONLY]) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 380 | |
| 381 | def _populate(self): |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 382 | execute_pre_post_process(self.d, self.d.getVar("POPULATE_SDK_PRE_TARGET_COMMAND")) |
| 383 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 384 | bb.note("Installing TARGET packages") |
| 385 | self._populate_sysroot(self.target_pm, self.target_manifest) |
| 386 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 387 | self.target_pm.install_complementary(self.d.getVar('SDKIMAGE_INSTALL_COMPLEMENTARY')) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 388 | |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 389 | self.target_pm.run_intercepts() |
| 390 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 391 | 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] | 392 | |
| 393 | self._copy_apt_dir_to(os.path.join(self.sdk_target_sysroot, "etc", "apt")) |
| 394 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 395 | if not bb.utils.contains("SDKIMAGE_FEATURES", "package-management", True, False, self.d): |
| 396 | self.target_pm.remove_packaging_data() |
| 397 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 398 | bb.note("Installing NATIVESDK packages") |
| 399 | self._populate_sysroot(self.host_pm, self.host_manifest) |
Brad Bishop | 0011132 | 2018-04-01 22:23:53 -0400 | [diff] [blame] | 400 | self.install_locales(self.host_pm) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 401 | |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 402 | self.host_pm.run_intercepts() |
| 403 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 404 | 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] | 405 | |
| 406 | self._copy_apt_dir_to(os.path.join(self.sdk_output, self.sdk_native_path, |
| 407 | "etc", "apt")) |
| 408 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 409 | if not bb.utils.contains("SDKIMAGE_FEATURES", "package-management", True, False, self.d): |
| 410 | self.host_pm.remove_packaging_data() |
| 411 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 412 | native_dpkg_state_dir = os.path.join(self.sdk_output, self.sdk_native_path, |
| 413 | "var", "lib", "dpkg") |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 414 | self.mkdirhier(native_dpkg_state_dir) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 415 | 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] | 416 | self.movefile(f, native_dpkg_state_dir) |
| 417 | self.remove(os.path.join(self.sdk_output, "var"), True) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 418 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 419 | |
| 420 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 421 | def sdk_list_installed_packages(d, target, rootfs_dir=None): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 422 | if rootfs_dir is None: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 423 | sdk_output = d.getVar('SDK_OUTPUT') |
| 424 | target_path = d.getVar('SDKTARGETSYSROOT').strip('/') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 425 | |
| 426 | rootfs_dir = [sdk_output, os.path.join(sdk_output, target_path)][target is True] |
| 427 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 428 | img_type = d.getVar('IMAGE_PKGTYPE') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 429 | if img_type == "rpm": |
| 430 | arch_var = ["SDK_PACKAGE_ARCHS", None][target is True] |
| 431 | os_var = ["SDK_OS", None][target is True] |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 432 | return RpmPkgsList(d, rootfs_dir).list_pkgs() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 433 | elif img_type == "ipk": |
| 434 | conf_file_var = ["IPKGCONF_SDK", "IPKGCONF_TARGET"][target is True] |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 435 | return OpkgPkgsList(d, rootfs_dir, d.getVar(conf_file_var)).list_pkgs() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 436 | elif img_type == "deb": |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 437 | return DpkgPkgsList(d, rootfs_dir).list_pkgs() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 438 | |
| 439 | def populate_sdk(d, manifest_dir=None): |
| 440 | env_bkp = os.environ.copy() |
| 441 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 442 | img_type = d.getVar('IMAGE_PKGTYPE') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 443 | if img_type == "rpm": |
| 444 | RpmSdk(d, manifest_dir).populate() |
| 445 | elif img_type == "ipk": |
| 446 | OpkgSdk(d, manifest_dir).populate() |
| 447 | elif img_type == "deb": |
| 448 | DpkgSdk(d, manifest_dir).populate() |
| 449 | |
| 450 | os.environ.clear() |
| 451 | os.environ.update(env_bkp) |
| 452 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 453 | def get_extra_sdkinfo(sstate_dir): |
| 454 | """ |
| 455 | This function is going to be used for generating the target and host manifest files packages of eSDK. |
| 456 | """ |
| 457 | import math |
| 458 | |
| 459 | extra_info = {} |
| 460 | extra_info['tasksizes'] = {} |
| 461 | extra_info['filesizes'] = {} |
| 462 | for root, _, files in os.walk(sstate_dir): |
| 463 | for fn in files: |
| 464 | if fn.endswith('.tgz'): |
| 465 | fsize = int(math.ceil(float(os.path.getsize(os.path.join(root, fn))) / 1024)) |
| 466 | task = fn.rsplit(':',1)[1].split('_',1)[1].split(',')[0] |
| 467 | origtotal = extra_info['tasksizes'].get(task, 0) |
| 468 | extra_info['tasksizes'][task] = origtotal + fsize |
| 469 | extra_info['filesizes'][fn] = fsize |
| 470 | return extra_info |
| 471 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 472 | if __name__ == "__main__": |
| 473 | pass |