From mboxrd@z Thu Jan 1 00:00:00 1970 Subject: Re: gitsm fetcher fails when `PREMIRRORS_ONLY` is set To: bitbake-devel@lists.openembedded.org From: tiago.mlb.vasconcelos@gmail.com X-Originating-Location: Lisbon, PT (213.205.68.220) X-Originating-Platform: Windows Chrome 157 User-Agent: GROUPS.IO Web Poster MIME-Version: 1.0 Date: Mon, 23 Nov 2026 02:35:35 -0800 References: <9Kec.1795097583791318314.gZXu@lists.openembedded.org> In-Reply-To: Message-ID: <1100827.1795430135720488922@lists.openembedded.org> Content-Type: multipart/alternative; boundary="tlvtmbFVm8PFhoUU4OeX" List-Id: X-Webhook-Received: from 45-33-107-173.ip.linodeusercontent.com [45.33.107.173] by lin-tor-korg-lkml-alma10-1 with HTTPS for ; Mon, 23 Nov 2026 10:35:43 -0000 X-Groupsio-URL: https://lists.openembedded.org/g/bitbake-devel/message/20470 --tlvtmbFVm8PFhoUU4OeX Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Hi Richard, Thank you for the feedback. Below are new bitbake-selftest cases in lib/bb/tests/fetch.py that show the issue, together with a possible fix. Without the gitsm.py change, `test_submodule_premirroronly` and `test_shallow_submodule_premirroronly` will fail: Signed-off-by: Tiago Vasconcelos --- diff --git a/lib/bb/fetch2/gitsm.py b/lib/bb/fetch2/gitsm.py index 5869e1b99..727462ea3 100644 --- a/lib/bb/fetch2/gitsm.py +++ b/lib/bb/fetch2/gitsm.py @@ -194,6 +194,12 @@ class GitSM(Git): # Is the following still needed? #url +=3D ";nocheckout=3D1" + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0# BB_NO_NETWORK may have been se= t by the parent fetch for its mirror + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0# tarball. The submodule Fetch a= pplies BB_FETCH_PREMIRRORONLY itself, + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0# blocking upstream but still al= lowing PREMIRRORS. + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0if bb.utils.to_boolean(d.getVar(= "BB_FETCH_PREMIRRORONLY")): + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0d.setVar("BB_NO_NE= TWORK", "0") + try: newfetch =3D Fetch([url], d, cache=3DFalse) newfetch.download() diff --git a/lib/bb/tests/fetch.py b/lib/bb/tests/fetch.py index cc133c1f5..106643d82 100644 --- a/lib/bb/tests/fetch.py +++ b/lib/bb/tests/fetch.py @@ -2092,6 +2092,102 @@ class GitShallowTest(FetcherTest): # Verify the submodule is also shallow self.assertRevCount(1, cwd=3Dos.path.join(self.gitdir, 'gitsubmodule')) + =C2=A0 =C2=A0def use_http_premirror(self, mirrordir): + =C2=A0 =C2=A0 =C2=A0 =C2=A0# Serve the prepared downloads locally and all= ow this host in mirror-only mode. + =C2=A0 =C2=A0 =C2=A0 =C2=A0server =3D HTTPService(mirrordir, host=3D'127.= 0.0.1') + =C2=A0 =C2=A0 =C2=A0 =C2=A0server.start() + =C2=A0 =C2=A0 =C2=A0 =C2=A0self.addCleanup(server.stop) + =C2=A0 =C2=A0 =C2=A0 =C2=A0self.d.setVar('PREMIRRORS', 'gitsm://.*/.* htt= p://127.0.0.1:%s/' % server.port) + =C2=A0 =C2=A0 =C2=A0 =C2=A0self.d.setVar('BB_FETCH_PREMIRRORONLY', '1') + =C2=A0 =C2=A0 =C2=A0 =C2=A0self.d.setVar('BB_NO_NETWORK', '0') + =C2=A0 =C2=A0 =C2=A0 =C2=A0self.d.setVar('BB_ALLOWED_NETWORKS', '127.0.0.= 1') + + =C2=A0 =C2=A0def check_submodule_premirroronly(self, shallow): + =C2=A0 =C2=A0 =C2=A0 =C2=A0if not shallow: + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0self.d.setVar('BB_GIT_SHALLOW', = '0') + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0self.d.setVar('BB_GENERATE_MIRRO= R_TARBALLS', '1') + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0self.d.setVar('BB_GENERATE_SHALL= OW_TARBALLS', '0') + + =C2=A0 =C2=A0 =C2=A0 =C2=A0# Create a submodule with two commits so its f= etched history can be checked. + =C2=A0 =C2=A0 =C2=A0 =C2=A0self.add_empty_file('a') + =C2=A0 =C2=A0 =C2=A0 =C2=A0self.add_empty_file('b') + + =C2=A0 =C2=A0 =C2=A0 =C2=A0smdir =3D os.path.join(self.tempdir, 'gitsubmo= dule') + =C2=A0 =C2=A0 =C2=A0 =C2=A0bb.utils.mkdirhier(smdir) + =C2=A0 =C2=A0 =C2=A0 =C2=A0self.git_init(cwd=3Dsmdir) + =C2=A0 =C2=A0 =C2=A0 =C2=A0# Make this look like it was cloned from a rem= ote... + =C2=A0 =C2=A0 =C2=A0 =C2=A0self.git('config --add remote.origin.url "%s"'= % smdir, cwd=3Dsmdir) + =C2=A0 =C2=A0 =C2=A0 =C2=A0self.git('config --add remote.origin.fetch "+r= efs/heads/*:refs/remotes/origin/*"', cwd=3Dsmdir) + =C2=A0 =C2=A0 =C2=A0 =C2=A0self.add_empty_file('asub', cwd=3Dsmdir) + =C2=A0 =C2=A0 =C2=A0 =C2=A0self.add_empty_file('bsub', cwd=3Dsmdir) + + =C2=A0 =C2=A0 =C2=A0 =C2=A0self.git('submodule init', cwd=3Dself.srcdir) + =C2=A0 =C2=A0 =C2=A0 =C2=A0self.git('-c protocol.file.allow=3Dalways subm= odule add file://%s' % smdir, cwd=3Dself.srcdir) + =C2=A0 =C2=A0 =C2=A0 =C2=A0self.git('submodule update', cwd=3Dself.srcdir= ) + =C2=A0 =C2=A0 =C2=A0 =C2=A0self.git('commit -m submodule -a', cwd=3Dself.= srcdir) + + =C2=A0 =C2=A0 =C2=A0 =C2=A0uri =3D 'gitsm://%s;protocol=3Dfile;subdir=3D$= {S};branch=3Dmaster' % self.srcdir + + =C2=A0 =C2=A0 =C2=A0 =C2=A0# Fetch once to generate the mirror tarballs + =C2=A0 =C2=A0 =C2=A0 =C2=A0self.fetch(uri) + + =C2=A0 =C2=A0 =C2=A0 =C2=A0# Stop generating tarballs during the mirror-o= nly fetch. + =C2=A0 =C2=A0 =C2=A0 =C2=A0self.d.setVar('BB_GENERATE_MIRROR_TARBALLS', '= 0') + =C2=A0 =C2=A0 =C2=A0 =C2=A0self.d.setVar('BB_GENERATE_SHALLOW_TARBALLS', = '0') + =C2=A0 =C2=A0 =C2=A0 =C2=A0mirrordir =3D os.path.join(self.tempdir, 'mirr= or') + =C2=A0 =C2=A0 =C2=A0 =C2=A0bb.utils.rename(self.dldir, mirrordir) + =C2=A0 =C2=A0 =C2=A0 =C2=A0bb.utils.mkdirhier(self.dldir) + =C2=A0 =C2=A0 =C2=A0 =C2=A0# Remove the original repositories so the fetc= h must use the premirror. + =C2=A0 =C2=A0 =C2=A0 =C2=A0bb.utils.remove(self.gitdir, recurse=3DTrue) + =C2=A0 =C2=A0 =C2=A0 =C2=A0bb.utils.remove(self.srcdir, recurse=3DTrue) + =C2=A0 =C2=A0 =C2=A0 =C2=A0bb.utils.remove(smdir, recurse=3DTrue) + + =C2=A0 =C2=A0 =C2=A0 =C2=A0self.use_http_premirror(mirrordir) + =C2=A0 =C2=A0 =C2=A0 =C2=A0self.fetch_and_unpack(uri) + + =C2=A0 =C2=A0 =C2=A0 =C2=A0# Shallow fetches retain only the tip commit; = full fetches retain all commits. + =C2=A0 =C2=A0 =C2=A0 =C2=A0expected_revisions =3D 1 if shallow else 3 + =C2=A0 =C2=A0 =C2=A0 =C2=A0self.assertRevCount(expected_revisions) + =C2=A0 =C2=A0 =C2=A0 =C2=A0self.assertTrue(os.listdir(os.path.join(self.g= itdir, 'gitsubmodule'))) + =C2=A0 =C2=A0 =C2=A0 =C2=A0expected_submodule_revisions =3D 1 if shallow = else 2 + =C2=A0 =C2=A0 =C2=A0 =C2=A0self.assertRevCount(expected_submodule_revisio= ns, cwd=3Dos.path.join(self.gitdir, 'gitsubmodule')) + + =C2=A0 =C2=A0def test_submodule_premirroronly(self): + =C2=A0 =C2=A0 =C2=A0 =C2=A0"""Submodules must be fetched from a network P= REMIRRORS with BB_FETCH_PREMIRRORONLY""" + =C2=A0 =C2=A0 =C2=A0 =C2=A0self.check_submodule_premirroronly(shallow=3DF= alse) + + =C2=A0 =C2=A0def test_shallow_submodule_premirroronly(self): + =C2=A0 =C2=A0 =C2=A0 =C2=A0"""Shallow submodules must be fetched from a n= etwork PREMIRRORS with BB_FETCH_PREMIRRORONLY""" + =C2=A0 =C2=A0 =C2=A0 =C2=A0self.check_submodule_premirroronly(shallow=3DT= rue) + + =C2=A0 =C2=A0def test_submodule_premirroronly_no_upstream(self): + =C2=A0 =C2=A0 =C2=A0 =C2=A0"""A submodule missing from PREMIRRORS must no= t be fetched from upstream""" + =C2=A0 =C2=A0 =C2=A0 =C2=A0self.add_empty_file('a') + =C2=A0 =C2=A0 =C2=A0 =C2=A0sha =3D self.git('rev-parse HEAD', cwd=3Dself.= srcdir).strip() + =C2=A0 =C2=A0 =C2=A0 =C2=A0# Point the submodule at an unavailable upstre= am and add its gitlink to the parent. + =C2=A0 =C2=A0 =C2=A0 =C2=A0with open(os.path.join(self.srcdir, '.gitmodul= es'), 'w') as f: + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0f.write('[submodule "sub"]\n\tpa= th =3D sub\n\turl =3D https://git.invalid/sub.git\n') + =C2=A0 =C2=A0 =C2=A0 =C2=A0self.git('add .gitmodules', cwd=3Dself.srcdir) + =C2=A0 =C2=A0 =C2=A0 =C2=A0self.git('update-index --add --cacheinfo 16000= 0,%s,sub' % sha, cwd=3Dself.srcdir) + =C2=A0 =C2=A0 =C2=A0 =C2=A0self.git('commit -m submodule', cwd=3Dself.src= dir) + + =C2=A0 =C2=A0 =C2=A0 =C2=A0self.d.setVar('BB_GIT_SHALLOW', '0') + =C2=A0 =C2=A0 =C2=A0 =C2=A0self.d.setVar('BB_GENERATE_MIRROR_TARBALLS', '= 1') + =C2=A0 =C2=A0 =C2=A0 =C2=A0self.d.setVar('BB_GENERATE_SHALLOW_TARBALLS', = '0') + + =C2=A0 =C2=A0 =C2=A0 =C2=A0_, ud =3D self.fetch('git://%s;protocol=3Dfile= ;branch=3Dmaster' % self.srcdir) + =C2=A0 =C2=A0 =C2=A0 =C2=A0mirrordir =3D os.path.join(self.tempdir, 'mirr= or') + =C2=A0 =C2=A0 =C2=A0 =C2=A0bb.utils.rename(self.dldir, mirrordir) + =C2=A0 =C2=A0 =C2=A0 =C2=A0self.d.setVar('BB_GENERATE_MIRROR_TARBALLS', '= 0') + =C2=A0 =C2=A0 =C2=A0 =C2=A0bb.utils.remove(self.srcdir, recurse=3DTrue) + =C2=A0 =C2=A0 =C2=A0 =C2=A0bb.utils.mkdirhier(self.dldir) + + =C2=A0 =C2=A0 =C2=A0 =C2=A0self.use_http_premirror(mirrordir) + =C2=A0 =C2=A0 =C2=A0 =C2=A0# The missing submodule premirror must fail in= stead of falling back to upstream. + =C2=A0 =C2=A0 =C2=A0 =C2=A0with self.assertRaises(bb.fetch2.NetworkAccess= ) as cm: + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0self.fetch('gitsm://%s;protocol= =3Dfile;subdir=3D${S};branch=3Dmaster' % self.srcdir) + =C2=A0 =C2=A0 =C2=A0 =C2=A0self.assertIn('git.invalid', cm.exception.url) + if any(os.path.exists(os.path.join(p, 'git-annex')) for p in os.environ.get= ('PATH').split(':')): def test_shallow_annex(self): self.add_empty_file('a') --tlvtmbFVm8PFhoUU4OeX Content-Type: text/html; charset="utf-8" Content-Transfer-Encoding: quoted-printable
Hi Richard,

