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 | |
Andrew Geissler | 9aee500 | 2022-03-30 16:27:02 +0000 | [diff] [blame] | 33 | src_uri = d.getVar("SRC_URI:class-devupstream") or d.getVar("SRC_URI") |
| 34 | uri = bb.fetch2.URI(src_uri.split()[0]) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 35 | |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 36 | if uri.scheme == "git" and not d.getVar("S:class-devupstream"): |
Andrew Geissler | 9aee500 | 2022-03-30 16:27:02 +0000 | [diff] [blame] | 37 | d.setVar("S", "${WORKDIR}/git") |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 38 | |
| 39 | # Modify the PV if the recipe hasn't already overridden it |
| 40 | pv = d.getVar("PV") |
| 41 | proto_marker = "+" + uri.scheme |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 42 | 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] | 43 | d.setVar("PV", pv + proto_marker + "${SRCPV}") |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 44 | |
| 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 Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | addhandler devupstream_virtclass_handler |
| 55 | devupstream_virtclass_handler[eventmask] = "bb.event.RecipePreFinalise" |