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.
This commit is contained in:
parent
b57d24a5e1
commit
5f59821433
@ -64,6 +64,7 @@
|
|||||||
import spack.subprocess_context
|
import spack.subprocess_context
|
||||||
import spack.user_environment
|
import spack.user_environment
|
||||||
import spack.util.path
|
import spack.util.path
|
||||||
|
import spack.util.pattern
|
||||||
from spack.error import NoHeadersError, NoLibrariesError
|
from spack.error import NoHeadersError, NoLibrariesError
|
||||||
from spack.installer import InstallError
|
from spack.installer import InstallError
|
||||||
from spack.util.cpus import cpus_available
|
from spack.util.cpus import cpus_available
|
||||||
@ -993,8 +994,24 @@ def add_modifications_for_dep(dep):
|
|||||||
dpkg = dep.package
|
dpkg = dep.package
|
||||||
if set_package_py_globals:
|
if set_package_py_globals:
|
||||||
set_module_variables_for_package(dpkg)
|
set_module_variables_for_package(dpkg)
|
||||||
|
|
||||||
# Allow dependencies to modify the module
|
# 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":
|
if context == "build":
|
||||||
dpkg.setup_dependent_build_environment(env, spec)
|
dpkg.setup_dependent_build_environment(env, spec)
|
||||||
else:
|
else:
|
||||||
|
@ -177,6 +177,14 @@ def _set_wrong_cc(x):
|
|||||||
assert os.environ["ANOTHER_VAR"] == "THIS_IS_SET"
|
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(
|
@pytest.mark.parametrize(
|
||||||
"initial,modifications,expected",
|
"initial,modifications,expected",
|
||||||
[
|
[
|
||||||
|
@ -0,0 +1,11 @@
|
|||||||
|
# Copyright 2013-2022 Lawrence Livermore National Security, LLC and other
|
||||||
|
# Spack Project Developers. See the top-level COPYRIGHT file for details.
|
||||||
|
#
|
||||||
|
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
|
||||||
|
|
||||||
|
from spack.package import * # noqa: F401
|
||||||
|
from spack.pkg.builtin.mock.cmake_client import CmakeClient
|
||||||
|
|
||||||
|
|
||||||
|
class CmakeClientInheritor(CmakeClient):
|
||||||
|
"""A dumy package that inherits from one using cmake."""
|
Loading…
Reference in New Issue
Block a user