diff options
Diffstat (limited to 'meta/lib/oe/sdk.py')
-rw-r--r-- | meta/lib/oe/sdk.py | 326 |
1 files changed, 326 insertions, 0 deletions
diff --git a/meta/lib/oe/sdk.py b/meta/lib/oe/sdk.py new file mode 100644 index 0000000000..c57a441941 --- /dev/null +++ b/meta/lib/oe/sdk.py | |||
@@ -0,0 +1,326 @@ | |||
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 | for pkg_type in self.install_order: | ||
111 | if pkg_type in pkgs_to_install: | ||
112 | pm.install(pkgs_to_install[pkg_type], | ||
113 | [False, True][pkg_type == Manifest.PKG_TYPE_ATTEMPT_ONLY]) | ||
114 | |||
115 | def _populate(self): | ||
116 | bb.note("Installing TARGET packages") | ||
117 | self._populate_sysroot(self.target_pm, self.target_manifest) | ||
118 | |||
119 | self.target_pm.install_complementary(self.d.getVar('SDKIMAGE_INSTALL_COMPLEMENTARY', True)) | ||
120 | |||
121 | execute_pre_post_process(self.d, self.d.getVar("POPULATE_SDK_POST_TARGET_COMMAND", True)) | ||
122 | |||
123 | self.target_pm.remove_packaging_data() | ||
124 | |||
125 | bb.note("Installing NATIVESDK packages") | ||
126 | self._populate_sysroot(self.host_pm, self.host_manifest) | ||
127 | |||
128 | execute_pre_post_process(self.d, self.d.getVar("POPULATE_SDK_POST_HOST_COMMAND", True)) | ||
129 | |||
130 | self.host_pm.remove_packaging_data() | ||
131 | |||
132 | # Move host RPM library data | ||
133 | native_rpm_state_dir = os.path.join(self.sdk_output, | ||
134 | self.sdk_native_path, | ||
135 | self.d.getVar('localstatedir_nativesdk', True).strip('/'), | ||
136 | "lib", | ||
137 | "rpm" | ||
138 | ) | ||
139 | bb.utils.mkdirhier(native_rpm_state_dir) | ||
140 | for f in glob.glob(os.path.join(self.sdk_output, | ||
141 | "var", | ||
142 | "lib", | ||
143 | "rpm", | ||
144 | "*")): | ||
145 | bb.utils.movefile(f, native_rpm_state_dir) | ||
146 | |||
147 | bb.utils.remove(os.path.join(self.sdk_output, "var"), True) | ||
148 | |||
149 | # Move host sysconfig data | ||
150 | native_sysconf_dir = os.path.join(self.sdk_output, | ||
151 | self.sdk_native_path, | ||
152 | self.d.getVar('sysconfdir', | ||
153 | True).strip('/'), | ||
154 | ) | ||
155 | bb.utils.mkdirhier(native_sysconf_dir) | ||
156 | for f in glob.glob(os.path.join(self.sdk_output, "etc", "*")): | ||
157 | bb.utils.movefile(f, native_sysconf_dir) | ||
158 | bb.utils.remove(os.path.join(self.sdk_output, "etc"), True) | ||
159 | |||
160 | |||
161 | class OpkgSdk(Sdk): | ||
162 | def __init__(self, d, manifest_dir=None): | ||
163 | super(OpkgSdk, self).__init__(d, manifest_dir) | ||
164 | |||
165 | self.target_conf = self.d.getVar("IPKGCONF_TARGET", True) | ||
166 | self.host_conf = self.d.getVar("IPKGCONF_SDK", True) | ||
167 | |||
168 | self.target_manifest = OpkgManifest(d, self.manifest_dir, | ||
169 | Manifest.MANIFEST_TYPE_SDK_TARGET) | ||
170 | self.host_manifest = OpkgManifest(d, self.manifest_dir, | ||
171 | Manifest.MANIFEST_TYPE_SDK_HOST) | ||
172 | |||
173 | self.target_pm = OpkgPM(d, self.sdk_target_sysroot, self.target_conf, | ||
174 | self.d.getVar("ALL_MULTILIB_PACKAGE_ARCHS", True)) | ||
175 | |||
176 | self.host_pm = OpkgPM(d, self.sdk_host_sysroot, self.host_conf, | ||
177 | self.d.getVar("SDK_PACKAGE_ARCHS", True)) | ||
178 | |||
179 | def _populate_sysroot(self, pm, manifest): | ||
180 | pkgs_to_install = manifest.parse_initial_manifest() | ||
181 | |||
182 | if (self.d.getVar('BUILD_IMAGES_FROM_FEEDS', True) or "") != "1": | ||
183 | pm.write_index() | ||
184 | |||
185 | pm.update() | ||
186 | |||
187 | for pkg_type in self.install_order: | ||
188 | if pkg_type in pkgs_to_install: | ||
189 | pm.install(pkgs_to_install[pkg_type], | ||
190 | [False, True][pkg_type == Manifest.PKG_TYPE_ATTEMPT_ONLY]) | ||
191 | |||
192 | def _populate(self): | ||
193 | bb.note("Installing TARGET packages") | ||
194 | self._populate_sysroot(self.target_pm, self.target_manifest) | ||
195 | |||
196 | self.target_pm.install_complementary(self.d.getVar('SDKIMAGE_INSTALL_COMPLEMENTARY', True)) | ||
197 | |||
198 | execute_pre_post_process(self.d, self.d.getVar("POPULATE_SDK_POST_TARGET_COMMAND", True)) | ||
199 | |||
200 | bb.note("Installing NATIVESDK packages") | ||
201 | self._populate_sysroot(self.host_pm, self.host_manifest) | ||
202 | |||
203 | execute_pre_post_process(self.d, self.d.getVar("POPULATE_SDK_POST_HOST_COMMAND", True)) | ||
204 | |||
205 | target_sysconfdir = os.path.join(self.sdk_target_sysroot, self.sysconfdir) | ||
206 | host_sysconfdir = os.path.join(self.sdk_host_sysroot, self.sysconfdir) | ||
207 | |||
208 | bb.utils.mkdirhier(target_sysconfdir) | ||
209 | shutil.copy(self.target_conf, target_sysconfdir) | ||
210 | os.chmod(os.path.join(target_sysconfdir, | ||
211 | os.path.basename(self.target_conf)), 0644) | ||
212 | |||
213 | bb.utils.mkdirhier(host_sysconfdir) | ||
214 | shutil.copy(self.host_conf, host_sysconfdir) | ||
215 | os.chmod(os.path.join(host_sysconfdir, | ||
216 | os.path.basename(self.host_conf)), 0644) | ||
217 | |||
218 | native_opkg_state_dir = os.path.join(self.sdk_output, self.sdk_native_path, | ||
219 | self.d.getVar('localstatedir_nativesdk', True).strip('/'), | ||
220 | "lib", "opkg") | ||
221 | bb.utils.mkdirhier(native_opkg_state_dir) | ||
222 | for f in glob.glob(os.path.join(self.sdk_output, "var", "lib", "opkg", "*")): | ||
223 | bb.utils.movefile(f, native_opkg_state_dir) | ||
224 | |||
225 | bb.utils.remove(os.path.join(self.sdk_output, "var"), True) | ||
226 | |||
227 | |||
228 | class DpkgSdk(Sdk): | ||
229 | def __init__(self, d, manifest_dir=None): | ||
230 | super(DpkgSdk, self).__init__(d, manifest_dir) | ||
231 | |||
232 | self.target_conf_dir = os.path.join(self.d.getVar("APTCONF_TARGET", True), "apt") | ||
233 | self.host_conf_dir = os.path.join(self.d.getVar("APTCONF_TARGET", True), "apt-sdk") | ||
234 | |||
235 | self.target_manifest = DpkgManifest(d, self.manifest_dir, | ||
236 | Manifest.MANIFEST_TYPE_SDK_TARGET) | ||
237 | self.host_manifest = DpkgManifest(d, self.manifest_dir, | ||
238 | Manifest.MANIFEST_TYPE_SDK_HOST) | ||
239 | |||
240 | self.target_pm = DpkgPM(d, self.sdk_target_sysroot, | ||
241 | self.d.getVar("PACKAGE_ARCHS", True), | ||
242 | self.d.getVar("DPKG_ARCH", True), | ||
243 | self.target_conf_dir) | ||
244 | |||
245 | self.host_pm = DpkgPM(d, self.sdk_host_sysroot, | ||
246 | self.d.getVar("SDK_PACKAGE_ARCHS", True), | ||
247 | self.d.getVar("DEB_SDK_ARCH", True), | ||
248 | self.host_conf_dir) | ||
249 | |||
250 | def _copy_apt_dir_to(self, dst_dir): | ||
251 | staging_etcdir_native = self.d.getVar("STAGING_ETCDIR_NATIVE", True) | ||
252 | |||
253 | bb.utils.remove(dst_dir, True) | ||
254 | |||
255 | shutil.copytree(os.path.join(staging_etcdir_native, "apt"), dst_dir) | ||
256 | |||
257 | def _populate_sysroot(self, pm, manifest): | ||
258 | pkgs_to_install = manifest.parse_initial_manifest() | ||
259 | |||
260 | pm.write_index() | ||
261 | pm.update() | ||
262 | |||
263 | for pkg_type in self.install_order: | ||
264 | if pkg_type in pkgs_to_install: | ||
265 | pm.install(pkgs_to_install[pkg_type], | ||
266 | [False, True][pkg_type == Manifest.PKG_TYPE_ATTEMPT_ONLY]) | ||
267 | |||
268 | def _populate(self): | ||
269 | bb.note("Installing TARGET packages") | ||
270 | self._populate_sysroot(self.target_pm, self.target_manifest) | ||
271 | |||
272 | execute_pre_post_process(self.d, self.d.getVar("POPULATE_SDK_POST_TARGET_COMMAND", True)) | ||
273 | |||
274 | self._copy_apt_dir_to(os.path.join(self.sdk_target_sysroot, "etc", "apt")) | ||
275 | |||
276 | bb.note("Installing NATIVESDK packages") | ||
277 | self._populate_sysroot(self.host_pm, self.host_manifest) | ||
278 | |||
279 | execute_pre_post_process(self.d, self.d.getVar("POPULATE_SDK_POST_HOST_COMMAND", True)) | ||
280 | |||
281 | self._copy_apt_dir_to(os.path.join(self.sdk_output, self.sdk_native_path, | ||
282 | "etc", "apt")) | ||
283 | |||
284 | native_dpkg_state_dir = os.path.join(self.sdk_output, self.sdk_native_path, | ||
285 | "var", "lib", "dpkg") | ||
286 | bb.utils.mkdirhier(native_dpkg_state_dir) | ||
287 | for f in glob.glob(os.path.join(self.sdk_output, "var", "lib", "dpkg", "*")): | ||
288 | bb.utils.movefile(f, native_dpkg_state_dir) | ||
289 | |||
290 | bb.utils.remove(os.path.join(self.sdk_output, "var"), True) | ||
291 | |||
292 | |||
293 | def sdk_list_installed_packages(d, target, format=None, rootfs_dir=None): | ||
294 | if rootfs_dir is None: | ||
295 | sdk_output = d.getVar('SDK_OUTPUT', True) | ||
296 | target_path = d.getVar('SDKTARGETSYSROOT', True).strip('/') | ||
297 | |||
298 | rootfs_dir = [sdk_output, os.path.join(sdk_output, target_path)][target is True] | ||
299 | |||
300 | img_type = d.getVar('IMAGE_PKGTYPE', True) | ||
301 | if img_type == "rpm": | ||
302 | arch_var = ["SDK_PACKAGE_ARCHS", None][target is True] | ||
303 | os_var = ["SDK_OS", None][target is True] | ||
304 | return RpmPkgsList(d, rootfs_dir, arch_var, os_var).list(format) | ||
305 | elif img_type == "ipk": | ||
306 | conf_file_var = ["IPKGCONF_SDK", "IPKGCONF_TARGET"][target is True] | ||
307 | return OpkgPkgsList(d, rootfs_dir, d.getVar(conf_file_var, True)).list(format) | ||
308 | elif img_type == "deb": | ||
309 | return DpkgPkgsList(d, rootfs_dir).list(format) | ||
310 | |||
311 | def populate_sdk(d, manifest_dir=None): | ||
312 | env_bkp = os.environ.copy() | ||
313 | |||
314 | img_type = d.getVar('IMAGE_PKGTYPE', True) | ||
315 | if img_type == "rpm": | ||
316 | RpmSdk(d, manifest_dir).populate() | ||
317 | elif img_type == "ipk": | ||
318 | OpkgSdk(d, manifest_dir).populate() | ||
319 | elif img_type == "deb": | ||
320 | DpkgSdk(d, manifest_dir).populate() | ||
321 | |||
322 | os.environ.clear() | ||
323 | os.environ.update(env_bkp) | ||
324 | |||
325 | if __name__ == "__main__": | ||
326 | pass | ||