summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/bb/fetch2/git.py
diff options
context:
space:
mode:
authorChen Qi <Qi.Chen@windriver.com>2024-01-31 19:30:58 -0800
committerRichard Purdie <richard.purdie@linuxfoundation.org>2024-02-19 15:08:30 +0000
commitc984b03f0275084566527559ea29bc480d7c27cb (patch)
tree8da3151233fb40bab8113d87a3622831a80f321a /bitbake/lib/bb/fetch2/git.py
parent6cddb77eee273d9d44110ec3ecd01a8d195d2e4b (diff)
downloadpoky-c984b03f0275084566527559ea29bc480d7c27cb.tar.gz
bitbake: fetch2/git.py: fix a corner case in try_premirror
For gitsm recipes, it's possible that some URL is used more than once. e.g., A -> B:rev1 (B is a submodule of A) A -> C (C is a submodule of A) C -> B:rev2 (B is a submodule of C) A anc C are both using B as submodules, but on different revs. Now if we have: B:rev1 -> D B:rev2 -> E Then, the mirror will not be fully used. Say we have all repo mirrors for A, B, C, D, E, then in theory it's not necessary to reach out to any network for downloading. But it's not the case. After downloading B(rev1) and its submodule D from mirrors, the fetch process continues to download C, thus B(rev2) and E. Now it finds that B needs an update because its submodule E needs an update. Of course this is true because E is not downloaded yet. Now the problem comes to whether to use mirror or not. The git.py defines try_premirror to return 'False' when the ud.clonedir exists. As B has been cloned, the ud.clonedir exists and try_mirror returns False, resulting in not using mirror and going to upstream directly. We can see that the mirrors are not fully used. This is usually not problem, as the cost is only some network download. But in case the following two settings are there, we get errors. BB_NO_NETWORK = "0" BB_ALLOWED_NETWORKS = "*.some.allowed.domain" In such case, the gitsm recipe A will fail to fetch. Note that all contents that A needs are in mirrors and now it's failing to fetch. This is unexpected. Note that the different revs of the same repo in gitsm recipe is not the only way to reveal this problem. For example, there might be a recipe call B that uses B:rev3. Check the protobuf and grpc recipes as an example. For now, we can use the following steps to reproduce this issue. To be clear, the grpc recipe in meta-oe is now 1.60.0. 1. Add in local.conf: DL_DIR = "${TOPDIR}/downloads-premirror" bitbake grpc -c fetch 2. Comment out the DL_DIR setting in local.conf and add the following lines: PREMIRRORS:append = " \ git://.*/.* git://${TOPDIR}/downloads-premirror/git2/MIRRORNAME;protocol=file \n \ gitsm://.*/.* gitsm://${TOPDIR}/downloads-premirror/git2/MIRRORNAME;protocol=file \n \ " 3. Set BB_NO_NETWORK = "1" and then 'bitbake grpc -c fetch'. This command succeeds and this shows that the premirror holds everything we need. 4. Add the following lines and then 'bitbake grpc -c fetch'. BB_NO_NETWORK = "0" BB_ALLOWED_NETWORKS = "*.some.domain" After step 4, the error message is as below: ERROR: grpc-1.60.0-r0 do_fetch: The URL: 'gitsm://github.com/protocolbuffers/protobuf.git;protocol=https;name=third_party/protobuf;subpath=third_party/protobuf;nobranch=1;lfs=True;bareclone=1;nobranch=1' is not trusted and cannot be used This patch fixes this problem by handling this corner case, that is, if the URL is not trusted from the settings of BB_NO_NETWORK and BB_ALLOWED_NETWORKS, then we should try premirrors because trying to reach upstream is destined to fail. (Bitbake rev: e1be272ad105b47d3131b77168d9172386993fcb) Signed-off-by: Chen Qi <Qi.Chen@windriver.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/bb/fetch2/git.py')
-rw-r--r--bitbake/lib/bb/fetch2/git.py6
1 files changed, 6 insertions, 0 deletions
diff --git a/bitbake/lib/bb/fetch2/git.py b/bitbake/lib/bb/fetch2/git.py
index 43c0ca2f15..1faa2145cf 100644
--- a/bitbake/lib/bb/fetch2/git.py
+++ b/bitbake/lib/bb/fetch2/git.py
@@ -87,6 +87,7 @@ from contextlib import contextmanager
87from bb.fetch2 import FetchMethod 87from bb.fetch2 import FetchMethod
88from bb.fetch2 import runfetchcmd 88from bb.fetch2 import runfetchcmd
89from bb.fetch2 import logger 89from bb.fetch2 import logger
90from bb.fetch2 import trusted_network
90 91
91 92
92sha1_re = re.compile(r'^[0-9a-f]{40}$') 93sha1_re = re.compile(r'^[0-9a-f]{40}$')
@@ -355,6 +356,11 @@ class Git(FetchMethod):
355 # is not possible 356 # is not possible
356 if bb.utils.to_boolean(d.getVar("BB_FETCH_PREMIRRORONLY")): 357 if bb.utils.to_boolean(d.getVar("BB_FETCH_PREMIRRORONLY")):
357 return True 358 return True
359 # If the url is not in trusted network, that is, BB_NO_NETWORK is set to 0
360 # and BB_ALLOWED_NETWORKS does not contain the host that ud.url uses, then
361 # we need to try premirrors first as using upstream is destined to fail.
362 if not trusted_network(d, ud.url):
363 return True
358 if os.path.exists(ud.clonedir): 364 if os.path.exists(ud.clonedir):
359 return False 365 return False
360 return True 366 return True