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