Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 1 | UNINATIVE_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)}" |
| 2 | UNINATIVE_STAGING_DIR ?= "${STAGING_DIR}" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 3 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 4 | UNINATIVE_URL ?= "unset" |
| 5 | UNINATIVE_TARBALL ?= "${BUILD_ARCH}-nativesdk-libc.tar.bz2" |
| 6 | # Example checksums |
| 7 | #UNINATIVE_CHECKSUM[i586] = "dead" |
| 8 | #UNINATIVE_CHECKSUM[x86_64] = "dead" |
| 9 | UNINATIVE_DLDIR ?= "${DL_DIR}/uninative/" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 10 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 11 | addhandler uninative_event_fetchloader |
| 12 | uninative_event_fetchloader[eventmask] = "bb.event.BuildStarted" |
| 13 | |
| 14 | addhandler uninative_event_enable |
| 15 | uninative_event_enable[eventmask] = "bb.event.ConfigParsed" |
| 16 | |
| 17 | python 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 | |
| 23 | chksum = d.getVarFlag("UNINATIVE_CHECKSUM", d.getVar("BUILD_ARCH", True), True) |
| 24 | if not chksum: |
| 25 | bb.fatal("Uninative selected but not configured correctly, please set UNINATIVE_CHECKSUM[%s]" % d.getVar("BUILD_ARCH", True)) |
| 26 | |
| 27 | loader = d.getVar("UNINATIVE_LOADER", True) |
| 28 | 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 | |
| 40 | tarball = d.getVar("UNINATIVE_TARBALL", True) |
| 41 | tarballdir = os.path.join(d.getVar("UNINATIVE_DLDIR", True), chksum) |
| 42 | tarballpath = os.path.join(tarballdir, tarball) |
| 43 | |
| 44 | if not os.path.exists(tarballpath): |
| 45 | bb.utils.mkdirhier(tarballdir) |
| 46 | if d.getVar("UNINATIVE_URL", True) == "unset": |
| 47 | 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 Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 62 | cmd = d.expand("mkdir -p ${UNINATIVE_STAGING_DIR}-uninative; cd ${UNINATIVE_STAGING_DIR}-uninative; tar -xjf ${UNINATIVE_DLDIR}/%s/${UNINATIVE_TARBALL}; ${UNINATIVE_STAGING_DIR}-uninative/relocate_sdk.py ${UNINATIVE_STAGING_DIR}-uninative/${BUILD_ARCH}-linux ${UNINATIVE_LOADER} ${UNINATIVE_LOADER} ${UNINATIVE_STAGING_DIR}-uninative/${BUILD_ARCH}-linux/${bindir_native}/patchelf-uninative ${UNINATIVE_STAGING_DIR}-uninative/${BUILD_ARCH}-linux${base_libdir_native}/libc*.so" % chksum) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 63 | subprocess.check_call(cmd, shell=True) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 64 | |
| 65 | with open(loaderchksum, "w") as f: |
| 66 | f.write(chksum) |
| 67 | |
| 68 | enable_uninative(d) |
| 69 | |
| 70 | except bb.fetch2.BBFetchException as exc: |
| 71 | bb.warn("Disabling uninative as unable to fetch uninative tarball: %s" % str(exc)) |
| 72 | bb.warn("To build your own uninative loader, please bitbake uninative-tarball and set UNINATIVE_TARBALL appropriately.") |
| 73 | except subprocess.CalledProcessError as exc: |
| 74 | bb.warn("Disabling uninative as unable to install uninative tarball: %s" % str(exc)) |
| 75 | bb.warn("To build your own uninative loader, please bitbake uninative-tarball and set UNINATIVE_TARBALL appropriately.") |
| 76 | finally: |
| 77 | os.chdir(olddir) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 78 | } |
| 79 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 80 | python uninative_event_enable() { |
| 81 | """ |
| 82 | This event handler is called in the workers and is responsible for setting |
| 83 | up uninative if a loader is found. |
| 84 | """ |
| 85 | enable_uninative(d) |
| 86 | } |
| 87 | |
| 88 | def enable_uninative(d): |
| 89 | loader = d.getVar("UNINATIVE_LOADER", True) |
| 90 | if os.path.exists(loader): |
| 91 | bb.debug(2, "Enabling uninative") |
Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 92 | d.setVar("NATIVELSBSTRING", "universal%s" % oe.utils.host_gcc_version(d)) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 93 | d.appendVar("SSTATEPOSTUNPACKFUNCS", " uninative_changeinterp") |
Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 94 | d.prependVar("PATH", "${UNINATIVE_STAGING_DIR}-uninative/${BUILD_ARCH}-linux${bindir_native}:") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 95 | |
| 96 | python uninative_changeinterp () { |
| 97 | import subprocess |
| 98 | import stat |
| 99 | import oe.qa |
| 100 | |
| 101 | if not (bb.data.inherits_class('native', d) or bb.data.inherits_class('crosssdk', d) or bb.data.inherits_class('cross', d)): |
| 102 | return |
| 103 | |
| 104 | sstateinst = d.getVar('SSTATE_INSTDIR', True) |
| 105 | for walkroot, dirs, files in os.walk(sstateinst): |
| 106 | for file in files: |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 107 | if file.endswith(".so") or ".so." in file: |
| 108 | continue |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 109 | f = os.path.join(walkroot, file) |
| 110 | if os.path.islink(f): |
| 111 | continue |
| 112 | s = os.stat(f) |
| 113 | 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)): |
| 114 | continue |
| 115 | elf = oe.qa.ELFFile(f) |
| 116 | try: |
| 117 | elf.open() |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 118 | except oe.qa.NotELFFileError: |
| 119 | continue |
| 120 | if not elf.isDynamic(): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 121 | continue |
| 122 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 123 | try: |
| 124 | subprocess.check_output(("patchelf-uninative", "--set-interpreter", |
| 125 | d.getVar("UNINATIVE_LOADER", True), f), |
| 126 | stderr=subprocess.STDOUT) |
| 127 | except subprocess.CalledProcessError as e: |
| 128 | bb.fatal("'%s' failed with exit code %d and the following output:\n%s" % |
| 129 | (e.cmd, e.returncode, e.output)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 130 | } |