Skip to content

Commit 62cc4d7

Browse files
authored
Merge pull request #77 from per1234/recurse-submodules
libraries/compile-examples: add support for submodules
2 parents 3f35832 + be46cb5 commit 62cc4d7

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

compilesketches/compilesketches.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,8 @@ def clone_repository(self, url, git_ref, destination_path):
630630
"""
631631
if git_ref is None:
632632
# Shallow clone is only possible if using the tip of the branch
633-
clone_arguments = {"depth": 1}
633+
# Use `None` as value for `git clone` options with no argument
634+
clone_arguments = {"depth": 1, "shallow-submodules": None, "recurse-submodules": True}
634635
else:
635636
clone_arguments = {}
636637
cloned_repository = git.Repo.clone_from(url=url, to_path=destination_path, **clone_arguments)
@@ -646,6 +647,7 @@ def clone_repository(self, url, git_ref, destination_path):
646647

647648
# checkout ref
648649
cloned_repository.git.checkout(git_ref)
650+
cloned_repository.git.submodule("update", "--init", "--recursive", "--recommend-shallow")
649651

650652
def install_platforms_from_download(self, platform_list):
651653
"""Install libraries by downloading them
@@ -894,7 +896,7 @@ def get_sketch_report(self, compilation_result):
894896
previous_compilation_result = self.compile_sketch(sketch_path=compilation_result.sketch)
895897

896898
# git checkout the head ref to return the repository to its previous state
897-
repository.git.checkout(original_git_ref)
899+
repository.git.checkout(original_git_ref, recurse_submodules=True)
898900

899901
previous_sizes = self.get_sizes_from_output(compilation_result=previous_compilation_result)
900902

@@ -1021,11 +1023,15 @@ def checkout_deltas_base_ref(self):
10211023

10221024
# git fetch the deltas base ref
10231025
origin_remote = repository.remotes["origin"]
1024-
origin_remote.fetch(refspec=self.deltas_base_ref, verbose=self.verbose, no_tags=True, prune=True,
1025-
depth=1)
1026+
origin_remote.fetch(refspec=self.deltas_base_ref,
1027+
verbose=self.verbose,
1028+
no_tags=True,
1029+
prune=True,
1030+
depth=1,
1031+
recurse_submodules=True)
10261032

10271033
# git checkout the deltas base ref
1028-
repository.git.checkout(self.deltas_base_ref)
1034+
repository.git.checkout(self.deltas_base_ref, recurse_submodules=True)
10291035

10301036
def get_sizes_report(self, current_sizes, previous_sizes):
10311037
"""Return a list containing all memory usage data assembled.

compilesketches/tests/test_compilesketches.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1364,7 +1364,7 @@ def checkout(self):
13641364
git.Repo.assert_called_once_with(path=os.environ["GITHUB_WORKSPACE"])
13651365
compile_sketches.checkout_deltas_base_ref.assert_called_once()
13661366
compile_sketches.compile_sketch.assert_called_once_with(compile_sketches, sketch_path=compilation_result.sketch)
1367-
Repo.checkout.assert_called_once_with(original_git_ref)
1367+
Repo.checkout.assert_called_once_with(original_git_ref, recurse_submodules=True)
13681368
get_sizes_from_output_calls.append(
13691369
unittest.mock.call(compile_sketches, compilation_result=previous_compilation_result))
13701370
expected_previous_sizes = sizes_list[1]
@@ -1646,9 +1646,11 @@ def checkout(self):
16461646
git.Repo.assert_called_once_with(path=os.environ["GITHUB_WORKSPACE"])
16471647
Repo.fetch.assert_called_once_with(refspec=deltas_base_ref,
16481648
verbose=compile_sketches.verbose,
1649-
no_tags=True, prune=True,
1650-
depth=1)
1651-
Repo.checkout.assert_called_once_with(deltas_base_ref)
1649+
no_tags=True,
1650+
prune=True,
1651+
depth=1,
1652+
recurse_submodules=True)
1653+
Repo.checkout.assert_called_once_with(deltas_base_ref, recurse_submodules=True)
16521654

16531655

16541656
def test_get_sizes_report(mocker):

0 commit comments

Comments
 (0)