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 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame^] | 23 | chksum = d.getVarFlag("UNINATIVE_CHECKSUM", d.getVar("BUILD_ARCH")) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 24 | if not chksum: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame^] | 25 | bb.fatal("Uninative selected but not configured correctly, please set UNINATIVE_CHECKSUM[%s]" % d.getVar("BUILD_ARCH")) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 26 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame^] | 27 | loader = d.getVar("UNINATIVE_LOADER") |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 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 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame^] | 40 | tarball = d.getVar("UNINATIVE_TARBALL") |
| 41 | tarballdir = os.path.join(d.getVar("UNINATIVE_DLDIR"), chksum) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 42 | tarballpath = os.path.join(tarballdir, tarball) |
| 43 | |
| 44 | if not os.path.exists(tarballpath): |
| 45 | bb.utils.mkdirhier(tarballdir) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame^] | 46 | if d.getVar("UNINATIVE_URL") == "unset": |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 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 | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame^] | 62 | cmd = d.expand("\ |
| 63 | mkdir -p ${UNINATIVE_STAGING_DIR}-uninative; \ |
| 64 | cd ${UNINATIVE_STAGING_DIR}-uninative; \ |
| 65 | tar -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 Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 73 | |
| 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 Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 87 | } |
| 88 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 89 | python 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 | |
| 97 | def enable_uninative(d): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame^] | 98 | loader = d.getVar("UNINATIVE_LOADER") |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 99 | if os.path.exists(loader): |
| 100 | bb.debug(2, "Enabling uninative") |
Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 101 | d.setVar("NATIVELSBSTRING", "universal%s" % oe.utils.host_gcc_version(d)) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 102 | d.appendVar("SSTATEPOSTUNPACKFUNCS", " uninative_changeinterp") |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame^] | 103 | d.appendVarFlag("SSTATEPOSTUNPACKFUNCS", "vardepvalueexclude", "| uninative_changeinterp") |
| 104 | d.prependVar("PATH", "${STAGING_DIR}-uninative/${BUILD_ARCH}-linux${bindir_native}:") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 105 | |
| 106 | python 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 Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame^] | 114 | sstateinst = d.getVar('SSTATE_INSTDIR') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 115 | for walkroot, dirs, files in os.walk(sstateinst): |
| 116 | for file in files: |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 117 | if file.endswith(".so") or ".so." in file: |
| 118 | continue |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 119 | 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 Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 128 | except oe.qa.NotELFFileError: |
| 129 | continue |
| 130 | if not elf.isDynamic(): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 131 | continue |
| 132 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame^] | 133 | subprocess.check_output(("patchelf-uninative", "--set-interpreter", d.getVar("UNINATIVE_LOADER"), f), stderr=subprocess.STDOUT) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 134 | } |