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