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