summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorTim Fuller <tjfulle@sandia.gov>2024-02-15 23:36:37 -0700
committerGitHub <noreply@github.com>2024-02-15 22:36:37 -0800
commit79087d08d96b71f373525ffc8f9b6cf9a4acd38b (patch)
treeab3d6e9948b2540fe8bedc0e4967bece65c22b7c /lib
parentd31e503e5bdb0e99fb5d26824a2caf4a6ca44298 (diff)
downloadspack-79087d08d96b71f373525ffc8f9b6cf9a4acd38b.tar.gz
spack-79087d08d96b71f373525ffc8f9b6cf9a4acd38b.tar.bz2
spack-79087d08d96b71f373525ffc8f9b6cf9a4acd38b.tar.xz
spack-79087d08d96b71f373525ffc8f9b6cf9a4acd38b.zip
allow packages to request no submodules be updated (#40409)
* allow packages to request no submodules be updated when self.submodules is a callable function * Extend the test added in Allow more fine-grained control over what submodules are updated: part 2 #27293 to include this case * Update the type signature for the submodules arg of version() in directives.py --------- Co-authored-by: tjfulle <tjfulle@users.noreply.github.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/spack/directives.py8
-rw-r--r--lib/spack/spack/fetch_strategy.py9
-rw-r--r--lib/spack/spack/test/git_fetch.py27
3 files changed, 39 insertions, 5 deletions
diff --git a/lib/spack/spack/directives.py b/lib/spack/spack/directives.py
index 2524562428..feb0412d84 100644
--- a/lib/spack/spack/directives.py
+++ b/lib/spack/spack/directives.py
@@ -34,7 +34,7 @@ import collections.abc
import functools
import os.path
import re
-from typing import Any, Callable, List, Optional, Set, Tuple, Union
+from typing import TYPE_CHECKING, Any, Callable, List, Optional, Set, Tuple, Union
import llnl.util.lang
import llnl.util.tty.color
@@ -57,6 +57,9 @@ from spack.version import (
VersionLookupError,
)
+if TYPE_CHECKING:
+ import spack.package_base
+
__all__ = [
"DirectiveError",
"DirectiveMeta",
@@ -349,6 +352,7 @@ class DirectiveMeta(type):
return _decorator
+SubmoduleCallback = Callable[["spack.package_base.PackageBase"], Union[str, List[str], bool]]
directive = DirectiveMeta.directive
@@ -380,7 +384,7 @@ def version(
tag: Optional[str] = None,
branch: Optional[str] = None,
get_full_repo: Optional[bool] = None,
- submodules: Optional[bool] = None,
+ submodules: Union[SubmoduleCallback, Optional[bool]] = None,
submodules_delete: Optional[bool] = None,
# other version control
svn: Optional[str] = None,
diff --git a/lib/spack/spack/fetch_strategy.py b/lib/spack/spack/fetch_strategy.py
index 9393a7c78b..c803b304c2 100644
--- a/lib/spack/spack/fetch_strategy.py
+++ b/lib/spack/spack/fetch_strategy.py
@@ -929,9 +929,12 @@ class GitFetchStrategy(VCSFetchStrategy):
git_commands = []
submodules = self.submodules
if callable(submodules):
- submodules = list(submodules(self.package))
- git_commands.append(["submodule", "init", "--"] + submodules)
- git_commands.append(["submodule", "update", "--recursive"])
+ submodules = submodules(self.package)
+ if submodules:
+ if isinstance(submodules, str):
+ submodules = [submodules]
+ git_commands.append(["submodule", "init", "--"] + submodules)
+ git_commands.append(["submodule", "update", "--recursive"])
elif submodules:
git_commands.append(["submodule", "update", "--init", "--recursive"])
diff --git a/lib/spack/spack/test/git_fetch.py b/lib/spack/spack/test/git_fetch.py
index a68eccb2a5..52b164e422 100644
--- a/lib/spack/spack/test/git_fetch.py
+++ b/lib/spack/spack/test/git_fetch.py
@@ -363,3 +363,30 @@ def test_gitsubmodules_delete(
assert not os.path.isdir(file_path)
file_path = os.path.join(s.package.stage.source_path, "third_party/submodule1")
assert not os.path.isdir(file_path)
+
+
+@pytest.mark.disable_clean_stage_check
+def test_gitsubmodules_falsey(
+ mock_git_repository, default_mock_concretization, mutable_mock_repo, monkeypatch
+):
+ """
+ Test GitFetchStrategy behavior when callable submodules returns Falsey
+ """
+
+ def submodules_callback(package):
+ return False
+
+ type_of_test = "tag-branch"
+ t = mock_git_repository.checks[type_of_test]
+
+ # Construct the package under test
+ s = default_mock_concretization("git-test")
+ args = copy.copy(t.args)
+ args["submodules"] = submodules_callback
+ monkeypatch.setitem(s.package.versions, Version("git"), args)
+ s.package.do_stage()
+ with working_dir(s.package.stage.source_path):
+ file_path = os.path.join(s.package.stage.source_path, "third_party/submodule0/r0_file_0")
+ assert not os.path.isfile(file_path)
+ file_path = os.path.join(s.package.stage.source_path, "third_party/submodule1/r0_file_1")
+ assert not os.path.isfile(file_path)