blob: 8f3448336f67a5f5b8f240aff5af6efd05631cf8 [file] [log] [blame]
Brad Bishop37a0e4d2017-12-04 01:01:44 -05001UNINATIVE_LOADER ?= "${UNINATIVE_STAGING_DIR}-uninative/${BUILD_ARCH}-linux/lib/${@bb.utils.contains('BUILD_ARCH', 'x86_64', 'ld-linux-x86-64.so.2', 'ld-linux.so.2', d)}"
2UNINATIVE_STAGING_DIR ?= "${STAGING_DIR}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05004UNINATIVE_URL ?= "unset"
5UNINATIVE_TARBALL ?= "${BUILD_ARCH}-nativesdk-libc.tar.bz2"
6# Example checksums
7#UNINATIVE_CHECKSUM[i586] = "dead"
8#UNINATIVE_CHECKSUM[x86_64] = "dead"
9UNINATIVE_DLDIR ?= "${DL_DIR}/uninative/"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050011addhandler uninative_event_fetchloader
12uninative_event_fetchloader[eventmask] = "bb.event.BuildStarted"
13
14addhandler uninative_event_enable
15uninative_event_enable[eventmask] = "bb.event.ConfigParsed"
16
17python uninative_event_fetchloader() {
18 """
19 This event fires on the parent and will try to fetch the tarball if the
20 loader isn't already present.
21 """
22
Brad Bishop6e60e8b2018-02-01 10:27:11 -050023 chksum = d.getVarFlag("UNINATIVE_CHECKSUM", d.getVar("BUILD_ARCH"))
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050024 if not chksum:
Brad Bishop6e60e8b2018-02-01 10:27:11 -050025 bb.fatal("Uninative selected but not configured correctly, please set UNINATIVE_CHECKSUM[%s]" % d.getVar("BUILD_ARCH"))
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050026
Brad Bishop6e60e8b2018-02-01 10:27:11 -050027 loader = d.getVar("UNINATIVE_LOADER")
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050028 loaderchksum = loader + ".chksum"
29 if os.path.exists(loader) and os.path.exists(loaderchksum):
30 with open(loaderchksum, "r") as f:
31 readchksum = f.read().strip()
32 if readchksum == chksum:
33 return
34
35 import subprocess
36 try:
37 # Save and restore cwd as Fetch.download() does a chdir()
38 olddir = os.getcwd()
39
Brad Bishop6e60e8b2018-02-01 10:27:11 -050040 tarball = d.getVar("UNINATIVE_TARBALL")
41 tarballdir = os.path.join(d.getVar("UNINATIVE_DLDIR"), chksum)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050042 tarballpath = os.path.join(tarballdir, tarball)
43
44 if not os.path.exists(tarballpath):
45 bb.utils.mkdirhier(tarballdir)
Brad Bishop6e60e8b2018-02-01 10:27:11 -050046 if d.getVar("UNINATIVE_URL") == "unset":
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050047 bb.fatal("Uninative selected but not configured, please set UNINATIVE_URL")
48
49 localdata = bb.data.createCopy(d)
50 localdata.setVar('FILESPATH', "")
51 localdata.setVar('DL_DIR', tarballdir)
52
53 srcuri = d.expand("${UNINATIVE_URL}${UNINATIVE_TARBALL};sha256sum=%s" % chksum)
54 bb.note("Fetching uninative binary shim from %s" % srcuri)
55
56 fetcher = bb.fetch2.Fetch([srcuri], localdata, cache=False)
57 fetcher.download()
58 localpath = fetcher.localpath(srcuri)
59 if localpath != tarballpath and os.path.exists(localpath) and not os.path.exists(tarballpath):
60 os.symlink(localpath, tarballpath)
61
Brad Bishop6e60e8b2018-02-01 10:27:11 -050062 cmd = d.expand("\
63mkdir -p ${UNINATIVE_STAGING_DIR}-uninative; \
64cd ${UNINATIVE_STAGING_DIR}-uninative; \
65tar -xjf ${UNINATIVE_DLDIR}/%s/${UNINATIVE_TARBALL}; \
66${UNINATIVE_STAGING_DIR}-uninative/relocate_sdk.py \
67 ${UNINATIVE_STAGING_DIR}-uninative/${BUILD_ARCH}-linux \
68 ${UNINATIVE_LOADER} \
69 ${UNINATIVE_LOADER} \
70 ${UNINATIVE_STAGING_DIR}-uninative/${BUILD_ARCH}-linux/${bindir_native}/patchelf-uninative \
71 ${UNINATIVE_STAGING_DIR}-uninative/${BUILD_ARCH}-linux${base_libdir_native}/libc*.so" % chksum)
72 subprocess.check_output(cmd, shell=True)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050073
74 with open(loaderchksum, "w") as f:
75 f.write(chksum)
76
77 enable_uninative(d)
78
79 except bb.fetch2.BBFetchException as exc:
80 bb.warn("Disabling uninative as unable to fetch uninative tarball: %s" % str(exc))
81 bb.warn("To build your own uninative loader, please bitbake uninative-tarball and set UNINATIVE_TARBALL appropriately.")
82 except subprocess.CalledProcessError as exc:
83 bb.warn("Disabling uninative as unable to install uninative tarball: %s" % str(exc))
84 bb.warn("To build your own uninative loader, please bitbake uninative-tarball and set UNINATIVE_TARBALL appropriately.")
85 finally:
86 os.chdir(olddir)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050087}
88
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050089python uninative_event_enable() {
90 """
91 This event handler is called in the workers and is responsible for setting
92 up uninative if a loader is found.
93 """
94 enable_uninative(d)
95}
96
97def enable_uninative(d):
Brad Bishop6e60e8b2018-02-01 10:27:11 -050098 loader = d.getVar("UNINATIVE_LOADER")
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050099 if os.path.exists(loader):
100 bb.debug(2, "Enabling uninative")
Brad Bishop37a0e4d2017-12-04 01:01:44 -0500101 d.setVar("NATIVELSBSTRING", "universal%s" % oe.utils.host_gcc_version(d))
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500102 d.appendVar("SSTATEPOSTUNPACKFUNCS", " uninative_changeinterp")
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500103 d.appendVarFlag("SSTATEPOSTUNPACKFUNCS", "vardepvalueexclude", "| uninative_changeinterp")
104 d.prependVar("PATH", "${STAGING_DIR}-uninative/${BUILD_ARCH}-linux${bindir_native}:")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500105
106python uninative_changeinterp () {
107 import subprocess
108 import stat
109 import oe.qa
110
111 if not (bb.data.inherits_class('native', d) or bb.data.inherits_class('crosssdk', d) or bb.data.inherits_class('cross', d)):
112 return
113
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500114 sstateinst = d.getVar('SSTATE_INSTDIR')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500115 for walkroot, dirs, files in os.walk(sstateinst):
116 for file in files:
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500117 if file.endswith(".so") or ".so." in file:
118 continue
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500119 f = os.path.join(walkroot, file)
120 if os.path.islink(f):
121 continue
122 s = os.stat(f)
123 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)):
124 continue
125 elf = oe.qa.ELFFile(f)
126 try:
127 elf.open()
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500128 except oe.qa.NotELFFileError:
129 continue
130 if not elf.isDynamic():
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500131 continue
132
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500133 subprocess.check_output(("patchelf-uninative", "--set-interpreter", d.getVar("UNINATIVE_LOADER"), f), stderr=subprocess.STDOUT)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500134}