Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1 | # 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 Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 7 | # SRC_URI:class-devupstream = "git://git.example.com/example;branch=master" |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 8 | # SRCREV:class-devupstream = "abcdef" |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 9 | # |
| 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 Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 19 | python 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 Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 26 | if variant not in ("target", "native"): |
| 27 | bb.error("Unsupported variant %s. Pass the variant when using devupstream, for example devupstream:target" % variant) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 28 | 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 Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 35 | if uri.scheme == "git" and not d.getVar("S:class-devupstream"): |
| 36 | d.setVar("S:class-devupstream", "${WORKDIR}/git") |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 37 | |
| 38 | # Modify the PV if the recipe hasn't already overridden it |
| 39 | pv = d.getVar("PV") |
| 40 | proto_marker = "+" + uri.scheme |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 41 | if proto_marker not in pv and not d.getVar("PV:class-devupstream"): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 42 | d.setVar("PV", pv + proto_marker + "${SRCPV}") |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 43 | |
| 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 Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | addhandler devupstream_virtclass_handler |
| 54 | devupstream_virtclass_handler[eventmask] = "bb.event.RecipePreFinalise" |