diff mbox series

[2/3] fetch2/git: Add offline build support for tags

Message ID 20250129112406.1660522-3-stefan-koch@siemens.com
State New
Headers show
Series fetch2/git: Improve shallow, lfs, and tag support | expand

Commit Message

Stefan Koch Jan. 29, 2025, 11:24 a.m. UTC
This adds support for offline builds when tags are used within `SRCREV`.
Offline building is enabled when `BB_NO_NETWORK = "1"` is set.

Signed-off-by: Stefan Koch <stefan-koch@siemens.com>
---
 lib/bb/fetch2/git.py | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

Comments

Alexander Kanavin Jan. 29, 2025, 11:34 a.m. UTC | #1
On Wed, 29 Jan 2025 at 12:24, Koch, Stefan via lists.openembedded.org
<stefan-koch=siemens.com@lists.openembedded.org> wrote:
> This adds support for offline builds when tags are used within `SRCREV`.

I'm not sure I understand the use case. Why not just specify commit id
in SRCREV?

We discourage using tags, as they can and do move around, breaking
reproducibility.

Alex
Alexander Kanavin Jan. 29, 2025, 1:20 p.m. UTC | #2
On Wed, 29 Jan 2025 at 12:24, Koch, Stefan via lists.openembedded.org
<stefan-koch=siemens.com@lists.openembedded.org> wrote:
>
> This adds support for offline builds when tags are used within `SRCREV`.
> Offline building is enabled when `BB_NO_NETWORK = "1"` is set.

I also forgot to mention there is this variable for the offline builds
situation:

   :term:`BB_SRCREV_POLICY`
      Defines the behavior of the fetcher when it interacts with source
      control systems and dynamic source revisions. The
      :term:`BB_SRCREV_POLICY` variable is useful when working without a
      network.

      The variable can be set using one of two policies:

      -  *cache* --- retains the value the system obtained previously rather
         than querying the source control system each time.

      -  *clear* --- queries the source controls system every time. With this
         policy, there is no cache. The "clear" policy is the default.

Does it not work for you? How?

Alex
diff mbox series

Patch

diff --git a/lib/bb/fetch2/git.py b/lib/bb/fetch2/git.py
index 6d87c2f18..7ac690bbe 100644
--- a/lib/bb/fetch2/git.py
+++ b/lib/bb/fetch2/git.py
@@ -270,13 +270,6 @@  class Git(FetchMethod):
 
         ud.setup_revisions(d)
 
-        for name in ud.names:
-            # Ensure any revision that doesn't look like a SHA-1 is translated into one
-            if not sha1_re.match(ud.revisions[name] or ''):
-                if ud.revisions[name]:
-                    ud.unresolvedrev[name] = ud.revisions[name]
-                ud.revisions[name] = self.latest_revision(ud, d, name)
-
         gitsrcname = '%s%s' % (ud.host.replace(':', '.'), ud.path.replace('/', '.').replace('*', '.').replace(' ','_').replace('(', '_').replace(')', '_'))
         if gitsrcname.startswith('.'):
             gitsrcname = gitsrcname[1:]
@@ -294,6 +287,13 @@  class Git(FetchMethod):
         ud.clonedir = os.path.join(gitdir, gitsrcname)
         ud.localfile = ud.clonedir
 
+        for name in ud.names:
+            # Ensure anything that doesn't look like a sha256 checksum/revision is translated into one
+            if not ud.revisions[name] or len(ud.revisions[name]) != 40  or (False in [c in "abcdef0123456789" for c in ud.revisions[name]]):
+                if ud.revisions[name]:
+                    ud.unresolvedrev[name] = ud.revisions[name]
+                ud.revisions[name] = self.latest_revision(ud, d, name)
+
         mirrortarball = 'git2_%s.tar.gz' % gitsrcname
         ud.fullmirror = os.path.join(dl_dir, mirrortarball)
         ud.mirrortarballs = [mirrortarball]
@@ -909,7 +909,11 @@  class Git(FetchMethod):
             repourl = self._get_repo_url(ud)
             cmd = "%s ls-remote %s %s" % \
                 (ud.basecmd, shlex.quote(repourl), search)
-            if ud.proto.lower() != 'file':
+
+            if bb.utils.to_boolean(d.getVar("BB_NO_NETWORK")):
+                cmd = "%s ls-remote file://%s %s" % \
+                    (ud.basecmd, shlex.quote(ud.clonedir), search)
+            elif ud.proto.lower() != 'file':
                 bb.fetch2.check_network_access(d, cmd, repourl)
             output = runfetchcmd(cmd, d, True)
             if not output: