diff options
author | Dan Lipsa <dan.lipsa@kitware.com> | 2024-09-06 20:54:09 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-06 18:54:09 -0600 |
commit | 6f08db463149efdea126abf8fdc770f684b4199d (patch) | |
tree | 43a898f7811a6c95efc4567f57942d0e32e80f18 /lib | |
parent | 7086d6f1ac9838ddc05b906e80e71cfbba7125ae (diff) | |
download | spack-6f08db463149efdea126abf8fdc770f684b4199d.tar.gz spack-6f08db463149efdea126abf8fdc770f684b4199d.tar.bz2 spack-6f08db463149efdea126abf8fdc770f684b4199d.tar.xz spack-6f08db463149efdea126abf8fdc770f684b4199d.zip |
Set module variables for all packages before running setup_dependent_package (#44327)
When a package is running `setup_dependent_package` on a parent, ensure
that module variables like `spack_cc` are available. This was often
true prior to this commit, but externals were an exception.
---------
Co-authored-by: John Parent <john.parent@kitware.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/spack/spack/build_environment.py | 7 | ||||
-rw-r--r-- | lib/spack/spack/test/build_environment.py | 24 |
2 files changed, 30 insertions, 1 deletions
diff --git a/lib/spack/spack/build_environment.py b/lib/spack/spack/build_environment.py index e807bf6fd0..e95a904217 100644 --- a/lib/spack/spack/build_environment.py +++ b/lib/spack/spack/build_environment.py @@ -1003,7 +1003,6 @@ class SetupContext: """Set the globals in modules of package.py files.""" for dspec, flag in chain(self.external, self.nonexternal): pkg = dspec.package - if self.should_set_package_py_globals & flag: if self.context == Context.BUILD and self.needs_build_context & flag: set_package_py_globals(pkg, context=Context.BUILD) @@ -1011,6 +1010,12 @@ class SetupContext: # This includes runtime dependencies, also runtime deps of direct build deps. set_package_py_globals(pkg, context=Context.RUN) + # Looping over the set of packages a second time + # ensures all globals are loaded into the module space prior to + # any package setup. This guarantees package setup methods have + # access to expected module level definitions such as "spack_cc" + for dspec, flag in chain(self.external, self.nonexternal): + pkg = dspec.package for spec in dspec.dependents(): # Note: some specs have dependents that are unreachable from the root, so avoid # setting globals for those. diff --git a/lib/spack/spack/test/build_environment.py b/lib/spack/spack/test/build_environment.py index 3ae41acc9c..02f0a27f46 100644 --- a/lib/spack/spack/test/build_environment.py +++ b/lib/spack/spack/test/build_environment.py @@ -513,6 +513,30 @@ def test_setting_dtags_based_on_config(config_setting, expected_flag, config, mo assert dtags_to_add.value == expected_flag +def test_module_globals_available_at_setup_dependent_time( + monkeypatch, mutable_config, mock_packages, working_env +): + """Spack built package externaltest depends on an external package + externaltool. Externaltool's setup_dependent_package needs to be able to + access globals on the dependent""" + + def setup_dependent_package(module, dependent_spec): + # Make sure set_package_py_globals was already called on + # dependents + # ninja is always set by the setup context and is not None + dependent_module = dependent_spec.package.module + assert hasattr(dependent_module, "ninja") + assert dependent_module.ninja is not None + dependent_spec.package.test_attr = True + + externaltool = spack.spec.Spec("externaltest").concretized() + monkeypatch.setattr( + externaltool["externaltool"].package, "setup_dependent_package", setup_dependent_package + ) + spack.build_environment.setup_package(externaltool.package, False) + assert externaltool.package.test_attr + + def test_build_jobs_sequential_is_sequential(): assert ( determine_number_of_jobs( |