canonicalize_path: add arch information to substitutions (#29810)
Co-authored-by: becker33 <becker33@users.noreply.github.com>
This commit is contained in:
parent
e550f48b17
commit
27e1d28c0b
@ -405,6 +405,17 @@ Spack understands several special variables. These are:
|
|||||||
* ``$user``: name of the current user
|
* ``$user``: name of the current user
|
||||||
* ``$user_cache_path``: user cache directory (``~/.spack`` unless
|
* ``$user_cache_path``: user cache directory (``~/.spack`` unless
|
||||||
:ref:`overridden <local-config-overrides>`)
|
:ref:`overridden <local-config-overrides>`)
|
||||||
|
* ``$architecture``: the architecture triple of the current host, as
|
||||||
|
detected by Spack.
|
||||||
|
* ``$arch``: alias for ``$architecture``.
|
||||||
|
* ``$platform``: the platform of the current host, as detected by Spack.
|
||||||
|
* ``$operating_system``: the operating system of the current host, as
|
||||||
|
detected by the ``distro`` python module.
|
||||||
|
* ``$os``: alias for ``$operating_system``.
|
||||||
|
* ``$target``: the ISA target for the current host, as detected by
|
||||||
|
ArchSpec. E.g. ``skylake`` or ``neoverse-n1``.
|
||||||
|
* ``$target_family``. The target family for the current host, as
|
||||||
|
detected by ArchSpec. E.g. ``x86_64`` or ``aarch64``.
|
||||||
|
|
||||||
Note that, as with shell variables, you can write these as ``$varname``
|
Note that, as with shell variables, you can write these as ``$varname``
|
||||||
or with braces to distinguish the variable from surrounding characters:
|
or with braces to distinguish the variable from surrounding characters:
|
||||||
|
@ -379,6 +379,17 @@ def test_substitute_config_variables(mock_low_high_config, monkeypatch):
|
|||||||
os.path.join(mock_low_high_config.scopes["low"].path, os.path.join("foo", "bar", "baz"))
|
os.path.join(mock_low_high_config.scopes["low"].path, os.path.join("foo", "bar", "baz"))
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# test architecture information is in replacements
|
||||||
|
assert spack_path.canonicalize_path(
|
||||||
|
os.path.join("foo", "$platform", "bar")
|
||||||
|
) == os.path.abspath(os.path.join("foo", "test", "bar"))
|
||||||
|
|
||||||
|
host_target = spack.platforms.host().target("default_target")
|
||||||
|
host_target_family = str(host_target.microarchitecture.family)
|
||||||
|
assert spack_path.canonicalize_path(
|
||||||
|
os.path.join("foo", "$target_family", "bar")
|
||||||
|
) == os.path.abspath(os.path.join("foo", host_target_family, "bar"))
|
||||||
|
|
||||||
|
|
||||||
packages_merge_low = {"packages": {"foo": {"variants": ["+v1"]}, "bar": {"variants": ["+v2"]}}}
|
packages_merge_low = {"packages": {"foo": {"variants": ["+v1"]}, "bar": {"variants": ["+v2"]}}}
|
||||||
|
|
||||||
|
@ -27,16 +27,37 @@
|
|||||||
__all__ = ["substitute_config_variables", "substitute_path_variables", "canonicalize_path"]
|
__all__ = ["substitute_config_variables", "substitute_path_variables", "canonicalize_path"]
|
||||||
|
|
||||||
|
|
||||||
|
def architecture():
|
||||||
|
# break circular import
|
||||||
|
import spack.platforms
|
||||||
|
import spack.spec
|
||||||
|
|
||||||
|
host_platform = spack.platforms.host()
|
||||||
|
host_os = host_platform.operating_system("default_os")
|
||||||
|
host_target = host_platform.target("default_target")
|
||||||
|
|
||||||
|
return spack.spec.ArchSpec((str(host_platform), str(host_os), str(host_target)))
|
||||||
|
|
||||||
|
|
||||||
# Substitutions to perform
|
# Substitutions to perform
|
||||||
def replacements():
|
def replacements():
|
||||||
# break circular import from spack.util.executable
|
# break circular import from spack.util.executable
|
||||||
import spack.paths
|
import spack.paths
|
||||||
|
|
||||||
|
arch = architecture()
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"spack": spack.paths.prefix,
|
"spack": spack.paths.prefix,
|
||||||
"user": getpass.getuser(),
|
"user": getpass.getuser(),
|
||||||
"tempdir": tempfile.gettempdir(),
|
"tempdir": tempfile.gettempdir(),
|
||||||
"user_cache_path": spack.paths.user_cache_path,
|
"user_cache_path": spack.paths.user_cache_path,
|
||||||
|
"architecture": str(arch),
|
||||||
|
"arch": str(arch),
|
||||||
|
"platform": str(arch.platform),
|
||||||
|
"operating_system": str(arch.os),
|
||||||
|
"os": str(arch.os),
|
||||||
|
"target": str(arch.target),
|
||||||
|
"target_family": str(arch.target.microarchitecture.family),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -245,6 +266,13 @@ def substitute_config_variables(path):
|
|||||||
- $tempdir Default temporary directory returned by tempfile.gettempdir()
|
- $tempdir Default temporary directory returned by tempfile.gettempdir()
|
||||||
- $user The current user's username
|
- $user The current user's username
|
||||||
- $user_cache_path The user cache directory (~/.spack, unless overridden)
|
- $user_cache_path The user cache directory (~/.spack, unless overridden)
|
||||||
|
- $architecture The spack architecture triple for the current system
|
||||||
|
- $arch The spack architecture triple for the current system
|
||||||
|
- $platform The spack platform for the current system
|
||||||
|
- $os The OS of the current system
|
||||||
|
- $operating_system The OS of the current system
|
||||||
|
- $target The ISA target detected for the system
|
||||||
|
- $target_family The family of the target detected for the system
|
||||||
|
|
||||||
These are substituted case-insensitively into the path, and users can
|
These are substituted case-insensitively into the path, and users can
|
||||||
use either ``$var`` or ``${var}`` syntax for the variables. $env is only
|
use either ``$var`` or ``${var}`` syntax for the variables. $env is only
|
||||||
|
Loading…
Reference in New Issue
Block a user