meta-rust / cargo-bitbake

cargo extension that can generate BitBake recipes utilizing the classes from meta-rust
Apache License 2.0
84 stars 59 forks source link

problem with reduced commit hash #28

Closed bernardoaraujor closed 3 years ago

bernardoaraujor commented 3 years ago

I'm working on a recipe for OpenEthereum. I ran $ cargo-bitbake bitbake on a clone of the repository (checked out at v3.2.5 tag).

However BitBake wasn't able to parse the resulting recipe:

                     try:
    >                    self.ud[url] = FetchData(url, d, localonly)
                     except NonLocalMethod:
  File "/home/bernardo/develop/oe-dev/oe-core/bitbake/lib/bb/fetch2/__init__.py", line 1277, in FetchData.__init__(url='git://github.com/gnosis/reth.git;protocol=https;nobranch=1;name=reth-util;destsuffix=reth-util', d=<bb.data_smart.DataSmart object at 0x7fa853421970>, localonly=False):
             if hasattr(self.method, "urldata_init"):
    >            self.method.urldata_init(self, d)

  File "/home/bernardo/develop/oe-dev/oe-core/bitbake/lib/bb/fetch2/git.py", line 243, in Git.urldata_init(ud=<bb.fetch2.FetchData object at 0x7fa8532f6a30>, d=<bb.data_smart.DataSmart object at 0x7fa853421970>):
                         ud.unresolvedrev[name] = ud.revisions[name]
    >                ud.revisions[name] = self.latest_revision(ud, d, name)

  File "/home/bernardo/develop/oe-dev/oe-core/bitbake/lib/bb/fetch2/__init__.py", line 1581, in Git.latest_revision(ud=<bb.fetch2.FetchData object at 0x7fa8532f6a30>, d=<bb.data_smart.DataSmart object at 0x7fa853421970>, name='reth-util'):
             except KeyError:
    >            revs[key] = rev = self._latest_revision(ud, d, name)
                 return rev
  File "/home/bernardo/develop/oe-dev/oe-core/bitbake/lib/bb/fetch2/git.py", line 703, in Git._latest_revision(ud=<bb.fetch2.FetchData object at 0x7fa8532f6a30>, d=<bb.data_smart.DataSmart object at 0x7fa853421970>, name='reth-util'):
                         return sha1
    >        raise bb.fetch2.FetchError("Unable to resolve '%s' in upstream git repository in git ls-remote output for %s" % \
                 (ud.unresolvedrev[name], ud.host+ud.path))
bb.data_smart.ExpansionError: Failure expanding variable SRCPV, expression was ${@bb.fetch2.get_srcrev(d)} which triggered exception FetchError: Fetcher failure: Unable to resolve '573e128' in upstream git repository in git ls-remote output for github.com/gnosis/reth.git

It seems BitBake doesn't understand the reduced version of the commit hash 573e128. So I did a $ grep -rn . -e 573e128 inside the openethereum local clone and arrived to the following line of Cargo.lock:

source = "git+https://github.com/gnosis/reth.git?rev=573e128#573e128487d5651f301e21faa97fc8e80f91dee8"

So I applied the following modification to the generated BB recipe:

- SRCREV_reth-util = "573e128"
+ SRCREV_reth-util = "573e128487d5651f301e21faa97fc8e80f91dee8"

And BitBake was able to parse it.

I would love to submit a PR to help cargo-bitbake avoid this error in the future. Should we modify some of the logic here? (tagging @cardoe cause I believe you wrote this block)

                let rev = match *src_id.git_reference()? {
                    GitReference::Tag(ref s) | GitReference::Rev(ref s) => s.to_owned(),
                    GitReference::Branch(ref s) => {
                        if s == "master" {
                            String::from("${AUTOREV}")
                        } else {
                            s.to_owned()
                        }
                    }
                    GitReference::DefaultBranch => String::from("${AUTOREV}"),
                };

The idea is to have the rev variable pick up the entire commit hash (instead of the reduced form) whenever the package is listed in Cargo.lock under the following format:

source = "git+https://<URL>?rev=<reduced_hash>#<full_hash>"

Perhaps a new match case? Or some specific function from git2 crate?