diff options
Diffstat (limited to 'meta/classes-global/uninative.bbclass')
| -rw-r--r-- | meta/classes-global/uninative.bbclass | 183 |
1 files changed, 0 insertions, 183 deletions
diff --git a/meta/classes-global/uninative.bbclass b/meta/classes-global/uninative.bbclass deleted file mode 100644 index c246a1ecd6..0000000000 --- a/meta/classes-global/uninative.bbclass +++ /dev/null | |||
| @@ -1,183 +0,0 @@ | |||
| 1 | # | ||
| 2 | # Copyright OpenEmbedded Contributors | ||
| 3 | # | ||
| 4 | # SPDX-License-Identifier: MIT | ||
| 5 | # | ||
| 6 | |||
| 7 | UNINATIVE_LOADER ?= "${UNINATIVE_STAGING_DIR}-uninative/${BUILD_ARCH}-linux/lib/${@bb.utils.contains('BUILD_ARCH', 'x86_64', 'ld-linux-x86-64.so.2', '', d)}${@bb.utils.contains('BUILD_ARCH', 'i686', 'ld-linux.so.2', '', d)}${@bb.utils.contains('BUILD_ARCH', 'aarch64', 'ld-linux-aarch64.so.1', '', d)}${@bb.utils.contains('BUILD_ARCH', 'ppc64le', 'ld64.so.2', '', d)}${@bb.utils.contains('BUILD_ARCH', 'riscv64', 'ld-linux-riscv64-lp64d.so.1', '', d)}" | ||
| 8 | UNINATIVE_STAGING_DIR ?= "${STAGING_DIR}" | ||
| 9 | |||
| 10 | UNINATIVE_URL ?= "unset" | ||
| 11 | UNINATIVE_TARBALL ?= "${BUILD_ARCH}-nativesdk-libc-${UNINATIVE_VERSION}.tar.xz" | ||
| 12 | # Example checksums | ||
| 13 | #UNINATIVE_CHECKSUM[aarch64] = "dead" | ||
| 14 | #UNINATIVE_CHECKSUM[i686] = "dead" | ||
| 15 | #UNINATIVE_CHECKSUM[x86_64] = "dead" | ||
| 16 | UNINATIVE_DLDIR ?= "${DL_DIR}/uninative/" | ||
| 17 | |||
| 18 | # Enabling uninative will change the following variables so they need to go the parsing ignored variables list to prevent multiple recipe parsing | ||
| 19 | BB_HASHCONFIG_IGNORE_VARS += "NATIVELSBSTRING SSTATEPOSTUNPACKFUNCS BUILD_LDFLAGS" | ||
| 20 | |||
| 21 | addhandler uninative_event_fetchloader | ||
| 22 | uninative_event_fetchloader[eventmask] = "bb.event.BuildStarted" | ||
| 23 | |||
| 24 | addhandler uninative_event_enable | ||
| 25 | uninative_event_enable[eventmask] = "bb.event.ConfigParsed" | ||
| 26 | |||
| 27 | python uninative_event_fetchloader() { | ||
| 28 | """ | ||
| 29 | This event fires on the parent and will try to fetch the tarball if the | ||
| 30 | loader isn't already present. | ||
| 31 | """ | ||
| 32 | |||
| 33 | chksum = d.getVarFlag("UNINATIVE_CHECKSUM", d.getVar("BUILD_ARCH")) | ||
| 34 | if not chksum: | ||
| 35 | bb.fatal("Uninative selected but not configured correctly, please set UNINATIVE_CHECKSUM[%s]" % d.getVar("BUILD_ARCH")) | ||
| 36 | |||
| 37 | loader = d.getVar("UNINATIVE_LOADER") | ||
| 38 | loaderchksum = loader + ".chksum" | ||
| 39 | if os.path.exists(loader) and os.path.exists(loaderchksum): | ||
| 40 | with open(loaderchksum, "r") as f: | ||
| 41 | readchksum = f.read().strip() | ||
| 42 | if readchksum == chksum: | ||
| 43 | if "uninative" not in d.getVar("SSTATEPOSTUNPACKFUNCS"): | ||
| 44 | enable_uninative(d) | ||
| 45 | return | ||
| 46 | |||
| 47 | import subprocess | ||
| 48 | try: | ||
| 49 | # Save and restore cwd as Fetch.download() does a chdir() | ||
| 50 | olddir = os.getcwd() | ||
| 51 | |||
| 52 | tarball = d.getVar("UNINATIVE_TARBALL") | ||
| 53 | tarballdir = os.path.join(d.getVar("UNINATIVE_DLDIR"), chksum) | ||
| 54 | tarballpath = os.path.join(tarballdir, tarball) | ||
| 55 | |||
| 56 | if not os.path.exists(tarballpath + ".done"): | ||
| 57 | bb.utils.mkdirhier(tarballdir) | ||
| 58 | if d.getVar("UNINATIVE_URL") == "unset": | ||
| 59 | bb.fatal("Uninative selected but not configured, please set UNINATIVE_URL") | ||
| 60 | |||
| 61 | localdata = bb.data.createCopy(d) | ||
| 62 | localdata.setVar('FILESPATH', "") | ||
| 63 | localdata.setVar('DL_DIR', tarballdir) | ||
| 64 | # Our games with path manipulation of DL_DIR mean standard PREMIRRORS don't work | ||
| 65 | # and we can't easily put 'chksum' into the url path from a url parameter with | ||
| 66 | # the current fetcher url handling | ||
| 67 | premirrors = bb.fetch2.mirror_from_string(localdata.getVar("PREMIRRORS")) | ||
| 68 | for line in premirrors: | ||
| 69 | try: | ||
| 70 | (find, replace) = line | ||
| 71 | except ValueError: | ||
| 72 | continue | ||
| 73 | if find.startswith("http"): | ||
| 74 | localdata.appendVar("PREMIRRORS", " ${UNINATIVE_URL}${UNINATIVE_TARBALL} %s/uninative/%s/${UNINATIVE_TARBALL}" % (replace, chksum)) | ||
| 75 | |||
| 76 | srcuri = d.expand("${UNINATIVE_URL}${UNINATIVE_TARBALL};sha256sum=%s" % chksum) | ||
| 77 | bb.note("Fetching uninative binary shim %s (will check PREMIRRORS first)" % srcuri) | ||
| 78 | |||
| 79 | fetcher = bb.fetch2.Fetch([srcuri], localdata, cache=False) | ||
| 80 | fetcher.download() | ||
| 81 | localpath = fetcher.localpath(srcuri) | ||
| 82 | if localpath != tarballpath and os.path.exists(localpath) and not os.path.exists(tarballpath): | ||
| 83 | # Follow the symlink behavior from the bitbake fetch2. | ||
| 84 | # This will cover the case where an existing symlink is broken | ||
| 85 | # as well as if there are two processes trying to create it | ||
| 86 | # at the same time. | ||
| 87 | if os.path.islink(tarballpath): | ||
| 88 | # Broken symbolic link | ||
| 89 | os.unlink(tarballpath) | ||
| 90 | |||
| 91 | # Deal with two processes trying to make symlink at once | ||
| 92 | try: | ||
| 93 | os.symlink(localpath, tarballpath) | ||
| 94 | except FileExistsError: | ||
| 95 | pass | ||
| 96 | |||
| 97 | # ldd output is "ldd (Ubuntu GLIBC 2.23-0ubuntu10) 2.23", extract last option from first line | ||
| 98 | glibcver = subprocess.check_output(["ldd", "--version"]).decode('utf-8').split('\n')[0].split()[-1] | ||
| 99 | if bb.utils.vercmp_string(d.getVar("UNINATIVE_MAXGLIBCVERSION"), glibcver) < 0: | ||
| 100 | raise RuntimeError("Your host glibc version (%s) is newer than that in uninative (%s). Disabling uninative so that sstate is not corrupted." % (glibcver, d.getVar("UNINATIVE_MAXGLIBCVERSION"))) | ||
| 101 | |||
| 102 | cmd = d.expand("\ | ||
| 103 | mkdir -p ${UNINATIVE_STAGING_DIR}-uninative; \ | ||
| 104 | cd ${UNINATIVE_STAGING_DIR}-uninative; \ | ||
| 105 | tar -xJf ${UNINATIVE_DLDIR}/%s/${UNINATIVE_TARBALL}; \ | ||
| 106 | ${UNINATIVE_STAGING_DIR}-uninative/relocate_sdk.py \ | ||
| 107 | ${UNINATIVE_STAGING_DIR}-uninative/${BUILD_ARCH}-linux \ | ||
| 108 | ${UNINATIVE_LOADER} \ | ||
| 109 | ${UNINATIVE_LOADER} \ | ||
| 110 | ${UNINATIVE_STAGING_DIR}-uninative/${BUILD_ARCH}-linux/${bindir_native}/patchelf-uninative \ | ||
| 111 | ${UNINATIVE_STAGING_DIR}-uninative/${BUILD_ARCH}-linux${base_libdir_native}/libc*.so*" % chksum) | ||
| 112 | subprocess.check_output(cmd, shell=True, text=True, stderr=subprocess.STDOUT) | ||
| 113 | |||
| 114 | with open(loaderchksum, "w") as f: | ||
| 115 | f.write(chksum) | ||
| 116 | |||
| 117 | enable_uninative(d) | ||
| 118 | |||
| 119 | except RuntimeError as e: | ||
| 120 | bb.warn(str(e)) | ||
| 121 | except bb.fetch2.BBFetchException as exc: | ||
| 122 | bb.warn("Disabling uninative as unable to fetch uninative tarball: %s" % str(exc)) | ||
| 123 | bb.warn("To build your own uninative loader, please bitbake uninative-tarball and set UNINATIVE_TARBALL appropriately.") | ||
| 124 | except subprocess.CalledProcessError as exc: | ||
| 125 | bb.warn("Disabling uninative as unable to install uninative tarball:") | ||
| 126 | bb.warn(str(exc)) | ||
| 127 | bb.warn(exc.stdout) | ||
| 128 | bb.warn("To build your own uninative loader, please bitbake uninative-tarball and set UNINATIVE_TARBALL appropriately.") | ||
| 129 | finally: | ||
| 130 | os.chdir(olddir) | ||
| 131 | } | ||
| 132 | |||
| 133 | python uninative_event_enable() { | ||
| 134 | """ | ||
| 135 | This event handler is called in the workers and is responsible for setting | ||
| 136 | up uninative if a loader is found. | ||
| 137 | """ | ||
| 138 | enable_uninative(d) | ||
| 139 | } | ||
| 140 | |||
| 141 | def enable_uninative(d): | ||
| 142 | loader = d.getVar("UNINATIVE_LOADER") | ||
| 143 | if os.path.exists(loader): | ||
| 144 | bb.debug(2, "Enabling uninative") | ||
| 145 | d.setVar("NATIVELSBSTRING", "universal") | ||
| 146 | d.appendVar("SSTATEPOSTUNPACKFUNCS", " uninative_changeinterp") | ||
| 147 | d.appendVarFlag("SSTATEPOSTUNPACKFUNCS", "vardepvalueexclude", "| uninative_changeinterp") | ||
| 148 | d.appendVar("BUILD_LDFLAGS", " -Wl,--allow-shlib-undefined -Wl,--dynamic-linker=${UNINATIVE_LOADER} -pthread") | ||
| 149 | d.appendVarFlag("BUILD_LDFLAGS", "vardepvalueexclude", "| -Wl,--allow-shlib-undefined -Wl,--dynamic-linker=${UNINATIVE_LOADER} -pthread") | ||
| 150 | d.appendVarFlag("BUILD_LDFLAGS", "vardepsexclude", "UNINATIVE_LOADER") | ||
| 151 | d.prependVar("PATH", "${UNINATIVE_STAGING_DIR}-uninative/${BUILD_ARCH}-linux${bindir_native}:") | ||
| 152 | |||
| 153 | python uninative_changeinterp () { | ||
| 154 | import subprocess | ||
| 155 | import stat | ||
| 156 | import oe.qa | ||
| 157 | |||
| 158 | if not (bb.data.inherits_class('native', d) or bb.data.inherits_class('crosssdk', d) or bb.data.inherits_class('cross', d)): | ||
| 159 | return | ||
| 160 | |||
| 161 | sstateinst = d.getVar('SSTATE_INSTDIR') | ||
| 162 | for walkroot, dirs, files in os.walk(sstateinst): | ||
| 163 | for file in files: | ||
| 164 | if file.endswith(".so") or ".so." in file: | ||
| 165 | continue | ||
| 166 | f = os.path.join(walkroot, file) | ||
| 167 | if os.path.islink(f): | ||
| 168 | continue | ||
| 169 | s = os.stat(f) | ||
| 170 | 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)): | ||
| 171 | continue | ||
| 172 | elf = oe.qa.ELFFile(f) | ||
| 173 | try: | ||
| 174 | elf.open() | ||
| 175 | except oe.qa.NotELFFileError: | ||
| 176 | continue | ||
| 177 | if not elf.isDynamic(): | ||
| 178 | continue | ||
| 179 | |||
| 180 | os.chmod(f, s[stat.ST_MODE] | stat.S_IWUSR) | ||
| 181 | subprocess.check_output(("patchelf-uninative", "--set-interpreter", d.getVar("UNINATIVE_LOADER"), f), stderr=subprocess.STDOUT) | ||
| 182 | os.chmod(f, s[stat.ST_MODE]) | ||
| 183 | } | ||