Thank you for the feedback. Below are new bitba= ke-selftest cases in
lib/bb/tests/fetch.py that show the issue, togeth= er with a possible fix.

Without the gitsm.py change, `test_submo= dule_premirroronly` and
`test_shallow_submodule_premirroronly` will fa= il:

Signed-off-by: Tiago Vasconcelos <tiago.mlb.vasconcelos@g= mail.com>
---

diff --git a/lib/bb/fetch2/gitsm.py b/lib/bb/fetch2/gitsm.py
index 5869e1b99..727462ea3 100644
--- a/lib/bb/fetch2/gitsm.py
= +++ b/lib/bb/fetch2/gitsm.py
@@ -194,6 +194,12 @@ class GitSM(Git):             # Is the following still= needed?
             #url +=3D ";n= ocheckout=3D1"
 
+            = # BB_NO_NETWORK may have been set by the parent fetch for its mirror
+=            # tarball. The submodule Fetch ap= plies BB_FETCH_PREMIRRORONLY itself,
+         &nb= sp;  # blocking upstream but still allowing PREMIRRORS.
+   =          if bb.utils.to_boolean(d.getVar("BB_FETCH= _PREMIRRORONLY")):
+               =  d.setVar("BB_NO_NETWORK", "0")
+
       = ;      try:
            &= nbsp;    newfetch =3D Fetch([url], d, cache=3DFalse)
  =                newfetch.download()<= br />diff --git a/lib/bb/tests/fetch.py b/lib/bb/tests/fetch.py
