devupstream.bbclass 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #
  2. # Copyright OpenEmbedded Contributors
  3. #
  4. # Class for use in BBCLASSEXTEND to make it easier to have a single recipe that
  5. # can build both stable tarballs and snapshots from upstream source
  6. # repositories.
  7. #
  8. # Usage:
  9. # BBCLASSEXTEND = "devupstream:target"
  10. # SRC_URI:class-devupstream = "git://git.example.com/example;branch=master"
  11. # SRCREV:class-devupstream = "abcdef"
  12. #
  13. # If the first entry in SRC_URI is a git: URL then S is rewritten to
  14. # WORKDIR/git.
  15. #
  16. # There are a few caveats that remain to be solved:
  17. # - You can't build native or nativesdk recipes using for example
  18. # devupstream:native, you can only build target recipes.
  19. # - If the fetcher requires native tools (such as subversion-native) then
  20. # bitbake won't be able to add them automatically.
  21. python devupstream_virtclass_handler () {
  22. # Do nothing if this is inherited, as it's for BBCLASSEXTEND
  23. if "devupstream" not in (d.getVar('BBCLASSEXTEND') or ""):
  24. bb.error("Don't inherit devupstream, use BBCLASSEXTEND")
  25. return
  26. variant = d.getVar("BBEXTENDVARIANT")
  27. if variant not in ("target", "native"):
  28. bb.error("Unsupported variant %s. Pass the variant when using devupstream, for example devupstream:target" % variant)
  29. return
  30. # Develpment releases are never preferred by default
  31. d.setVar("DEFAULT_PREFERENCE", "-1")
  32. src_uri = d.getVar("SRC_URI:class-devupstream") or d.getVar("SRC_URI")
  33. uri = bb.fetch2.URI(src_uri.split()[0])
  34. if uri.scheme == "git" and not d.getVar("S:class-devupstream"):
  35. d.setVar("S", "${WORKDIR}/git")
  36. # Modify the PV if the recipe hasn't already overridden it
  37. pv = d.getVar("PV")
  38. proto_marker = "+" + uri.scheme
  39. if proto_marker not in pv and not d.getVar("PV:class-devupstream"):
  40. d.setVar("PV", pv + proto_marker + "${SRCPV}")
  41. if variant == "native":
  42. pn = d.getVar("PN")
  43. d.setVar("PN", "%s-native" % (pn))
  44. fn = d.getVar("FILE")
  45. bb.parse.BBHandler.inherit("native", fn, 0, d)
  46. d.appendVar("CLASSOVERRIDE", ":class-devupstream")
  47. }
  48. addhandler devupstream_virtclass_handler
  49. devupstream_virtclass_handler[eventmask] = "bb.event.RecipePreFinalise"