waf.bbclass 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. # avoids build breaks when using no-static-libs.inc
  2. DISABLE_STATIC = ""
  3. # What Python interpretter to use. Defaults to Python 3 but can be
  4. # overridden if required.
  5. WAF_PYTHON ?= "python3"
  6. B = "${WORKDIR}/build"
  7. do_configure[cleandirs] += "${B}"
  8. EXTRA_OECONF_append = " ${PACKAGECONFIG_CONFARGS}"
  9. EXTRA_OEWAF_BUILD ??= ""
  10. # In most cases, you want to pass the same arguments to `waf build` and `waf
  11. # install`, but you can override it if necessary
  12. EXTRA_OEWAF_INSTALL ??= "${EXTRA_OEWAF_BUILD}"
  13. def waflock_hash(d):
  14. # Calculates the hash used for the waf lock file. This should include
  15. # all of the user controllable inputs passed to waf configure. Note
  16. # that the full paths for ${B} and ${S} are used; this is OK and desired
  17. # because a change to either of these should create a unique lock file
  18. # to prevent collisions.
  19. import hashlib
  20. h = hashlib.sha512()
  21. def update(name):
  22. val = d.getVar(name)
  23. if val is not None:
  24. h.update(val.encode('utf-8'))
  25. update('S')
  26. update('B')
  27. update('prefix')
  28. update('EXTRA_OECONF')
  29. return h.hexdigest()
  30. # Use WAFLOCK to specify a separate lock file. The build is already
  31. # sufficiently isolated by setting the output directory, this ensures that
  32. # bitbake won't step on toes of any other configured context in the source
  33. # directory (e.g. if the source is coming from externalsrc and was previously
  34. # configured elsewhere).
  35. export WAFLOCK = ".lock-waf_oe_${@waflock_hash(d)}_build"
  36. BB_HASHBASE_WHITELIST += "WAFLOCK"
  37. python waf_preconfigure() {
  38. import subprocess
  39. from distutils.version import StrictVersion
  40. subsrcdir = d.getVar('S')
  41. python = d.getVar('WAF_PYTHON')
  42. wafbin = os.path.join(subsrcdir, 'waf')
  43. try:
  44. result = subprocess.check_output([python, wafbin, '--version'], cwd=subsrcdir, stderr=subprocess.STDOUT)
  45. version = result.decode('utf-8').split()[1]
  46. if StrictVersion(version) >= StrictVersion("1.8.7"):
  47. d.setVar("WAF_EXTRA_CONF", "--bindir=${bindir} --libdir=${libdir}")
  48. except subprocess.CalledProcessError as e:
  49. bb.warn("Unable to execute waf --version, exit code %d. Assuming waf version without bindir/libdir support." % e.returncode)
  50. except FileNotFoundError:
  51. bb.fatal("waf does not exist in %s" % subsrcdir)
  52. }
  53. do_configure[prefuncs] += "waf_preconfigure"
  54. waf_do_configure() {
  55. (cd ${S} && ${WAF_PYTHON} ./waf configure -o ${B} --prefix=${prefix} ${WAF_EXTRA_CONF} ${EXTRA_OECONF})
  56. }
  57. do_compile[progress] = "outof:^\[\s*(\d+)/\s*(\d+)\]\s+"
  58. waf_do_compile() {
  59. (cd ${S} && ${WAF_PYTHON} ./waf build ${@oe.utils.parallel_make_argument(d, '-j%d', limit=64)} ${EXTRA_OEWAF_BUILD})
  60. }
  61. waf_do_install() {
  62. (cd ${S} && ${WAF_PYTHON} ./waf install --destdir=${D} ${EXTRA_OEWAF_INSTALL})
  63. }
  64. EXPORT_FUNCTIONS do_configure do_compile do_install