Skip to content

Commit

Permalink
meta-balena-rust: Provide crate fetcher for Yocto versions without it
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Florin Sarbu <[email protected]>
  • Loading branch information
floion committed Dec 11, 2024
1 parent 87e338d commit 27ab937
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
7 changes: 7 additions & 0 deletions meta-balena-rust/classes/cargo_common.bbclass
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 28 additions & 0 deletions meta-balena-rust/classes/crate-fetch.bbclass
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#
# crate-fetch class
#
# Registers 'crate' method for Bitbake fetch2.
#
# Adds support for following format in recipe SRC_URI:
# crate://<packagename>/<version>
#

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)}"
2 changes: 1 addition & 1 deletion meta-balena-rust/lib/crate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down

0 comments on commit 27ab937

Please sign in to comment.