]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Support copying git submodule files 232/head
authorLucas De Marchi <lucas.demarchi@intel.com>
Thu, 8 Feb 2018 00:23:30 +0000 (16:23 -0800)
committerLucas De Marchi <lucas.demarchi@intel.com>
Thu, 8 Feb 2018 00:23:30 +0000 (16:23 -0800)
Besides getting the files from the git directory, iterate through each
submodules to copy them over to the build image as well. We had some
(better) alternative, but each of them failing to provide what we need:

    - Recent versions for git-ls-files learned a --recurse-submodules
      but they are not support together with --others

    - git-submodule foreach --recursive would allow us to git-ls-files
      inside each submodule, however there's no easy way to control from
      which submodule the command is printing the files in order to
      prepend the submodule path

So for now we live with getting the list of submodules from
`git submodule status --recursive` and calling git-ls-files on each of
them.

mkosi

diff --git a/mkosi b/mkosi
index 97413547fcc1329d5e05ae521da7e9a7c7bc4237..22a994807b5a063846b18156fc7188966ab5d81b 100755 (executable)
--- a/mkosi
+++ b/mkosi
@@ -1714,6 +1714,25 @@ def copy_git_files(src, dest, *, git_files):
             check=True)
     files = {x.decode("utf-8") for x in c.stdout.rstrip(b'\0').split(b'\0')}
 
+    # Get submodule files
+    c = run(['git', '-C', src, 'submodule', 'status', '--recursive'],
+            stdout=PIPE,
+            universal_newlines=True,
+            check=True)
+    submodules = {x.split()[1] for x in c.stdout.splitlines()}
+
+    # workaround for git-ls-files returning the path of submodules that we will
+    # still parse
+    files -= submodules
+
+    for sm in submodules:
+        c = run(['git', '-C', os.path.join(src, sm), 'ls-files', '-z'] + what_files,
+                stdout=PIPE,
+                universal_newlines=False,
+                check=True)
+        files |= {os.path.join(sm, x.decode("utf-8"))for x in c.stdout.rstrip(b'\0').split(b'\0')}
+        files -= submodules
+
     del c
 
     for path in files: