blob: ba6dc4136c161aaf0d26be546696e4fadcd8b790 [file] [log] [blame]
Brad Bishop6e60e8b2018-02-01 10:27:11 -05001# Class for use in BBCLASSEXTEND to make it easier to have a single recipe that
2# can build both stable tarballs and snapshots from upstream source
3# repositories.
4#
5# Usage:
6# BBCLASSEXTEND = "devupstream:target"
Andrew Geissler595f6302022-01-24 19:11:47 +00007# SRC_URI:class-devupstream = "git://git.example.com/example;branch=master"
Patrick Williams213cb262021-08-07 19:21:33 -05008# SRCREV:class-devupstream = "abcdef"
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009#
10# If the first entry in SRC_URI is a git: URL then S is rewritten to
11# WORKDIR/git.
12#
13# There are a few caveats that remain to be solved:
14# - You can't build native or nativesdk recipes using for example
15# devupstream:native, you can only build target recipes.
16# - If the fetcher requires native tools (such as subversion-native) then
17# bitbake won't be able to add them automatically.
18
Brad Bishop6e60e8b2018-02-01 10:27:11 -050019python devupstream_virtclass_handler () {
20 # Do nothing if this is inherited, as it's for BBCLASSEXTEND
21 if "devupstream" not in (d.getVar('BBCLASSEXTEND') or ""):
22 bb.error("Don't inherit devupstream, use BBCLASSEXTEND")
23 return
24
25 variant = d.getVar("BBEXTENDVARIANT")
Patrick Williams213cb262021-08-07 19:21:33 -050026 if variant not in ("target", "native"):
27 bb.error("Unsupported variant %s. Pass the variant when using devupstream, for example devupstream:target" % variant)
Brad Bishop6e60e8b2018-02-01 10:27:11 -050028 return
29
30 # Develpment releases are never preferred by default
31 d.setVar("DEFAULT_PREFERENCE", "-1")
32
Andrew Geissler9aee5002022-03-30 16:27:02 +000033 src_uri = d.getVar("SRC_URI:class-devupstream") or d.getVar("SRC_URI")
34 uri = bb.fetch2.URI(src_uri.split()[0])
Brad Bishop6e60e8b2018-02-01 10:27:11 -050035
Patrick Williams213cb262021-08-07 19:21:33 -050036 if uri.scheme == "git" and not d.getVar("S:class-devupstream"):
Andrew Geissler9aee5002022-03-30 16:27:02 +000037 d.setVar("S", "${WORKDIR}/git")
Brad Bishop6e60e8b2018-02-01 10:27:11 -050038
39 # Modify the PV if the recipe hasn't already overridden it
40 pv = d.getVar("PV")
41 proto_marker = "+" + uri.scheme
Patrick Williams213cb262021-08-07 19:21:33 -050042 if proto_marker not in pv and not d.getVar("PV:class-devupstream"):
Brad Bishop6e60e8b2018-02-01 10:27:11 -050043 d.setVar("PV", pv + proto_marker + "${SRCPV}")
Patrick Williams213cb262021-08-07 19:21:33 -050044
45 if variant == "native":
46 pn = d.getVar("PN")
47 d.setVar("PN", "%s-native" % (pn))
48 fn = d.getVar("FILE")
49 bb.parse.BBHandler.inherit("native", fn, 0, d)
50
51 d.appendVar("CLASSOVERRIDE", ":class-devupstream")
Brad Bishop6e60e8b2018-02-01 10:27:11 -050052}
53
54addhandler devupstream_virtclass_handler
55devupstream_virtclass_handler[eventmask] = "bb.event.RecipePreFinalise"