diff --git a/lib/spack/spack/environment/environment.py b/lib/spack/spack/environment/environment.py index 7877a847645..d13f1edf3a1 100644 --- a/lib/spack/spack/environment/environment.py +++ b/lib/spack/spack/environment/environment.py @@ -2634,6 +2634,29 @@ def _ensure_env_dir(): shutil.copy(envfile, target_manifest) + # Copy relative path includes that live inside the environment dir + try: + manifest = EnvironmentManifestFile(environment_dir) + except Exception as e: + msg = f"cannot initialize environment, '{environment_dir}' from manifest" + raise SpackEnvironmentError(msg) from e + else: + includes = manifest[TOP_LEVEL_KEY].get("include", []) + for include in includes: + if os.path.isabs(include): + continue + + abspath = pathlib.Path(os.path.normpath(environment_dir / include)) + if not abspath.is_relative_to(environment_dir): + # Warn that we are not copying relative path + msg = "Spack will not copy relative include path from outside environment" + msg += f" directory: {include}" + tty.warn(msg) + continue + + orig_abspath = os.path.normpath(envfile.parent / include) + shutil.copy(orig_abspath, abspath) + class EnvironmentManifestFile(collections.abc.Mapping): """Manages the in-memory representation of a manifest file, and its synchronization