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 |
| 8 | |
| 9 | |
| 10 | class Sdk(object): |
| 11 | __metaclass__ = ABCMeta |
| 12 | |
| 13 | def __init__(self, d, manifest_dir): |
| 14 | self.d = d |
| 15 | self.sdk_output = self.d.getVar('SDK_OUTPUT', True) |
| 16 | self.sdk_native_path = self.d.getVar('SDKPATHNATIVE', True).strip('/') |
| 17 | self.target_path = self.d.getVar('SDKTARGETSYSROOT', True).strip('/') |
| 18 | self.sysconfdir = self.d.getVar('sysconfdir', True).strip('/') |
| 19 | |
| 20 | self.sdk_target_sysroot = os.path.join(self.sdk_output, self.target_path) |
| 21 | self.sdk_host_sysroot = self.sdk_output |
| 22 | |
| 23 | if manifest_dir is None: |
| 24 | self.manifest_dir = self.d.getVar("SDK_DIR", True) |
| 25 | else: |
| 26 | self.manifest_dir = manifest_dir |
| 27 | |
| 28 | bb.utils.remove(self.sdk_output, True) |
| 29 | |
| 30 | self.install_order = Manifest.INSTALL_ORDER |
| 31 | |
| 32 | @abstractmethod |
| 33 | def _populate(self): |
| 34 | pass |
| 35 | |
| 36 | def populate(self): |
| 37 | bb.utils.mkdirhier(self.sdk_output) |
| 38 | |
| 39 | # call backend dependent implementation |
| 40 | self._populate() |
| 41 | |
| 42 | # Don't ship any libGL in the SDK |
| 43 | bb.utils.remove(os.path.join(self.sdk_output, self.sdk_native_path, |
| 44 | self.d.getVar('libdir_nativesdk', True).strip('/'), |
| 45 | "libGL*")) |
| 46 | |
| 47 | # Fix or remove broken .la files |
| 48 | bb.utils.remove(os.path.join(self.sdk_output, self.sdk_native_path, |
| 49 | self.d.getVar('libdir_nativesdk', True).strip('/'), |
| 50 | "*.la")) |
| 51 | |
| 52 | # Link the ld.so.cache file into the hosts filesystem |
| 53 | link_name = os.path.join(self.sdk_output, self.sdk_native_path, |
| 54 | self.sysconfdir, "ld.so.cache") |
| 55 | bb.utils.mkdirhier(os.path.dirname(link_name)) |
| 56 | os.symlink("/etc/ld.so.cache", link_name) |
| 57 | |
| 58 | execute_pre_post_process(self.d, self.d.getVar('SDK_POSTPROCESS_COMMAND', True)) |
| 59 | |
| 60 | |
| 61 | class RpmSdk(Sdk): |
| 62 | def __init__(self, d, manifest_dir=None): |
| 63 | super(RpmSdk, self).__init__(d, manifest_dir) |
| 64 | |
| 65 | self.target_manifest = RpmManifest(d, self.manifest_dir, |
| 66 | Manifest.MANIFEST_TYPE_SDK_TARGET) |
| 67 | self.host_manifest = RpmManifest(d, self.manifest_dir, |
| 68 | Manifest.MANIFEST_TYPE_SDK_HOST) |
| 69 | |
| 70 | target_providename = ['/bin/sh', |
| 71 | '/bin/bash', |
| 72 | '/usr/bin/env', |
| 73 | '/usr/bin/perl', |
| 74 | 'pkgconfig' |
| 75 | ] |
| 76 | |
| 77 | self.target_pm = RpmPM(d, |
| 78 | self.sdk_target_sysroot, |
| 79 | self.d.getVar('TARGET_VENDOR', True), |
| 80 | 'target', |
| 81 | target_providename |
| 82 | ) |
| 83 | |
| 84 | sdk_providename = ['/bin/sh', |
| 85 | '/bin/bash', |
| 86 | '/usr/bin/env', |
| 87 | '/usr/bin/perl', |
| 88 | 'pkgconfig', |
| 89 | 'libGL.so()(64bit)', |
| 90 | 'libGL.so' |
| 91 | ] |
| 92 | |
| 93 | self.host_pm = RpmPM(d, |
| 94 | self.sdk_host_sysroot, |
| 95 | self.d.getVar('SDK_VENDOR', True), |
| 96 | 'host', |
| 97 | sdk_providename, |
| 98 | "SDK_PACKAGE_ARCHS", |
| 99 | "SDK_OS" |
| 100 | ) |
| 101 | |
| 102 | def _populate_sysroot(self, pm, manifest): |
| 103 | pkgs_to_install = manifest.parse_initial_manifest() |
| 104 | |
| 105 | pm.create_configs() |
| 106 | pm.write_index() |
| 107 | pm.dump_all_available_pkgs() |
| 108 | pm.update() |
| 109 | |
| 110 | pkgs = [] |
| 111 | pkgs_attempt = [] |
| 112 | for pkg_type in pkgs_to_install: |
| 113 | if pkg_type == Manifest.PKG_TYPE_ATTEMPT_ONLY: |
| 114 | pkgs_attempt += pkgs_to_install[pkg_type] |
| 115 | else: |
| 116 | pkgs += pkgs_to_install[pkg_type] |
| 117 | |
| 118 | pm.install(pkgs) |
| 119 | |
| 120 | pm.install(pkgs_attempt, True) |
| 121 | |
| 122 | def _populate(self): |
| 123 | bb.note("Installing TARGET packages") |
| 124 | self._populate_sysroot(self.target_pm, self.target_manifest) |
| 125 | |
| 126 | self.target_pm.install_complementary(self.d.getVar('SDKIMAGE_INSTALL_COMPLEMENTARY', True)) |
| 127 | |
| 128 | execute_pre_post_process(self.d, self.d.getVar("POPULATE_SDK_POST_TARGET_COMMAND", True)) |
| 129 | |
| 130 | self.target_pm.remove_packaging_data() |
| 131 | |
| 132 | bb.note("Installing NATIVESDK packages") |
| 133 | self._populate_sysroot(self.host_pm, self.host_manifest) |
| 134 | |
| 135 | execute_pre_post_process(self.d, self.d.getVar("POPULATE_SDK_POST_HOST_COMMAND", True)) |
| 136 | |
| 137 | self.host_pm.remove_packaging_data() |
| 138 | |
| 139 | # Move host RPM library data |
| 140 | native_rpm_state_dir = os.path.join(self.sdk_output, |
| 141 | self.sdk_native_path, |
| 142 | self.d.getVar('localstatedir_nativesdk', True).strip('/'), |
| 143 | "lib", |
| 144 | "rpm" |
| 145 | ) |
| 146 | bb.utils.mkdirhier(native_rpm_state_dir) |
| 147 | for f in glob.glob(os.path.join(self.sdk_output, |
| 148 | "var", |
| 149 | "lib", |
| 150 | "rpm", |
| 151 | "*")): |
| 152 | bb.utils.movefile(f, native_rpm_state_dir) |
| 153 | |
| 154 | bb.utils.remove(os.path.join(self.sdk_output, "var"), True) |
| 155 | |
| 156 | # Move host sysconfig data |
| 157 | native_sysconf_dir = os.path.join(self.sdk_output, |
| 158 | self.sdk_native_path, |
| 159 | self.d.getVar('sysconfdir', |
| 160 | True).strip('/'), |
| 161 | ) |
| 162 | bb.utils.mkdirhier(native_sysconf_dir) |
| 163 | for f in glob.glob(os.path.join(self.sdk_output, "etc", "*")): |
| 164 | bb.utils.movefile(f, native_sysconf_dir) |
| 165 | bb.utils.remove(os.path.join(self.sdk_output, "etc"), True) |
| 166 | |
| 167 | |
| 168 | class OpkgSdk(Sdk): |
| 169 | def __init__(self, d, manifest_dir=None): |
| 170 | super(OpkgSdk, self).__init__(d, manifest_dir) |
| 171 | |
| 172 | self.target_conf = self.d.getVar("IPKGCONF_TARGET", True) |
| 173 | self.host_conf = self.d.getVar("IPKGCONF_SDK", True) |
| 174 | |
| 175 | self.target_manifest = OpkgManifest(d, self.manifest_dir, |
| 176 | Manifest.MANIFEST_TYPE_SDK_TARGET) |
| 177 | self.host_manifest = OpkgManifest(d, self.manifest_dir, |
| 178 | Manifest.MANIFEST_TYPE_SDK_HOST) |
| 179 | |
| 180 | self.target_pm = OpkgPM(d, self.sdk_target_sysroot, self.target_conf, |
| 181 | self.d.getVar("ALL_MULTILIB_PACKAGE_ARCHS", True)) |
| 182 | |
| 183 | self.host_pm = OpkgPM(d, self.sdk_host_sysroot, self.host_conf, |
| 184 | self.d.getVar("SDK_PACKAGE_ARCHS", True)) |
| 185 | |
| 186 | def _populate_sysroot(self, pm, manifest): |
| 187 | pkgs_to_install = manifest.parse_initial_manifest() |
| 188 | |
| 189 | if (self.d.getVar('BUILD_IMAGES_FROM_FEEDS', True) or "") != "1": |
| 190 | pm.write_index() |
| 191 | |
| 192 | pm.update() |
| 193 | |
| 194 | pkgs = [] |
| 195 | pkgs_attempt = [] |
| 196 | for pkg_type in pkgs_to_install: |
| 197 | if pkg_type == Manifest.PKG_TYPE_ATTEMPT_ONLY: |
| 198 | pkgs_attempt += pkgs_to_install[pkg_type] |
| 199 | else: |
| 200 | pkgs += pkgs_to_install[pkg_type] |
| 201 | |
| 202 | pm.install(pkgs) |
| 203 | |
| 204 | pm.install(pkgs_attempt, True) |
| 205 | |
| 206 | def _populate(self): |
| 207 | bb.note("Installing TARGET packages") |
| 208 | self._populate_sysroot(self.target_pm, self.target_manifest) |
| 209 | |
| 210 | self.target_pm.install_complementary(self.d.getVar('SDKIMAGE_INSTALL_COMPLEMENTARY', True)) |
| 211 | |
| 212 | execute_pre_post_process(self.d, self.d.getVar("POPULATE_SDK_POST_TARGET_COMMAND", True)) |
| 213 | |
| 214 | bb.note("Installing NATIVESDK packages") |
| 215 | self._populate_sysroot(self.host_pm, self.host_manifest) |
| 216 | |
| 217 | execute_pre_post_process(self.d, self.d.getVar("POPULATE_SDK_POST_HOST_COMMAND", True)) |
| 218 | |
| 219 | target_sysconfdir = os.path.join(self.sdk_target_sysroot, self.sysconfdir) |
| 220 | host_sysconfdir = os.path.join(self.sdk_host_sysroot, self.sysconfdir) |
| 221 | |
| 222 | bb.utils.mkdirhier(target_sysconfdir) |
| 223 | shutil.copy(self.target_conf, target_sysconfdir) |
| 224 | os.chmod(os.path.join(target_sysconfdir, |
| 225 | os.path.basename(self.target_conf)), 0644) |
| 226 | |
| 227 | bb.utils.mkdirhier(host_sysconfdir) |
| 228 | shutil.copy(self.host_conf, host_sysconfdir) |
| 229 | os.chmod(os.path.join(host_sysconfdir, |
| 230 | os.path.basename(self.host_conf)), 0644) |
| 231 | |
| 232 | native_opkg_state_dir = os.path.join(self.sdk_output, self.sdk_native_path, |
| 233 | self.d.getVar('localstatedir_nativesdk', True).strip('/'), |
| 234 | "lib", "opkg") |
| 235 | bb.utils.mkdirhier(native_opkg_state_dir) |
| 236 | for f in glob.glob(os.path.join(self.sdk_output, "var", "lib", "opkg", "*")): |
| 237 | bb.utils.movefile(f, native_opkg_state_dir) |
| 238 | |
| 239 | bb.utils.remove(os.path.join(self.sdk_output, "var"), True) |
| 240 | |
| 241 | |
| 242 | class DpkgSdk(Sdk): |
| 243 | def __init__(self, d, manifest_dir=None): |
| 244 | super(DpkgSdk, self).__init__(d, manifest_dir) |
| 245 | |
| 246 | self.target_conf_dir = os.path.join(self.d.getVar("APTCONF_TARGET", True), "apt") |
| 247 | self.host_conf_dir = os.path.join(self.d.getVar("APTCONF_TARGET", True), "apt-sdk") |
| 248 | |
| 249 | self.target_manifest = DpkgManifest(d, self.manifest_dir, |
| 250 | Manifest.MANIFEST_TYPE_SDK_TARGET) |
| 251 | self.host_manifest = DpkgManifest(d, self.manifest_dir, |
| 252 | Manifest.MANIFEST_TYPE_SDK_HOST) |
| 253 | |
| 254 | self.target_pm = DpkgPM(d, self.sdk_target_sysroot, |
| 255 | self.d.getVar("PACKAGE_ARCHS", True), |
| 256 | self.d.getVar("DPKG_ARCH", True), |
| 257 | self.target_conf_dir) |
| 258 | |
| 259 | self.host_pm = DpkgPM(d, self.sdk_host_sysroot, |
| 260 | self.d.getVar("SDK_PACKAGE_ARCHS", True), |
| 261 | self.d.getVar("DEB_SDK_ARCH", True), |
| 262 | self.host_conf_dir) |
| 263 | |
| 264 | def _copy_apt_dir_to(self, dst_dir): |
| 265 | staging_etcdir_native = self.d.getVar("STAGING_ETCDIR_NATIVE", True) |
| 266 | |
| 267 | bb.utils.remove(dst_dir, True) |
| 268 | |
| 269 | shutil.copytree(os.path.join(staging_etcdir_native, "apt"), dst_dir) |
| 270 | |
| 271 | def _populate_sysroot(self, pm, manifest): |
| 272 | pkgs_to_install = manifest.parse_initial_manifest() |
| 273 | |
| 274 | pm.write_index() |
| 275 | pm.update() |
| 276 | |
| 277 | pkgs = [] |
| 278 | pkgs_attempt = [] |
| 279 | for pkg_type in pkgs_to_install: |
| 280 | if pkg_type == Manifest.PKG_TYPE_ATTEMPT_ONLY: |
| 281 | pkgs_attempt += pkgs_to_install[pkg_type] |
| 282 | else: |
| 283 | pkgs += pkgs_to_install[pkg_type] |
| 284 | |
| 285 | pm.install(pkgs) |
| 286 | |
| 287 | pm.install(pkgs_attempt, True) |
| 288 | |
| 289 | def _populate(self): |
| 290 | bb.note("Installing TARGET packages") |
| 291 | self._populate_sysroot(self.target_pm, self.target_manifest) |
| 292 | |
| 293 | self.target_pm.install_complementary(self.d.getVar('SDKIMAGE_INSTALL_COMPLEMENTARY', True)) |
| 294 | |
| 295 | execute_pre_post_process(self.d, self.d.getVar("POPULATE_SDK_POST_TARGET_COMMAND", True)) |
| 296 | |
| 297 | self._copy_apt_dir_to(os.path.join(self.sdk_target_sysroot, "etc", "apt")) |
| 298 | |
| 299 | bb.note("Installing NATIVESDK packages") |
| 300 | self._populate_sysroot(self.host_pm, self.host_manifest) |
| 301 | |
| 302 | execute_pre_post_process(self.d, self.d.getVar("POPULATE_SDK_POST_HOST_COMMAND", True)) |
| 303 | |
| 304 | self._copy_apt_dir_to(os.path.join(self.sdk_output, self.sdk_native_path, |
| 305 | "etc", "apt")) |
| 306 | |
| 307 | native_dpkg_state_dir = os.path.join(self.sdk_output, self.sdk_native_path, |
| 308 | "var", "lib", "dpkg") |
| 309 | bb.utils.mkdirhier(native_dpkg_state_dir) |
| 310 | for f in glob.glob(os.path.join(self.sdk_output, "var", "lib", "dpkg", "*")): |
| 311 | bb.utils.movefile(f, native_dpkg_state_dir) |
| 312 | |
| 313 | bb.utils.remove(os.path.join(self.sdk_output, "var"), True) |
| 314 | |
| 315 | |
| 316 | def sdk_list_installed_packages(d, target, format=None, rootfs_dir=None): |
| 317 | if rootfs_dir is None: |
| 318 | sdk_output = d.getVar('SDK_OUTPUT', True) |
| 319 | target_path = d.getVar('SDKTARGETSYSROOT', True).strip('/') |
| 320 | |
| 321 | rootfs_dir = [sdk_output, os.path.join(sdk_output, target_path)][target is True] |
| 322 | |
| 323 | img_type = d.getVar('IMAGE_PKGTYPE', True) |
| 324 | if img_type == "rpm": |
| 325 | arch_var = ["SDK_PACKAGE_ARCHS", None][target is True] |
| 326 | os_var = ["SDK_OS", None][target is True] |
| 327 | return RpmPkgsList(d, rootfs_dir, arch_var, os_var).list(format) |
| 328 | elif img_type == "ipk": |
| 329 | conf_file_var = ["IPKGCONF_SDK", "IPKGCONF_TARGET"][target is True] |
| 330 | return OpkgPkgsList(d, rootfs_dir, d.getVar(conf_file_var, True)).list(format) |
| 331 | elif img_type == "deb": |
| 332 | return DpkgPkgsList(d, rootfs_dir).list(format) |
| 333 | |
| 334 | def populate_sdk(d, manifest_dir=None): |
| 335 | env_bkp = os.environ.copy() |
| 336 | |
| 337 | img_type = d.getVar('IMAGE_PKGTYPE', True) |
| 338 | if img_type == "rpm": |
| 339 | RpmSdk(d, manifest_dir).populate() |
| 340 | elif img_type == "ipk": |
| 341 | OpkgSdk(d, manifest_dir).populate() |
| 342 | elif img_type == "deb": |
| 343 | DpkgSdk(d, manifest_dir).populate() |
| 344 | |
| 345 | os.environ.clear() |
| 346 | os.environ.update(env_bkp) |
| 347 | |
| 348 | if __name__ == "__main__": |
| 349 | pass |