diff mbox series

[kirkstone,master] externalsrc: fix host git >=2.38.1

Message ID 20221117213914.3598174-1-adrian.freihofer@siemens.com
State New, archived
Headers show
Series [kirkstone,master] externalsrc: fix host git >=2.38.1 | expand

Commit Message

Adrian Freihofer Nov. 17, 2022, 9:39 p.m. UTC
This is a fix for 0533edac277080e1bd130c14df0cbac61ba01a0c.

If the externalsrc directory is a git repository without submodules
  git config --file .gitmodules --get-regexp path
exits with 1. This leads to a subprocess.CalledProcessError exception:

bb.data_smart.ExpansionError: Failure expanding variable do_compile[file-checksums],
  expression was ${@srctree_hash_files(d)} which triggered exception
  CalledProcessError: Command '['git', 'config', '--file', '.gitmodules',
  '--get-regexp', 'path']' returned non-zero exit status 1.
The variable dependency chain for the failure is: do_compile[file-checksums]

Signed-off-by: Adrian Freihofer <adrian.freihofer@siemens.com>
---
 meta/classes/externalsrc.bbclass | 21 ++++++++++++---------
 1 file changed, 12 insertions(+), 9 deletions(-)
diff mbox series

Patch

diff --git a/meta/classes/externalsrc.bbclass b/meta/classes/externalsrc.bbclass
index 75fb91bcb0..2f2e00aab4 100644
--- a/meta/classes/externalsrc.bbclass
+++ b/meta/classes/externalsrc.bbclass
@@ -231,15 +231,18 @@  def srctree_hash_files(d, srcdir=None):
             subprocess.check_output(['git', 'add', '-A', '.'], cwd=s_dir, env=env)
             git_sha1 = subprocess.check_output(['git', 'write-tree'], cwd=s_dir, env=env).decode("utf-8")
             if os.path.exists(".gitmodules"):
-                submodule_helper = subprocess.check_output(["git", "config", "--file", ".gitmodules", "--get-regexp", "path"], cwd=s_dir, env=env).decode("utf-8")
-                for line in submodule_helper.splitlines():
-                    module_dir = os.path.join(s_dir, line.rsplit(maxsplit=1)[1])
-                    if os.path.isdir(module_dir):
-                        proc = subprocess.Popen(['git', 'add', '-A', '.'], cwd=module_dir, env=env, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
-                        proc.communicate()
-                        proc = subprocess.Popen(['git', 'write-tree'], cwd=module_dir, env=env, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL)
-                        stdout, _ = proc.communicate()
-                        git_sha1 += stdout.decode("utf-8")
+                try:
+                    submodule_helper = subprocess.check_output(["git", "config", "--file", ".gitmodules", "--get-regexp", "path"], cwd=s_dir, env=env).decode("utf-8")
+                    for line in submodule_helper.splitlines():
+                        module_dir = os.path.join(s_dir, line.rsplit(maxsplit=1)[1])
+                        if os.path.isdir(module_dir):
+                            proc = subprocess.Popen(['git', 'add', '-A', '.'], cwd=module_dir, env=env, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
+                            proc.communicate()
+                            proc = subprocess.Popen(['git', 'write-tree'], cwd=module_dir, env=env, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL)
+                            stdout, _ = proc.communicate()
+                            git_sha1 += stdout.decode("utf-8")
+                except subprocess.CalledProcessError:
+                    pass
             sha1 = hashlib.sha1(git_sha1.encode("utf-8")).hexdigest()
         with open(oe_hash_file, 'w') as fobj:
             fobj.write(sha1)