Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 1 | # |
| 2 | # Copyright OpenEmbedded Contributors |
| 3 | # |
| 4 | # SPDX-License-Identifier: MIT |
| 5 | # |
| 6 | |
| 7 | # avoids build breaks when using no-static-libs.inc |
| 8 | DISABLE_STATIC = "" |
| 9 | |
| 10 | # What Python interpretter to use. Defaults to Python 3 but can be |
| 11 | # overridden if required. |
| 12 | WAF_PYTHON ?= "python3" |
| 13 | |
| 14 | B = "${WORKDIR}/build" |
| 15 | do_configure[cleandirs] += "${B}" |
| 16 | |
| 17 | EXTRA_OECONF:append = " ${PACKAGECONFIG_CONFARGS}" |
| 18 | |
| 19 | EXTRA_OEWAF_BUILD ??= "" |
| 20 | # In most cases, you want to pass the same arguments to `waf build` and `waf |
| 21 | # install`, but you can override it if necessary |
| 22 | EXTRA_OEWAF_INSTALL ??= "${EXTRA_OEWAF_BUILD}" |
| 23 | |
| 24 | def waflock_hash(d): |
| 25 | # Calculates the hash used for the waf lock file. This should include |
| 26 | # all of the user controllable inputs passed to waf configure. Note |
| 27 | # that the full paths for ${B} and ${S} are used; this is OK and desired |
| 28 | # because a change to either of these should create a unique lock file |
| 29 | # to prevent collisions. |
| 30 | import hashlib |
| 31 | h = hashlib.sha512() |
| 32 | def update(name): |
| 33 | val = d.getVar(name) |
| 34 | if val is not None: |
| 35 | h.update(val.encode('utf-8')) |
| 36 | update('S') |
| 37 | update('B') |
| 38 | update('prefix') |
| 39 | update('EXTRA_OECONF') |
| 40 | return h.hexdigest() |
| 41 | |
| 42 | # Use WAFLOCK to specify a separate lock file. The build is already |
| 43 | # sufficiently isolated by setting the output directory, this ensures that |
| 44 | # bitbake won't step on toes of any other configured context in the source |
| 45 | # directory (e.g. if the source is coming from externalsrc and was previously |
| 46 | # configured elsewhere). |
| 47 | export WAFLOCK = ".lock-waf_oe_${@waflock_hash(d)}_build" |
| 48 | BB_BASEHASH_IGNORE_VARS += "WAFLOCK" |
| 49 | |
| 50 | python waf_preconfigure() { |
| 51 | import subprocess |
| 52 | subsrcdir = d.getVar('S') |
| 53 | python = d.getVar('WAF_PYTHON') |
| 54 | wafbin = os.path.join(subsrcdir, 'waf') |
| 55 | try: |
| 56 | result = subprocess.check_output([python, wafbin, '--version'], cwd=subsrcdir, stderr=subprocess.STDOUT) |
Patrick Williams | 3965356 | 2024-03-01 08:54:02 -0600 | [diff] [blame^] | 57 | # Output looks like: |
| 58 | # # output from lower modules (e.g. warnings, ...) |
| 59 | # waf X.Y.Z ... |
| 60 | # So, look for the line starting with "waf " |
| 61 | version = None |
| 62 | for line in result.decode('utf-8').split("\n"): |
| 63 | if line.startswith("waf "): |
| 64 | version = line.split()[1] |
| 65 | break |
| 66 | |
| 67 | if not version or not bb.utils.is_semver(version): |
Patrick Williams | 73bd93f | 2024-02-20 08:07:48 -0600 | [diff] [blame] | 68 | bb.warn("Unable to parse \"waf --version\" output. Assuming waf version without bindir/libdir support.") |
| 69 | bb.warn("waf·--version·output = \n%s" % result.decode('utf-8')) |
| 70 | elif bb.utils.vercmp_string_op(version, "1.8.7", ">="): |
Patrick Williams | 3965356 | 2024-03-01 08:54:02 -0600 | [diff] [blame^] | 71 | bb.note("waf version is high enough to add --bindir and --libdir") |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 72 | d.setVar("WAF_EXTRA_CONF", "--bindir=${bindir} --libdir=${libdir}") |
| 73 | except subprocess.CalledProcessError as e: |
| 74 | bb.warn("Unable to execute waf --version, exit code %d. Assuming waf version without bindir/libdir support." % e.returncode) |
| 75 | except FileNotFoundError: |
| 76 | bb.fatal("waf does not exist in %s" % subsrcdir) |
| 77 | } |
| 78 | |
| 79 | do_configure[prefuncs] += "waf_preconfigure" |
| 80 | |
| 81 | waf_do_configure() { |
| 82 | (cd ${S} && ${WAF_PYTHON} ./waf configure -o ${B} --prefix=${prefix} ${WAF_EXTRA_CONF} ${EXTRA_OECONF}) |
| 83 | } |
| 84 | |
| 85 | do_compile[progress] = "outof:^\[\s*(\d+)/\s*(\d+)\]\s+" |
| 86 | waf_do_compile() { |
| 87 | (cd ${S} && ${WAF_PYTHON} ./waf build ${@oe.utils.parallel_make_argument(d, '-j%d', limit=64)} ${EXTRA_OEWAF_BUILD}) |
| 88 | } |
| 89 | |
| 90 | waf_do_install() { |
| 91 | (cd ${S} && ${WAF_PYTHON} ./waf install --destdir=${D} ${EXTRA_OEWAF_INSTALL}) |
| 92 | } |
| 93 | |
| 94 | EXPORT_FUNCTIONS do_configure do_compile do_install |