summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Scheibel <scheibel1@llnl.gov>2022-04-22 11:02:17 -0700
committerGitHub <noreply@github.com>2022-04-22 11:02:17 -0700
commit267da7855947933ffb360b6a7f003782c7df942b (patch)
treeca4d120020c4a6bd9500ec8e49c99c81a9b53efb
parent013a0a04a4b571c336f6639f9e51e991280391a4 (diff)
downloadspack-267da7855947933ffb360b6a7f003782c7df942b.tar.gz
spack-267da7855947933ffb360b6a7f003782c7df942b.tar.bz2
spack-267da7855947933ffb360b6a7f003782c7df942b.tar.xz
spack-267da7855947933ffb360b6a7f003782c7df942b.zip
Package-level submodule attribute: support explicit versions (#30085)
-rw-r--r--lib/spack/spack/fetch_strategy.py4
-rw-r--r--lib/spack/spack/test/conftest.py6
-rw-r--r--lib/spack/spack/test/git_fetch.py42
-rw-r--r--var/spack/repos/builtin.mock/packages/git-test/package.py2
-rw-r--r--var/spack/repos/builtin/packages/axom/package.py23
5 files changed, 64 insertions, 13 deletions
diff --git a/lib/spack/spack/fetch_strategy.py b/lib/spack/spack/fetch_strategy.py
index a8675550ff..378209308f 100644
--- a/lib/spack/spack/fetch_strategy.py
+++ b/lib/spack/spack/fetch_strategy.py
@@ -1575,6 +1575,10 @@ def _from_merged_attrs(fetcher, pkg, version):
attrs['fetch_options'] = pkg.fetch_options
attrs.update(pkg.versions[version])
+
+ if fetcher.url_attr == 'git' and hasattr(pkg, 'submodules'):
+ attrs.setdefault('submodules', pkg.submodules)
+
return fetcher(**attrs)
diff --git a/lib/spack/spack/test/conftest.py b/lib/spack/spack/test/conftest.py
index 420910b764..1a1b15f469 100644
--- a/lib/spack/spack/test/conftest.py
+++ b/lib/spack/spack/test/conftest.py
@@ -1364,6 +1364,12 @@ def mock_git_repository(tmpdir_factory):
),
'commit': Bunch(
revision=r1, file=r1_file, args={'git': url, 'commit': r1}
+ ),
+ # In this case, the version() args do not include a 'git' key:
+ # this is the norm for packages, so this tests how the fetching logic
+ # would most-commonly assemble a Git fetcher
+ 'master-no-per-version-git': Bunch(
+ revision='master', file=r0_file, args={'branch': 'master'}
)
}
diff --git a/lib/spack/spack/test/git_fetch.py b/lib/spack/spack/test/git_fetch.py
index acefb98175..5313fd8c8f 100644
--- a/lib/spack/spack/test/git_fetch.py
+++ b/lib/spack/spack/test/git_fetch.py
@@ -82,7 +82,8 @@ def test_bad_git(tmpdir, mock_bad_git):
fetcher.fetch()
-@pytest.mark.parametrize("type_of_test", ['master', 'branch', 'tag', 'commit'])
+@pytest.mark.parametrize("type_of_test",
+ ['master', 'branch', 'tag', 'commit'])
@pytest.mark.parametrize("secure", [True, False])
def test_fetch(type_of_test,
secure,
@@ -104,6 +105,11 @@ def test_fetch(type_of_test,
t = mock_git_repository.checks[type_of_test]
h = mock_git_repository.hash
+ pkg_class = spack.repo.path.get_pkg_class('git-test')
+ # This would fail using the master-no-per-version-git check but that
+ # isn't included in this test
+ monkeypatch.delattr(pkg_class, 'git')
+
# Construct the package under test
spec = Spec('git-test')
spec.concretize()
@@ -137,6 +143,40 @@ def test_fetch(type_of_test,
assert h('HEAD') == h(t.revision)
+@pytest.mark.disable_clean_stage_check
+def test_fetch_pkg_attr_submodule_init(
+ mock_git_repository,
+ config,
+ mutable_mock_repo,
+ monkeypatch,
+ mock_stage):
+ """In this case the version() args do not contain a 'git' URL, so
+ the fetcher must be assembled using the Package-level 'git' attribute.
+ This test ensures that the submodules are properly initialized and the
+ expected branch file is present.
+ """
+
+ t = mock_git_repository.checks['master-no-per-version-git']
+ pkg_class = spack.repo.path.get_pkg_class('git-test')
+ # For this test, the version args don't specify 'git' (which is
+ # the majority of version specifications)
+ monkeypatch.setattr(pkg_class, 'git', mock_git_repository.url)
+
+ # Construct the package under test
+ spec = Spec('git-test')
+ spec.concretize()
+ pkg = spack.repo.get(spec)
+ monkeypatch.setitem(pkg.versions, ver('git'), t.args)
+
+ spec.package.do_stage()
+
+ collected_fnames = set()
+ for root, dirs, files in os.walk(spec.package.stage.source_path):
+ collected_fnames.update(files)
+ # The submodules generate files with the prefix "r0_file_"
+ assert set(['r0_file_0', 'r0_file_1', t.file]) < collected_fnames
+
+
@pytest.mark.skipif(str(spack.platforms.host()) == 'windows',
reason=('Git fails to clone because the src/dst paths'
' are too long: the name of the staging directory'
diff --git a/var/spack/repos/builtin.mock/packages/git-test/package.py b/var/spack/repos/builtin.mock/packages/git-test/package.py
index ab72e5921e..f9ae590e9a 100644
--- a/var/spack/repos/builtin.mock/packages/git-test/package.py
+++ b/var/spack/repos/builtin.mock/packages/git-test/package.py
@@ -9,6 +9,8 @@ from spack import *
class GitTest(Package):
"""Mock package that uses git for fetching."""
homepage = "http://www.git-fetch-example.com"
+ # To be set by test
+ git = None
submodules = True
diff --git a/var/spack/repos/builtin/packages/axom/package.py b/var/spack/repos/builtin/packages/axom/package.py
index 7b02b25c56..3bbd896603 100644
--- a/var/spack/repos/builtin/packages/axom/package.py
+++ b/var/spack/repos/builtin/packages/axom/package.py
@@ -38,21 +38,20 @@ class Axom(CachedCMakePackage, CudaPackage):
git = "https://github.com/LLNL/axom.git"
tags = ['radiuss']
- version('main', branch='main', submodules=True)
- version('develop', branch='develop', submodules=True)
- version('0.6.1', tag='v0.6.1', submodules=True)
- version('0.6.0', tag='v0.6.0', submodules=True)
- version('0.5.0', tag='v0.5.0', submodules=True)
- version('0.4.0', tag='v0.4.0', submodules=True)
- version('0.3.3', tag='v0.3.3', submodules=True)
- version('0.3.2', tag='v0.3.2', submodules=True)
- version('0.3.1', tag='v0.3.1', submodules=True)
- version('0.3.0', tag='v0.3.0', submodules=True)
- version('0.2.9', tag='v0.2.9', submodules=True)
+ version('main', branch='main')
+ version('develop', branch='develop')
+ version('0.6.1', tag='v0.6.1')
+ version('0.6.0', tag='v0.6.0')
+ version('0.5.0', tag='v0.5.0')
+ version('0.4.0', tag='v0.4.0')
+ version('0.3.3', tag='v0.3.3')
+ version('0.3.2', tag='v0.3.2')
+ version('0.3.1', tag='v0.3.1')
+ version('0.3.0', tag='v0.3.0')
+ version('0.2.9', tag='v0.2.9')
@property
def submodules(self):
- # All git checkouts should also initialize submodules
return True
patch('scr_examples_gtest.patch', when='@0.6.0:0.6.1')