blob: dc9a9472b1c3ae40c38413968b55d3849a302a14 [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"
Patrick Williams213cb262021-08-07 19:21:33 -05007# SRC_URI:class-devupstream = "git://git.example.com/example"
8# 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
33 uri = bb.fetch2.URI(d.getVar("SRC_URI").split()[0])
34
Patrick Williams213cb262021-08-07 19:21:33 -050035 if uri.scheme == "git" and not d.getVar("S:class-devupstream"):
36 d.setVar("S:class-devupstream", "${WORKDIR}/git")
Brad Bishop6e60e8b2018-02-01 10:27:11 -050037
38 # Modify the PV if the recipe hasn't already overridden it
39 pv = d.getVar("PV")
40 proto_marker = "+" + uri.scheme
Patrick Williams213cb262021-08-07 19:21:33 -050041 if proto_marker not in pv and not d.getVar("PV:class-devupstream"):
Brad Bishop6e60e8b2018-02-01 10:27:11 -050042 d.setVar("PV", pv + proto_marker + "${SRCPV}")
Patrick Williams213cb262021-08-07 19:21:33 -050043
44 if variant == "native":
45 pn = d.getVar("PN")
46 d.setVar("PN", "%s-native" % (pn))
47 fn = d.getVar("FILE")
48 bb.parse.BBHandler.inherit("native", fn, 0, d)
49
50 d.appendVar("CLASSOVERRIDE", ":class-devupstream")
Brad Bishop6e60e8b2018-02-01 10:27:11 -050051}
52
53addhandler devupstream_virtclass_handler
54devupstream_virtclass_handler[eventmask] = "bb.event.RecipePreFinalise"