index = cc133c1f5..106643d82 100644
--- a/lib/bb/tests/fetch.py
+++ b/lib= /bb/tests/fetch.py
@@ -2092,6 +2092,102 @@ class GitShallowTest(Fetche= rTest):
         # Verify the submodule is al= so shallow
         self.assertRevCount(1, cw= d=3Dos.path.join(self.gitdir, 'gitsubmodule'))
 
+   &n= bsp;def use_http_premirror(self, mirrordir):
+       &n= bsp;# Serve the prepared downloads locally and allow this host in mirror-on= ly mode.
+        server =3D HTTPService(mirrordir= , host=3D'127.0.0.1')
+        server.start()
+        self.addCleanup(server.stop)
+   &n= bsp;    self.d.setVar('PREMIRRORS', 'gitsm://.*/.* http://127.0.0= .1:%s/' % server.port)
+        self.d.setVar('BB_= FETCH_PREMIRRORONLY', '1')
+        self.d.setVar(= 'BB_NO_NETWORK', '0')
+        self.d.setVar('BB_A= LLOWED_NETWORKS', '127.0.0.1')
+
+    def check_submodu= le_premirroronly(self, shallow):
+        if not s= hallow:
+            self.d.setVar('BB_G= IT_SHALLOW', '0')
+            self.d.se= tVar('BB_GENERATE_MIRROR_TARBALLS', '1')
+        =    self.d.setVar('BB_GENERATE_SHALLOW_TARBALLS', '0')
+
+        # Create a submodule with two commits so its= fetched history can be checked.
+        self.add= _empty_file('a')
+        self.add_empty_file('b')=
+
+        smdir =3D os.path.join(self.tempd= ir, 'gitsubmodule')
+        bb.utils.mkdirhier(sm= dir)
+        self.git_init(cwd=3Dsmdir)
+ &n= bsp;      # Make this look like it was cloned from a remote.= ..
+        self.git('config --add remote.origin.u= rl "%s"' % smdir, cwd=3Dsmdir)
+        self.git('= config --add remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"', cw= d=3Dsmdir)
+        self.add_empty_file('asub', cw= d=3Dsmdir)
+        self.add_empty_file('bsub', cw= d=3Dsmdir)
+
+        self.git('submodule ini= t', cwd=3Dself.srcdir)
+        self.git('-c proto= col.file.allow=3Dalways submodule add file://%s' % smdir, cwd=3Dself.srcdir= )
+        self.git('submodule update', cwd=3Dself= .srcdir)
+        self.git('commit -m submodule -a= ', cwd=3Dself.srcdir)
+
+        uri =3D 'git= sm://%s;protocol=3Dfile;subdir=3D${S};branch=3Dmaster' % self.srcdir
+=
+        # Fetch once to generate the mirror tarb= alls
+        self.fetch(uri)
+
+  =      # Stop generating tarballs during the mirror-only fetc= h.
+        self.d.setVar('BB_GENERATE_MIRROR_TARB= ALLS', '0')
+        self.d.setVar('BB_GENERATE_SH= ALLOW_TARBALLS', '0')
+        mirrordir =3D os.pa= th.join(self.tempdir, 'mirror')
+        bb.utils.= rename(self.dldir, mirrordir)
+        bb.utils.mk= dirhier(self.dldir)
+        # Remove the original= repositories so the fetch must use the premirror.
+     &nb= sp;  bb.utils.remove(self.gitdir, recurse=3DTrue)
+    =    bb.utils.remove(self.srcdir, recurse=3DTrue)
+   &n= bsp;    bb.utils.remove(smdir, recurse=3DTrue)
+
+ &nbs= p;      self.use_http_premirror(mirrordir)
+   &nb= sp;    self.fetch_and_unpack(uri)
+
+     &nb= sp;  # Shallow fetches retain only the tip commit; full fetches retain= all commits.
+        expected_revisions =3D 1 if= shallow else 3
+        self.assertRevCount(expec= ted_revisions)
+        self.assertTrue(os.listdir= (os.path.join(self.gitdir, 'gitsubmodule')))
+       &n= bsp;expected_submodule_revisions =3D 1 if shallow else 2
+   &nbs= p;    self.assertRevCount(expected_submodule_revisions, cwd=3Dos.= path.join(self.gitdir, 'gitsubmodule'))
+
+    def test= _submodule_premirroronly(self):
+        """Submod= ules must be fetched from a network PREMIRRORS with BB_FETCH_PREMIRRORONLY"= ""
+        self.check_submodule_premirroronly(sha= llow=3DFalse)
+
+    def test_shallow_submodule_premirr= oronly(self):
+        """Shallow submodules must = be fetched from a network PREMIRRORS with BB_FETCH_PREMIRRORONLY"""
+ =        self.check_submodule_premirroronly(shallow=3DTru= e)
+
+    def test_submodule_premirroronly_no_upstream(= self):
+        """A submodule missing from PREMIR= RORS must not be fetched from upstream"""
+        = ;self.add_empty_file('a')
+        sha =3D self.gi= t('rev-parse HEAD', cwd=3Dself.srcdir).strip()
+       =  # Point the submodule at an unavailable upstream and add its gitlink = to the parent.
+        with open(os.path.join(sel= f.srcdir, '.gitmodules'), 'w') as f:
+         &nb= sp;  f.write('[submodule "sub"]\n\tpath =3D sub\n\turl =3D https://git= .invalid/sub.git\n')
+        self.git('add .gitmo= dules', cwd=3Dself.srcdir)
+        self.git('upda= te-index --add --cacheinfo 160000,%s,sub' % sha, cwd=3Dself.srcdir)
+ =        self.git('commit -m submodule', cwd=3Dself.srcdi= r)
+
+        self.d.setVar('BB_GIT_SHALLOW',= '0')
+        self.d.setVar('BB_GENERATE_MIRROR_T= ARBALLS', '1')
+        self.d.setVar('BB_GENERATE= _SHALLOW_TARBALLS', '0')
+
+        _, ud =3D= self.fetch('git://%s;protocol=3Dfile;branch=3Dmaster' % self.srcdir)
= +        mirrordir =3D os.path.join(self.tempdir, 'mirr= or')
+        bb.utils.rename(self.dldir, mirrordi= r)
+        self.d.setVar('BB_GENERATE_MIRROR_TARB= ALLS', '0')
+        bb.utils.remove(self.srcdir, = recurse=3DTrue)
+        bb.utils.mkdirhier(self.d= ldir)
+
+        self.use_http_premirror(mirr= ordir)
+        # The missing submodule premirror = must fail instead of falling back to upstream.
+       =  with self.assertRaises(bb.fetch2.NetworkAccess) as cm:
+   =          self.fetch('gitsm://%s;protocol=3Dfile;su= bdir=3D${S};branch=3Dmaster' % self.srcdir)
+       &nb= sp;self.assertIn('git.invalid', cm.exception.url)
+
   =  if any(os.path.exists(os.path.join(p, 'git-annex')) for p in os.envi= ron.get('PATH').split(':')):
         def tes= t_shallow_annex(self):
             = ;self.add_empty_file('a')
--tlvtmbFVm8PFhoUU4OeX--