diff options
| author | Laurentiu Palcu <laurentiu.palcu@intel.com> | 2014-01-22 14:21:39 +0200 |
|---|---|---|
| committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2014-02-11 11:53:40 +0000 |
| commit | 09c508abd56c107c46dadeb3683722b30b015a3e (patch) | |
| tree | 6ca1339c027200f1c8464caee43898d4df4827a1 | |
| parent | 080ce635164e3b4d6036205c1ec3419dd629615d (diff) | |
| download | poky-09c508abd56c107c46dadeb3683722b30b015a3e.tar.gz | |
lib/oe/sdk.py: add SDK class
This new file contains the python 'populate sdk' implementation of the
old bash populate_sdk_image() function for Opkg and Dpkg.
(From OE-Core rev: 6247efaba592db924e6466c39aef441f0e07c62a)
Signed-off-by: Laurentiu Palcu <laurentiu.palcu@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
| -rw-r--r-- | meta/lib/oe/sdk.py | 209 |
1 files changed, 209 insertions, 0 deletions
diff --git a/meta/lib/oe/sdk.py b/meta/lib/oe/sdk.py new file mode 100644 index 0000000000..c24b34d1c0 --- /dev/null +++ b/meta/lib/oe/sdk.py | |||
| @@ -0,0 +1,209 @@ | |||
| 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 | os.symlink("/etc/ld.so.cache", link_name) | ||
| 56 | |||
| 57 | execute_pre_post_process(self.d, self.d.getVar('SDK_POSTPROCESS_COMMAND', True)) | ||
| 58 | |||
| 59 | |||
| 60 | class RpmSdk(Sdk): | ||
| 61 | pass | ||
| 62 | |||
| 63 | |||
| 64 | class OpkgSdk(Sdk): | ||
| 65 | def __init__(self, d, manifest_dir=None): | ||
| 66 | super(OpkgSdk, self).__init__(d, manifest_dir) | ||
| 67 | |||
| 68 | self.target_conf = self.d.getVar("IPKGCONF_TARGET", True) | ||
| 69 | self.host_conf = self.d.getVar("IPKGCONF_SDK", True) | ||
| 70 | |||
| 71 | self.target_manifest = OpkgManifest(d, self.manifest_dir, | ||
| 72 | Manifest.MANIFEST_TYPE_SDK_TARGET) | ||
| 73 | self.host_manifest = OpkgManifest(d, self.manifest_dir, | ||
| 74 | Manifest.MANIFEST_TYPE_SDK_HOST) | ||
| 75 | |||
| 76 | self.target_pm = OpkgPM(d, self.sdk_target_sysroot, self.target_conf, | ||
| 77 | self.d.getVar("ALL_MULTILIB_PACKAGE_ARCHS", True)) | ||
| 78 | |||
| 79 | self.host_pm = OpkgPM(d, self.sdk_host_sysroot, self.host_conf, | ||
| 80 | self.d.getVar("SDK_PACKAGE_ARCHS", True)) | ||
| 81 | |||
| 82 | def _populate_sysroot(self, pm, manifest): | ||
| 83 | pkgs_to_install = manifest.parse_initial_manifest() | ||
| 84 | |||
| 85 | pm.write_index() | ||
| 86 | pm.update() | ||
| 87 | |||
| 88 | for pkg_type in self.install_order: | ||
| 89 | if pkg_type in pkgs_to_install: | ||
| 90 | pm.install(pkgs_to_install[pkg_type], | ||
| 91 | [False, True][pkg_type == Manifest.PKG_TYPE_ATTEMPT_ONLY]) | ||
| 92 | |||
| 93 | def _populate(self): | ||
| 94 | bb.note("Installing TARGET packages") | ||
| 95 | self._populate_sysroot(self.target_pm, self.target_manifest) | ||
| 96 | |||
| 97 | self.target_pm.install_complementary(self.d.getVar('SDKIMAGE_INSTALL_COMPLEMENTARY', True)) | ||
| 98 | |||
| 99 | execute_pre_post_process(self.d, self.d.getVar("POPULATE_SDK_POST_TARGET_COMMAND", True)) | ||
| 100 | |||
| 101 | bb.note("Installing NATIVESDK packages") | ||
| 102 | self._populate_sysroot(self.host_pm, self.host_manifest) | ||
| 103 | |||
| 104 | execute_pre_post_process(self.d, self.d.getVar("POPULATE_SDK_POST_HOST_COMMAND", True)) | ||
| 105 | |||
| 106 | target_sysconfdir = os.path.join(self.sdk_target_sysroot, self.sysconfdir) | ||
| 107 | host_sysconfdir = os.path.join(self.sdk_host_sysroot, self.sysconfdir) | ||
| 108 | |||
| 109 | bb.utils.mkdirhier(target_sysconfdir) | ||
| 110 | shutil.copy(self.target_conf, target_sysconfdir) | ||
| 111 | os.chmod(os.path.join(target_sysconfdir, | ||
| 112 | os.path.basename(self.target_conf)), 0644) | ||
| 113 | |||
| 114 | bb.utils.mkdirhier(host_sysconfdir) | ||
| 115 | shutil.copy(self.host_conf, host_sysconfdir) | ||
| 116 | os.chmod(os.path.join(host_sysconfdir, | ||
| 117 | os.path.basename(self.host_conf)), 0644) | ||
| 118 | |||
| 119 | native_opkg_state_dir = os.path.join(self.sdk_output, self.sdk_native_path, | ||
| 120 | self.d.getVar('localstatedir_nativesdk', True).strip('/'), | ||
| 121 | "lib", "opkg") | ||
| 122 | bb.utils.mkdirhier(native_opkg_state_dir) | ||
| 123 | for f in glob.glob(os.path.join(self.sdk_output, "var", "lib", "opkg", "*")): | ||
| 124 | bb.utils.movefile(f, native_opkg_state_dir) | ||
| 125 | |||
| 126 | bb.utils.remove(os.path.join(self.sdk_output, "var"), True) | ||
| 127 | |||
| 128 | |||
| 129 | class DpkgSdk(Sdk): | ||
| 130 | def __init__(self, d, manifest_dir=None): | ||
| 131 | super(DpkgSdk, self).__init__(d, manifest_dir) | ||
| 132 | |||
| 133 | self.target_conf_dir = os.path.join(self.d.getVar("APTCONF_TARGET", True), "apt") | ||
| 134 | self.host_conf_dir = os.path.join(self.d.getVar("APTCONF_TARGET", True), "apt-sdk") | ||
| 135 | |||
| 136 | self.target_manifest = DpkgManifest(d, self.manifest_dir, | ||
| 137 | Manifest.MANIFEST_TYPE_SDK_TARGET) | ||
| 138 | self.host_manifest = DpkgManifest(d, self.manifest_dir, | ||
| 139 | Manifest.MANIFEST_TYPE_SDK_HOST) | ||
| 140 | |||
| 141 | self.target_pm = DpkgPM(d, self.sdk_target_sysroot, | ||
| 142 | self.d.getVar("PACKAGE_ARCHS", True), | ||
| 143 | self.d.getVar("DPKG_ARCH", True), | ||
| 144 | self.target_conf_dir) | ||
| 145 | |||
| 146 | self.host_pm = DpkgPM(d, self.sdk_host_sysroot, | ||
| 147 | self.d.getVar("SDK_PACKAGE_ARCHS", True), | ||
| 148 | self.d.getVar("DEB_SDK_ARCH", True), | ||
| 149 | self.host_conf_dir) | ||
| 150 | |||
| 151 | def _copy_apt_dir_to(self, dst_dir): | ||
| 152 | staging_etcdir_native = self.d.getVar("STAGING_ETCDIR_NATIVE", True) | ||
| 153 | |||
| 154 | bb.utils.remove(dst_dir, True) | ||
| 155 | |||
| 156 | shutil.copytree(os.path.join(staging_etcdir_native, "apt"), dst_dir) | ||
| 157 | |||
| 158 | def _populate_sysroot(self, pm, manifest): | ||
| 159 | pkgs_to_install = manifest.parse_initial_manifest() | ||
| 160 | |||
| 161 | pm.write_index() | ||
| 162 | pm.update() | ||
| 163 | |||
| 164 | for pkg_type in self.install_order: | ||
| 165 | if pkg_type in pkgs_to_install: | ||
| 166 | pm.install(pkgs_to_install[pkg_type], | ||
| 167 | [False, True][pkg_type == Manifest.PKG_TYPE_ATTEMPT_ONLY]) | ||
| 168 | |||
| 169 | def _populate(self): | ||
| 170 | bb.note("Installing TARGET packages") | ||
| 171 | self._populate_sysroot(self.target_pm, self.target_manifest) | ||
| 172 | |||
| 173 | execute_pre_post_process(self.d, self.d.getVar("POPULATE_SDK_POST_TARGET_COMMAND", True)) | ||
| 174 | |||
| 175 | self._copy_apt_dir_to(os.path.join(self.sdk_target_sysroot, "etc", "apt")) | ||
| 176 | |||
| 177 | bb.note("Installing NATIVESDK packages") | ||
| 178 | self._populate_sysroot(self.host_pm, self.host_manifest) | ||
| 179 | |||
| 180 | execute_pre_post_process(self.d, self.d.getVar("POPULATE_SDK_POST_HOST_COMMAND", True)) | ||
| 181 | |||
| 182 | self._copy_apt_dir_to(os.path.join(self.sdk_output, self.sdk_native_path, | ||
| 183 | "etc", "apt")) | ||
| 184 | |||
| 185 | native_dpkg_state_dir = os.path.join(self.sdk_output, self.sdk_native_path, | ||
| 186 | "var", "lib", "dpkg") | ||
| 187 | bb.utils.mkdirhier(native_dpkg_state_dir) | ||
| 188 | for f in glob.glob(os.path.join(self.sdk_output, "var", "lib", "dpkg", "*")): | ||
| 189 | bb.utils.movefile(f, native_dpkg_state_dir) | ||
| 190 | |||
| 191 | bb.utils.remove(os.path.join(self.sdk_output, "var"), True) | ||
| 192 | |||
| 193 | |||
| 194 | def populate_sdk(d, manifest_dir=None): | ||
| 195 | env_bkp = os.environ.copy() | ||
| 196 | |||
| 197 | img_type = d.getVar('IMAGE_PKGTYPE', True) | ||
| 198 | if img_type == "rpm": | ||
| 199 | bb.fatal("RPM backend was not implemented yet...") | ||
| 200 | elif img_type == "ipk": | ||
| 201 | OpkgSdk(d, manifest_dir).populate() | ||
| 202 | elif img_type == "deb": | ||
| 203 | DpkgSdk(d, manifest_dir).populate() | ||
| 204 | |||
| 205 | os.environ.clear() | ||
| 206 | os.environ.update(env_bkp) | ||
| 207 | |||
| 208 | if __name__ == "__main__": | ||
| 209 | pass | ||
