diff options
author | Greg Becker <becker33@llnl.gov> | 2022-10-04 13:06:50 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-04 13:06:50 -0700 |
commit | 5f598214336716d5dd54bbf30327ea3fb9cea0e5 (patch) | |
tree | 01f02d9f45f8a8822c299bfd8a102dd48b4f3e85 /lib | |
parent | b57d24a5e1111912e4e2c3e50db54c87a88bbe53 (diff) | |
download | spack-5f598214336716d5dd54bbf30327ea3fb9cea0e5.tar.gz spack-5f598214336716d5dd54bbf30327ea3fb9cea0e5.tar.bz2 spack-5f598214336716d5dd54bbf30327ea3fb9cea0e5.tar.xz spack-5f598214336716d5dd54bbf30327ea3fb9cea0e5.zip |
BuildEnvironment: accumulate module changes to poke to all relevant modules (#32340)
Currently, module changes from `setup_dependent_package` are applied only to the module of the package class, but not to any parent classes' modules between the package class module and `spack.package_base`.
In this PR, we create a custom class to accumulate module changes, and apply those changes to each class that requires it. This design allows us to code for a single module, while applying the changes to multiple modules as needed under the hood, without requiring the user to reason about package inheritance.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/spack/spack/build_environment.py | 19 | ||||
-rw-r--r-- | lib/spack/spack/test/build_environment.py | 8 |
2 files changed, 26 insertions, 1 deletions
diff --git a/lib/spack/spack/build_environment.py b/lib/spack/spack/build_environment.py index 93ff1512a7..63b1309a22 100644 --- a/lib/spack/spack/build_environment.py +++ b/lib/spack/spack/build_environment.py @@ -64,6 +64,7 @@ import spack.store import spack.subprocess_context import spack.user_environment import spack.util.path +import spack.util.pattern from spack.error import NoHeadersError, NoLibrariesError from spack.installer import InstallError from spack.util.cpus import cpus_available @@ -993,8 +994,24 @@ def modifications_from_dependencies( dpkg = dep.package if set_package_py_globals: set_module_variables_for_package(dpkg) + # Allow dependencies to modify the module - dpkg.setup_dependent_package(spec.package.module, spec) + # Get list of modules that may need updating + modules = [] + for cls in inspect.getmro(type(spec.package)): + module = cls.module + if module == spack.package_base: + break + modules.append(module) + + # Execute changes as if on a single module + # copy dict to ensure prior changes are available + changes = spack.util.pattern.Bunch() + dpkg.setup_dependent_package(changes, spec) + + for module in modules: + module.__dict__.update(changes.__dict__) + if context == "build": dpkg.setup_dependent_build_environment(env, spec) else: diff --git a/lib/spack/spack/test/build_environment.py b/lib/spack/spack/test/build_environment.py index 41a5475c89..6ba8fc056f 100644 --- a/lib/spack/spack/test/build_environment.py +++ b/lib/spack/spack/test/build_environment.py @@ -177,6 +177,14 @@ def test_cc_not_changed_by_modules(monkeypatch, working_env): assert os.environ["ANOTHER_VAR"] == "THIS_IS_SET" +def test_setup_dependent_package_inherited_modules( + config, working_env, mock_packages, install_mockery, mock_fetch +): + # This will raise on regression + s = spack.spec.Spec("cmake-client-inheritor").concretized() + s.package.do_install() + + @pytest.mark.parametrize( "initial,modifications,expected", [ |