From 27ab937ff026c00f9f2aae0b83cdad0814f1b756 Mon Sep 17 00:00:00 2001 From: Florin Sarbu Date: Wed, 11 Dec 2024 21:55:04 +0000 Subject: [PATCH] meta-balena-rust: Provide crate fetcher for Yocto versions without it The crate fetcher was introduced in bitbake in Kirkstone, before that it was living in meta-rust. We want to use the balena-rust layer across a wide variety of Yocto versions so include the fetcher conditionally. Signed-off-by: Alex Gonzalez Signed-off-by: Florin Sarbu --- meta-balena-rust/classes/cargo_common.bbclass | 7 +++++ meta-balena-rust/classes/crate-fetch.bbclass | 28 +++++++++++++++++++ meta-balena-rust/lib/crate.py | 2 +- 3 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 meta-balena-rust/classes/crate-fetch.bbclass diff --git a/meta-balena-rust/classes/cargo_common.bbclass b/meta-balena-rust/classes/cargo_common.bbclass index f503a001dd..e269f4df78 100644 --- a/meta-balena-rust/classes/cargo_common.bbclass +++ b/meta-balena-rust/classes/cargo_common.bbclass @@ -14,7 +14,14 @@ ## is used by cargo.bbclass and Rust ## +def set_crate_fetcher(d): + # Check to see whether bitbake has a crate fetcher (included in Kirkstone) + if not os.path.exists(os.path.join(d.getVar('TOPDIR'),'../layers/poky/bitbake/lib/bb/fetch2/crate.py')): + return "crate-fetch" + return "" + # add crate fetch support +inherit ${@set_crate_fetcher(d)} inherit rust-common # Where we download our registry and dependencies to diff --git a/meta-balena-rust/classes/crate-fetch.bbclass b/meta-balena-rust/classes/crate-fetch.bbclass new file mode 100644 index 0000000000..a7fa22b2a0 --- /dev/null +++ b/meta-balena-rust/classes/crate-fetch.bbclass @@ -0,0 +1,28 @@ +# +# crate-fetch class +# +# Registers 'crate' method for Bitbake fetch2. +# +# Adds support for following format in recipe SRC_URI: +# crate:/// +# + +def import_crate(d): + import crate + if not getattr(crate, 'imported', False): + bb.fetch2.methods.append(crate.Crate()) + crate.imported = True + +python crate_import_handler() { + import_crate(d) +} + +addhandler crate_import_handler +crate_import_handler[eventmask] = "bb.event.RecipePreFinalise" + +def crate_get_srcrev(d): + import_crate(d) + return bb.fetch2.get_srcrev(d) + +# Override SRCPV to make sure it imports the fetcher first +SRCPV = "${@crate_get_srcrev(d)}" diff --git a/meta-balena-rust/lib/crate.py b/meta-balena-rust/lib/crate.py index f091200dd9..47012b1a63 100644 --- a/meta-balena-rust/lib/crate.py +++ b/meta-balena-rust/lib/crate.py @@ -71,7 +71,7 @@ def _crate_urldata_init(self, ud, d): ud.parm['downloadfilename'] = "%s-%s.crate" % (name, version) ud.parm['name'] = name - logger.debug2("Fetching %s to %s" % (ud.url, ud.parm['downloadfilename'])) + logger.debug(2, "Fetching %s to %s" % (ud.url, ud.parm['downloadfilename'])) def unpack(self, ud, rootdir, d): """