public inbox for openembedded-core@lists.openembedded.org
 help / color / mirror / Atom feed
From: <rs@ti.com>
To: <paul@pbarker.dev>, <raj.khem@gmail.com>,
	<richard.purdie@linuxfoundation.org>,
	<mathieu.dubois-briand@bootlin.com>, <alex@linutronix.de>,
	<otavio@ossystems.com.br>, <kexin.hao@windriver.com>
Cc: <afd@ti.com>, <detheridge@ti.com>, <denis@denix.org>,
	<reatmon@ti.com>, <openembedded-core@lists.openembedded.org>,
	<vijayp@ti.com>
Subject: [oe-core][PATCHv3] reproducible: fix git SOURCE_DATE_EPOCH randomness
Date: Thu, 19 Feb 2026 19:54:16 -0600	[thread overview]
Message-ID: <20260220015416.67093-1-rs@ti.com> (raw)

From: Randolph Sapp <rs@ti.com>

Anything that defines multiple git sources should have the largest value
taken when calculating the SOURCE_DATE_EPOCH for a package.

The previous iteration actually introduced some degree of randomness, as
it would stop on the first git repository reported by os.walk, which
does not assure any specific ordering by default.

Signed-off-by: Randolph Sapp <rs@ti.com>
---

v2: Use os.walk method as opposed to glob to avoid infinite recursion when
navigating symbolic links

v3: Cover submodule / worktree related cases by using -C and checking for .git
files.

 meta/lib/oe/reproducible.py | 66 ++++++++++++++++---------------------
 1 file changed, 29 insertions(+), 37 deletions(-)

diff --git a/meta/lib/oe/reproducible.py b/meta/lib/oe/reproducible.py
index 0270024a83..a80376010a 100644
--- a/meta/lib/oe/reproducible.py
+++ b/meta/lib/oe/reproducible.py
@@ -74,52 +74,44 @@ def get_source_date_epoch_from_known_files(d, sourcedir):
         bb.debug(1, "SOURCE_DATE_EPOCH taken from: %s" % newest_file)
     return source_date_epoch

-def find_git_folder(d, sourcedir):
-    # First guess: UNPACKDIR/BB_GIT_DEFAULT_DESTSUFFIX
-    # This is the default git fetcher unpack path
+def find_git_repositories(d, sourcedir):
     unpackdir = d.getVar('UNPACKDIR')
-    default_destsuffix = d.getVar('BB_GIT_DEFAULT_DESTSUFFIX')
-    gitpath = os.path.join(unpackdir, default_destsuffix, ".git")
-    if os.path.isdir(gitpath):
-        return gitpath
-
-    # Second guess: ${S}
-    gitpath = os.path.join(sourcedir, ".git")
-    if os.path.isdir(gitpath):
-        return gitpath
-
-    # Perhaps there was a subpath or destsuffix specified.
-    # Go looking in the UNPACKDIR
-    for root, dirs, files in os.walk(unpackdir, topdown=True):
-        if '.git' in dirs:
-            return os.path.join(root, ".git")
+    git_repositories = []

-    for root, dirs, files in os.walk(sourcedir, topdown=True):
-        if '.git' in dirs:
-            return os.path.join(root, ".git")
+    for mainpath in (sourcedir, unpackdir):
+        for root, dirs, files in os.walk(mainpath, topdown=True):
+            if '.git' in dirs or '.git' in files:
+                git_repositories.append(root)

-    bb.warn("Failed to find a git repository in UNPACKDIR: %s" % unpackdir)
-    return None
+    if not git_repositories:
+        bb.warn('Failed to find any git repositories in UNPACKDIR or S')
+
+    return git_repositories

 def get_source_date_epoch_from_git(d, sourcedir):
     if not "git://" in d.getVar('SRC_URI') and not "gitsm://" in d.getVar('SRC_URI'):
         return None

-    gitpath = find_git_folder(d, sourcedir)
-    if not gitpath:
-        return None
+    # Get an epoch from all valid git repositories
+    source_dates = []
+    for repo_path in find_git_repositories(d, sourcedir):
+        # Check that the repository has a valid HEAD; it may not if subdir is used
+        # in SRC_URI
+        p = subprocess.run(['git', '-C', repo_path, 'rev-parse', 'HEAD'],
+                           check=False, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
+        if p.returncode != 0:
+            bb.debug(1, "%s does not have a valid HEAD: %s" % (repo_path, p.stdout.decode('utf-8')))
+            continue
+
+        bb.debug(1, "git repository: %s" % repo_path)
+        p = subprocess.run(['git', '-C', repo_path, 'log', '-1', '--pretty=%ct'],
+                           check=True, stdout=subprocess.PIPE)
+        source_dates.append(int(p.stdout.decode('utf-8')))
+
+    if source_dates:
+        return max(source_dates)

-    # Check that the repository has a valid HEAD; it may not if subdir is used
-    # in SRC_URI
-    p = subprocess.run(['git', '--git-dir', gitpath, 'rev-parse', 'HEAD'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
-    if p.returncode != 0:
-        bb.debug(1, "%s does not have a valid HEAD: %s" % (gitpath, p.stdout.decode('utf-8')))
-        return None
-
-    bb.debug(1, "git repository: %s" % gitpath)
-    p = subprocess.run(['git', '-c', 'log.showSignature=false', '--git-dir', gitpath, 'log', '-1', '--pretty=%ct'],
-                       check=True, stdout=subprocess.PIPE)
-    return int(p.stdout.decode('utf-8'))
+    return None

 def get_source_date_epoch_from_youngest_file(d, sourcedir):
     if sourcedir == d.getVar('UNPACKDIR'):
--
2.52.0



                 reply	other threads:[~2026-02-20  1:54 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260220015416.67093-1-rs@ti.com \
    --to=rs@ti.com \
    --cc=afd@ti.com \
    --cc=alex@linutronix.de \
    --cc=denis@denix.org \
    --cc=detheridge@ti.com \
    --cc=kexin.hao@windriver.com \
    --cc=mathieu.dubois-briand@bootlin.com \
    --cc=openembedded-core@lists.openembedded.org \
    --cc=otavio@ossystems.com.br \
    --cc=paul@pbarker.dev \
    --cc=raj.khem@gmail.com \
    --cc=reatmon@ti.com \
    --cc=richard.purdie@linuxfoundation.org \
    --cc=vijayp@ti.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox