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): |
| 155 | bb.note("Installing TARGET packages") |
| 156 | self._populate_sysroot(self.target_pm, self.target_manifest) |
| 157 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 158 | self.target_pm.install_complementary(self.d.getVar('SDKIMAGE_INSTALL_COMPLEMENTARY')) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 159 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 160 | 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] | 161 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 162 | if not bb.utils.contains("SDKIMAGE_FEATURES", "package-management", True, False, self.d): |
| 163 | self.target_pm.remove_packaging_data() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 164 | |
| 165 | bb.note("Installing NATIVESDK packages") |
| 166 | self._populate_sysroot(self.host_pm, self.host_manifest) |
| 167 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 168 | 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] | 169 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 170 | if not bb.utils.contains("SDKIMAGE_FEATURES", "package-management", True, False, self.d): |
| 171 | self.host_pm.remove_packaging_data() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 172 | |
| 173 | # Move host RPM library data |
| 174 | native_rpm_state_dir = os.path.join(self.sdk_output, |
| 175 | self.sdk_native_path, |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 176 | self.d.getVar('localstatedir_nativesdk').strip('/'), |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 177 | "lib", |
| 178 | "rpm" |
| 179 | ) |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 180 | self.mkdirhier(native_rpm_state_dir) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 181 | for f in glob.glob(os.path.join(self.sdk_output, |
| 182 | "var", |
| 183 | "lib", |
| 184 | "rpm", |
| 185 | "*")): |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 186 | self.movefile(f, native_rpm_state_dir) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 187 | |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 188 | self.remove(os.path.join(self.sdk_output, "var"), True) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 189 | |
| 190 | # Move host sysconfig data |
| 191 | native_sysconf_dir = os.path.join(self.sdk_output, |
| 192 | self.sdk_native_path, |
| 193 | self.d.getVar('sysconfdir', |
| 194 | True).strip('/'), |
| 195 | ) |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 196 | self.mkdirhier(native_sysconf_dir) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 197 | for f in glob.glob(os.path.join(self.sdk_output, "etc", "rpm*")): |
| 198 | self.movefile(f, native_sysconf_dir) |
| 199 | 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] | 200 | self.movefile(f, native_sysconf_dir) |
| 201 | self.remove(os.path.join(self.sdk_output, "etc"), True) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 202 | |
| 203 | |
| 204 | class OpkgSdk(Sdk): |
| 205 | def __init__(self, d, manifest_dir=None): |
| 206 | super(OpkgSdk, self).__init__(d, manifest_dir) |
| 207 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 208 | self.target_conf = self.d.getVar("IPKGCONF_TARGET") |
| 209 | self.host_conf = self.d.getVar("IPKGCONF_SDK") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 210 | |
| 211 | self.target_manifest = OpkgManifest(d, self.manifest_dir, |
| 212 | Manifest.MANIFEST_TYPE_SDK_TARGET) |
| 213 | self.host_manifest = OpkgManifest(d, self.manifest_dir, |
| 214 | Manifest.MANIFEST_TYPE_SDK_HOST) |
| 215 | |
| 216 | self.target_pm = OpkgPM(d, self.sdk_target_sysroot, self.target_conf, |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 217 | self.d.getVar("ALL_MULTILIB_PACKAGE_ARCHS")) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 218 | |
| 219 | self.host_pm = OpkgPM(d, self.sdk_host_sysroot, self.host_conf, |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 220 | self.d.getVar("SDK_PACKAGE_ARCHS")) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 221 | |
| 222 | def _populate_sysroot(self, pm, manifest): |
| 223 | pkgs_to_install = manifest.parse_initial_manifest() |
| 224 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 225 | if (self.d.getVar('BUILD_IMAGES_FROM_FEEDS') or "") != "1": |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 226 | pm.write_index() |
| 227 | |
| 228 | pm.update() |
| 229 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 230 | for pkg_type in self.install_order: |
| 231 | if pkg_type in pkgs_to_install: |
| 232 | pm.install(pkgs_to_install[pkg_type], |
| 233 | [False, True][pkg_type == Manifest.PKG_TYPE_ATTEMPT_ONLY]) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 234 | |
| 235 | def _populate(self): |
| 236 | bb.note("Installing TARGET packages") |
| 237 | self._populate_sysroot(self.target_pm, self.target_manifest) |
| 238 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 239 | self.target_pm.install_complementary(self.d.getVar('SDKIMAGE_INSTALL_COMPLEMENTARY')) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 240 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 241 | 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] | 242 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 243 | if not bb.utils.contains("SDKIMAGE_FEATURES", "package-management", True, False, self.d): |
| 244 | self.target_pm.remove_packaging_data() |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 245 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 246 | bb.note("Installing NATIVESDK packages") |
| 247 | self._populate_sysroot(self.host_pm, self.host_manifest) |
| 248 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 249 | 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] | 250 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 251 | if not bb.utils.contains("SDKIMAGE_FEATURES", "package-management", True, False, self.d): |
| 252 | self.host_pm.remove_packaging_data() |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 253 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 254 | target_sysconfdir = os.path.join(self.sdk_target_sysroot, self.sysconfdir) |
| 255 | host_sysconfdir = os.path.join(self.sdk_host_sysroot, self.sysconfdir) |
| 256 | |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 257 | self.mkdirhier(target_sysconfdir) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 258 | shutil.copy(self.target_conf, target_sysconfdir) |
| 259 | os.chmod(os.path.join(target_sysconfdir, |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 260 | os.path.basename(self.target_conf)), 0o644) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 261 | |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 262 | self.mkdirhier(host_sysconfdir) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 263 | shutil.copy(self.host_conf, host_sysconfdir) |
| 264 | os.chmod(os.path.join(host_sysconfdir, |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 265 | os.path.basename(self.host_conf)), 0o644) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 266 | |
| 267 | 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] | 268 | self.d.getVar('localstatedir_nativesdk').strip('/'), |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 269 | "lib", "opkg") |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 270 | self.mkdirhier(native_opkg_state_dir) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 271 | 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] | 272 | self.movefile(f, native_opkg_state_dir) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 273 | |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 274 | self.remove(os.path.join(self.sdk_output, "var"), True) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 275 | |
| 276 | |
| 277 | class DpkgSdk(Sdk): |
| 278 | def __init__(self, d, manifest_dir=None): |
| 279 | super(DpkgSdk, self).__init__(d, manifest_dir) |
| 280 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 281 | self.target_conf_dir = os.path.join(self.d.getVar("APTCONF_TARGET"), "apt") |
| 282 | 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] | 283 | |
| 284 | self.target_manifest = DpkgManifest(d, self.manifest_dir, |
| 285 | Manifest.MANIFEST_TYPE_SDK_TARGET) |
| 286 | self.host_manifest = DpkgManifest(d, self.manifest_dir, |
| 287 | Manifest.MANIFEST_TYPE_SDK_HOST) |
| 288 | |
| 289 | self.target_pm = DpkgPM(d, self.sdk_target_sysroot, |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 290 | self.d.getVar("PACKAGE_ARCHS"), |
| 291 | self.d.getVar("DPKG_ARCH"), |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 292 | self.target_conf_dir) |
| 293 | |
| 294 | self.host_pm = DpkgPM(d, self.sdk_host_sysroot, |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 295 | self.d.getVar("SDK_PACKAGE_ARCHS"), |
| 296 | self.d.getVar("DEB_SDK_ARCH"), |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 297 | self.host_conf_dir) |
| 298 | |
| 299 | def _copy_apt_dir_to(self, dst_dir): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 300 | staging_etcdir_native = self.d.getVar("STAGING_ETCDIR_NATIVE") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 301 | |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 302 | self.remove(dst_dir, True) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 303 | |
| 304 | shutil.copytree(os.path.join(staging_etcdir_native, "apt"), dst_dir) |
| 305 | |
| 306 | def _populate_sysroot(self, pm, manifest): |
| 307 | pkgs_to_install = manifest.parse_initial_manifest() |
| 308 | |
| 309 | pm.write_index() |
| 310 | pm.update() |
| 311 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 312 | for pkg_type in self.install_order: |
| 313 | if pkg_type in pkgs_to_install: |
| 314 | pm.install(pkgs_to_install[pkg_type], |
| 315 | [False, True][pkg_type == Manifest.PKG_TYPE_ATTEMPT_ONLY]) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 316 | |
| 317 | def _populate(self): |
| 318 | bb.note("Installing TARGET packages") |
| 319 | self._populate_sysroot(self.target_pm, self.target_manifest) |
| 320 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 321 | self.target_pm.install_complementary(self.d.getVar('SDKIMAGE_INSTALL_COMPLEMENTARY')) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 322 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 323 | 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] | 324 | |
| 325 | self._copy_apt_dir_to(os.path.join(self.sdk_target_sysroot, "etc", "apt")) |
| 326 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 327 | if not bb.utils.contains("SDKIMAGE_FEATURES", "package-management", True, False, self.d): |
| 328 | self.target_pm.remove_packaging_data() |
| 329 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 330 | bb.note("Installing NATIVESDK packages") |
| 331 | self._populate_sysroot(self.host_pm, self.host_manifest) |
| 332 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 333 | 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] | 334 | |
| 335 | self._copy_apt_dir_to(os.path.join(self.sdk_output, self.sdk_native_path, |
| 336 | "etc", "apt")) |
| 337 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 338 | if not bb.utils.contains("SDKIMAGE_FEATURES", "package-management", True, False, self.d): |
| 339 | self.host_pm.remove_packaging_data() |
| 340 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 341 | native_dpkg_state_dir = os.path.join(self.sdk_output, self.sdk_native_path, |
| 342 | "var", "lib", "dpkg") |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 343 | self.mkdirhier(native_dpkg_state_dir) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 344 | 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] | 345 | self.movefile(f, native_dpkg_state_dir) |
| 346 | self.remove(os.path.join(self.sdk_output, "var"), True) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 347 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 348 | |
| 349 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 350 | def sdk_list_installed_packages(d, target, rootfs_dir=None): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 351 | if rootfs_dir is None: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 352 | sdk_output = d.getVar('SDK_OUTPUT') |
| 353 | target_path = d.getVar('SDKTARGETSYSROOT').strip('/') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 354 | |
| 355 | rootfs_dir = [sdk_output, os.path.join(sdk_output, target_path)][target is True] |
| 356 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 357 | img_type = d.getVar('IMAGE_PKGTYPE') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 358 | if img_type == "rpm": |
| 359 | arch_var = ["SDK_PACKAGE_ARCHS", None][target is True] |
| 360 | os_var = ["SDK_OS", None][target is True] |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 361 | return RpmPkgsList(d, rootfs_dir).list_pkgs() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 362 | elif img_type == "ipk": |
| 363 | conf_file_var = ["IPKGCONF_SDK", "IPKGCONF_TARGET"][target is True] |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 364 | return OpkgPkgsList(d, rootfs_dir, d.getVar(conf_file_var)).list_pkgs() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 365 | elif img_type == "deb": |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 366 | return DpkgPkgsList(d, rootfs_dir).list_pkgs() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 367 | |
| 368 | def populate_sdk(d, manifest_dir=None): |
| 369 | env_bkp = os.environ.copy() |
| 370 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 371 | img_type = d.getVar('IMAGE_PKGTYPE') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 372 | if img_type == "rpm": |
| 373 | RpmSdk(d, manifest_dir).populate() |
| 374 | elif img_type == "ipk": |
| 375 | OpkgSdk(d, manifest_dir).populate() |
| 376 | elif img_type == "deb": |
| 377 | DpkgSdk(d, manifest_dir).populate() |
| 378 | |
| 379 | os.environ.clear() |
| 380 | os.environ.update(env_bkp) |
| 381 | |
| 382 | if __name__ == "__main__": |
| 383 | pass |