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