diff --git a/lib/spack/spack/installer.py b/lib/spack/spack/installer.py index 3329b1a1ca3..5c529b08d38 100644 --- a/lib/spack/spack/installer.py +++ b/lib/spack/spack/installer.py @@ -2436,10 +2436,11 @@ def get_deptypes(self, pkg): else: cache_only = self.install_args.get("dependencies_cache_only") - # Include build dependencies if pkg is not installed and cache_only - # is False, or if build depdencies are explicitly called for - # by include_build_deps. - if include_build_deps or not (cache_only or pkg.spec.installed): + # Include build dependencies if pkg is going to be built from sources, or + # if build deps are explicitly requested. + if include_build_deps or not ( + cache_only or pkg.spec.installed and not pkg.spec.dag_hash() in self.overwrite + ): deptypes.append("build") if self.run_tests(pkg): deptypes.append("test") diff --git a/lib/spack/spack/test/installer.py b/lib/spack/spack/test/installer.py index 7b9c2b5184d..ba99c904841 100644 --- a/lib/spack/spack/test/installer.py +++ b/lib/spack/spack/test/installer.py @@ -1386,6 +1386,30 @@ def test_single_external_implicit_install(install_mockery, explicit_args, is_exp assert spack.store.db.get_record(pkg).explicit == is_explicit +@pytest.mark.skipif( + sys.platform == "win32", + reason="Windows breaks overwrite install due to prefix normalization inconsistencies", +) +def test_overwrite_install_does_install_build_deps(install_mockery, mock_fetch): + """When overwrite installing something from sources, build deps should be installed.""" + s = spack.spec.Spec("dtrun3").concretized() + create_installer([(s, {})]).install() + + # Verify there is a pure build dep + edge = s.edges_to_dependencies(name="dtbuild3").pop() + assert edge.deptypes == ("build",) + build_dep = edge.spec + + # Uninstall the build dep + build_dep.package.do_uninstall() + + # Overwrite install the root dtrun3 + create_installer([(s, {"overwrite": [s.dag_hash()]})]).install() + + # Verify that the build dep was also installed. + assert build_dep.installed + + @pytest.mark.parametrize("run_tests", [True, False]) def test_print_install_test_log_skipped(install_mockery, mock_packages, capfd, run_tests): """Confirm printing of install log skipped if not run/no failures."""