diff options
author | Richard Purdie <richard.purdie@linuxfoundation.org> | 2014-08-28 10:10:06 +0000 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2014-09-23 20:31:18 +0100 |
commit | 2cbab459e471abbddba8badc64805e7226e864be (patch) | |
tree | 1005e79daebb1f6cba2ef6258da00995e2572263 /meta | |
parent | a94574f189a2840ddb9cf78c050384d4c833d291 (diff) | |
download | poky-2cbab459e471abbddba8badc64805e7226e864be.tar.gz |
uninative: Add uninative - a way of reusing native/cross over multiple distros
These patches are the start of a new idea, a way of allowing a single set of
cross/native sstate to work over mutliple distros, even old ones.
The assumption is that our own C library is basically up to date. We build
and share a small tarball (~2MB) of a prebuilt copy of this along with a
patchelf binary (which sadly is C++ based so libstdc++ is in there). This
tarball can be generated from our usual SDK generation process through
the supplied recipe, uninative-tarball.
At the start of the build, if its not been extracted into the sysroot, this
tarball is extracted there and configured for the specified path.
When we install binaries from a "uninative" sstate feed, we change the
dynamic loader to point at this dynamic loader and C librbary. This works
exactly the same way as our relocatable SDK does. The only real difference
is a switch to use patchelf, so even if the interpreter section is too small,
it can still adjust the binary.
Right now this implements a working proof of concept. If you build the tarball
and place it at the head of the tree (in COREBASE), you can run a build from
sstate and successfully build packages and construct images.
There is some improvement needed, its hardcoded for x86_64 right now, its trivial
to add 32 bit support too. The tarball isn't fetched right now, there is just a
harcoded path assumption and there is no error handling. I haven't figured
out the best delivery mechanism for that yet. BuildStarted is probably not
the right event to hook on either.
I've merged this to illustrate how with a small change, we might make the
native/cross sstate much more reusable and hence improve the accessibility
of lower overhead builds. With this change, its possible the Yocto Project may
be able to support a configured sstate mirror out the box. This also has
positive implications for our developer workflow/SDK improvements.
(From OE-Core rev: e66c96ae9c7ba21ebd04a4807390f0031238a85a)
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta')
-rw-r--r-- | meta/classes/uninative.bbclass | 44 | ||||
-rw-r--r-- | meta/recipes-core/meta/uninative-tarball.bb | 48 |
2 files changed, 92 insertions, 0 deletions
diff --git a/meta/classes/uninative.bbclass b/meta/classes/uninative.bbclass new file mode 100644 index 0000000000..51391dbc4a --- /dev/null +++ b/meta/classes/uninative.bbclass | |||
@@ -0,0 +1,44 @@ | |||
1 | NATIVELSBSTRING = "universal" | ||
2 | |||
3 | UNINATIVE_LOADER = "${STAGING_DIR_NATIVE}/lib/ld-linux-x86-64.so.2" | ||
4 | |||
5 | addhandler uninative_eventhandler | ||
6 | uninative_eventhandler[eventmask] = "bb.event.BuildStarted" | ||
7 | |||
8 | python uninative_eventhandler() { | ||
9 | loader = e.data.getVar("UNINATIVE_LOADER", True) | ||
10 | if not os.path.exists(loader): | ||
11 | import subprocess | ||
12 | cmd = e.data.expand("mkdir -p ${STAGING_DIR}; cd ${STAGING_DIR}; tar -xjf ${COREBASE}/${BUILD_ARCH}-nativesdk-libc.tar.bz2; ${STAGING_DIR}/relocate_sdk.py ${STAGING_DIR_NATIVE} ${UNINATIVE_LOADER} ${UNINATIVE_LOADER} ${STAGING_BINDIR_NATIVE}/patchelf-uninative") | ||
13 | #bb.warn("nativesdk lib extraction: " + cmd) | ||
14 | subprocess.check_call(cmd, shell=True) | ||
15 | } | ||
16 | |||
17 | SSTATEPOSTUNPACKFUNCS_append = " uninative_changeinterp" | ||
18 | |||
19 | python uninative_changeinterp () { | ||
20 | import subprocess | ||
21 | import stat | ||
22 | import oe.qa | ||
23 | |||
24 | if not (bb.data.inherits_class('native', d) or bb.data.inherits_class('crosssdk', d) or bb.data.inherits_class('cross', d)): | ||
25 | return | ||
26 | |||
27 | sstateinst = d.getVar('SSTATE_INSTDIR', True) | ||
28 | for walkroot, dirs, files in os.walk(sstateinst): | ||
29 | for file in files: | ||
30 | f = os.path.join(walkroot, file) | ||
31 | if os.path.islink(f): | ||
32 | continue | ||
33 | s = os.stat(f) | ||
34 | if not ((s[stat.ST_MODE] & stat.S_IXUSR) or (s[stat.ST_MODE] & stat.S_IXGRP) or (s[stat.ST_MODE] & stat.S_IXOTH)): | ||
35 | continue | ||
36 | elf = oe.qa.ELFFile(f) | ||
37 | try: | ||
38 | elf.open() | ||
39 | except: | ||
40 | continue | ||
41 | |||
42 | #bb.warn("patchelf-uninative --set-interpreter %s %s" % (d.getVar("UNINATIVE_LOADER", True), f)) | ||
43 | subprocess.call("patchelf-uninative --set-interpreter %s %s" % (d.getVar("UNINATIVE_LOADER", True), f), shell=True) | ||
44 | } | ||
diff --git a/meta/recipes-core/meta/uninative-tarball.bb b/meta/recipes-core/meta/uninative-tarball.bb new file mode 100644 index 0000000000..ed1279f09b --- /dev/null +++ b/meta/recipes-core/meta/uninative-tarball.bb | |||
@@ -0,0 +1,48 @@ | |||
1 | SUMMARY = "libc and patchelf tarball for use with uninative.bbclass" | ||
2 | LICENSE = "MIT" | ||
3 | LIC_FILES_CHKSUM = "file://${COREBASE}/LICENSE;md5=4d92cd373abda3937c2bc47fbc49d690 \ | ||
4 | file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420" | ||
5 | |||
6 | TOOLCHAIN_TARGET_TASK = "" | ||
7 | |||
8 | TOOLCHAIN_HOST_TASK = "\ | ||
9 | nativesdk-eglibc \ | ||
10 | nativesdk-patchelf \ | ||
11 | " | ||
12 | |||
13 | INHIBIT_DEFAULT_DEPS = "1" | ||
14 | DEPENDS += "patchelf-native" | ||
15 | |||
16 | TOOLCHAIN_OUTPUTNAME ?= "${BUILD_ARCH}-nativesdk-libc" | ||
17 | |||
18 | RDEPENDS = "${TOOLCHAIN_HOST_TASK}" | ||
19 | |||
20 | EXCLUDE_FROM_WORLD = "1" | ||
21 | |||
22 | inherit meta | ||
23 | inherit populate_sdk | ||
24 | |||
25 | deltask install | ||
26 | deltask package | ||
27 | |||
28 | SDK_PACKAGING_FUNC = "" | ||
29 | |||
30 | fakeroot create_sdk_files() { | ||
31 | cp ${COREBASE}/scripts/relocate_sdk.py ${SDK_OUTPUT}/${SDKPATH}/ | ||
32 | |||
33 | # Replace the ##DEFAULT_INSTALL_DIR## with the correct pattern. | ||
34 | # Escape special characters like '+' and '.' in the SDKPATH | ||
35 | escaped_sdkpath=$(echo ${SDKPATH}/sysroots/${SDK_SYS} |sed -e "s:[\+\.]:\\\\\\\\\0:g") | ||
36 | sed -i -e "s:##DEFAULT_INSTALL_DIR##:$escaped_sdkpath:" ${SDK_OUTPUT}/${SDKPATH}/relocate_sdk.py | ||
37 | } | ||
38 | |||
39 | |||
40 | fakeroot tar_sdk() { | ||
41 | mkdir -p ${SDK_DEPLOY} | ||
42 | cd ${SDK_OUTPUT}/${SDKPATH} | ||
43 | mv sysroots/${SDK_SYS} ./${BUILD_SYS} | ||
44 | rm sysroots -rf | ||
45 | patchelf --set-interpreter ${@''.join('a' for n in xrange(1024))} ./${BUILD_SYS}/usr/bin/patchelf | ||
46 | mv ./${BUILD_SYS}/usr/bin/patchelf ./${BUILD_SYS}/usr/bin/patchelf-uninative | ||
47 | tar ${SDKTAROPTS} -c --file=${SDK_DEPLOY}/${TOOLCHAIN_OUTPUTNAME}.tar.bz2 . | ||
48 | } | ||