Issue
When specifying the SRC_URI in a bitbake recipe, we were originally doing something like this:
SRC_URI = "git://[email protected]/our_org/our_repo;protocol=ssh;branch=main"
This works fine if you have SSH set up in that environment. However, due to different approaches by different teams, we also need to be able to support GitHub's PATs (personal access token). A SRC_URI for that would look like this:
SRC_URI = "git://github.com/our_org/our_repo;protocol=https;branch=main"
Is there a way to use both somehow? To have the SSH URI as a backup when the PAT URI fails? I tried using mirrors (which may be innapropriate, I am fairly new to Yocto) like this:
SRC_URI = "git://github.com/our_org/our_repo;protocol=https;branch=main"
MIRRORS = "git://.*/.* git://github.com/our_org/our_repo;protocol=https;branch=main"
However, when the first SRC_URI fails to authorize, we just exit immediately with an exception.
Is the best approach to use global variables to construct the SRC_URI? Or is there another built in way to support this fallback approach?
Thanks!
Solution
I would still love to hear if anyone has come up with a better fallback option, rather then using variables. However, I ended up using variables.
First I created a new bbclass called github-uri
:
FETCH_PROTOCOL ??= "ssh"
def build_github_uri(d, res, is_submodule=False):
fetch_protocol = d.getVar('FETCH_PROTOCOL', True).lower()
github_base = 'git@' if fetch_protocol == 'ssh' else ''
repo_type = 'gitsm' if is_submodule else 'git'
return "{}://{}github.com/{};protocol={}".format(repo_type, github_base, res, fetch_protocol)
I then used this in my recipes when I wanted to create a new SRC_URI for a github resource like so:
inherit github-uri
SRC_URI = "${@build_github_uri(d, 'my-org/our-repo.git')};branch=main"
Answered By - Alec Petersen Answer Checked By - David Goodson (WPSolving Volunteer)