compiler specs: do not print '@=' when clear from context (#37787)

Ensure that spack compiler add/find/list and lists of concrete specs
print the compiler effectively as {compiler.name}{@compiler.version}.

Co-authored-by: Harmen Stoppels <harmenstoppels@gmail.com>
This commit is contained in:
Greg Becker 2023-05-19 02:31:27 -07:00 committed by GitHub
parent ac0903ef9f
commit 16e9279420
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 22 additions and 12 deletions

View File

@ -347,7 +347,7 @@ def iter_groups(specs, indent, all_headers):
spack.spec.architecture_color, spack.spec.architecture_color,
architecture if architecture else "no arch", architecture if architecture else "no arch",
spack.spec.compiler_color, spack.spec.compiler_color,
f"{compiler}" if compiler else "no compiler", f"{compiler.display_str}" if compiler else "no compiler",
) )
# Sometimes we want to display specs that are not yet concretized. # Sometimes we want to display specs that are not yet concretized.

View File

@ -98,7 +98,7 @@ def compiler_find(args):
config = spack.config.config config = spack.config.config
filename = config.get_config_filename(args.scope, "compilers") filename = config.get_config_filename(args.scope, "compilers")
tty.msg("Added %d new compiler%s to %s" % (n, s, filename)) tty.msg("Added %d new compiler%s to %s" % (n, s, filename))
colify(reversed(sorted(c.spec for c in new_compilers)), indent=4) colify(reversed(sorted(c.spec.display_str for c in new_compilers)), indent=4)
else: else:
tty.msg("Found no new compilers") tty.msg("Found no new compilers")
tty.msg("Compilers are defined in the following files:") tty.msg("Compilers are defined in the following files:")
@ -112,13 +112,13 @@ def compiler_remove(args):
tty.die("No compilers match spec %s" % cspec) tty.die("No compilers match spec %s" % cspec)
elif not args.all and len(compilers) > 1: elif not args.all and len(compilers) > 1:
tty.error("Multiple compilers match spec %s. Choose one:" % cspec) tty.error("Multiple compilers match spec %s. Choose one:" % cspec)
colify(reversed(sorted([c.spec for c in compilers])), indent=4) colify(reversed(sorted([c.spec.display_str for c in compilers])), indent=4)
tty.msg("Or, use `spack compiler remove -a` to remove all of them.") tty.msg("Or, use `spack compiler remove -a` to remove all of them.")
sys.exit(1) sys.exit(1)
for compiler in compilers: for compiler in compilers:
spack.compilers.remove_compiler_from_config(compiler.spec, scope=args.scope) spack.compilers.remove_compiler_from_config(compiler.spec, scope=args.scope)
tty.msg("Removed compiler %s" % compiler.spec) tty.msg("Removed compiler %s" % compiler.spec.display_str)
def compiler_info(args): def compiler_info(args):
@ -130,7 +130,7 @@ def compiler_info(args):
tty.die("No compilers match spec %s" % cspec) tty.die("No compilers match spec %s" % cspec)
else: else:
for c in compilers: for c in compilers:
print(str(c.spec) + ":") print(c.spec.display_str + ":")
print("\tpaths:") print("\tpaths:")
for cpath in ["cc", "cxx", "f77", "fc"]: for cpath in ["cc", "cxx", "f77", "fc"]:
print("\t\t%s = %s" % (cpath, getattr(c, cpath, None))) print("\t\t%s = %s" % (cpath, getattr(c, cpath, None)))
@ -188,7 +188,7 @@ def compiler_list(args):
os_str += "-%s" % target os_str += "-%s" % target
cname = "%s{%s} %s" % (spack.spec.compiler_color, name, os_str) cname = "%s{%s} %s" % (spack.spec.compiler_color, name, os_str)
tty.hline(colorize(cname), char="-") tty.hline(colorize(cname), char="-")
colify(reversed(sorted(c.spec for c in compilers))) colify(reversed(sorted(c.spec.display_str for c in compilers)))
def compiler(parser, args): def compiler(parser, args):

View File

@ -679,6 +679,16 @@ def from_dict(d):
d = d["compiler"] d = d["compiler"]
return CompilerSpec(d["name"], vn.VersionList.from_dict(d)) return CompilerSpec(d["name"], vn.VersionList.from_dict(d))
@property
def display_str(self):
"""Equivalent to {compiler.name}{@compiler.version} for Specs, without extra
@= for readability."""
if self.concrete:
return f"{self.name}@{self.version}"
elif self.versions != vn.any_version:
return f"{self.name}@{self.versions}"
return self.name
def __str__(self): def __str__(self):
out = self.name out = self.name
if self.versions and self.versions != vn.any_version: if self.versions and self.versions != vn.any_version:
@ -1730,14 +1740,14 @@ def traverse_edges(self, **kwargs):
def short_spec(self): def short_spec(self):
"""Returns a version of the spec with the dependencies hashed """Returns a version of the spec with the dependencies hashed
instead of completely enumerated.""" instead of completely enumerated."""
spec_format = "{name}{@version}{%compiler}" spec_format = "{name}{@version}{%compiler.name}{@compiler.version}"
spec_format += "{variants}{arch=architecture}{/hash:7}" spec_format += "{variants}{arch=architecture}{/hash:7}"
return self.format(spec_format) return self.format(spec_format)
@property @property
def cshort_spec(self): def cshort_spec(self):
"""Returns an auto-colorized version of ``self.short_spec``.""" """Returns an auto-colorized version of ``self.short_spec``."""
spec_format = "{name}{@version}{%compiler}" spec_format = "{name}{@version}{%compiler.name}{@compiler.version}"
spec_format += "{variants}{arch=architecture}{/hash:7}" spec_format += "{variants}{arch=architecture}{/hash:7}"
return self.cformat(spec_format) return self.cformat(spec_format)

View File

@ -204,8 +204,8 @@ def test_compiler_find_mixed_suffixes(no_compilers_yaml, working_env, clangdir):
os.environ["PATH"] = str(clangdir) os.environ["PATH"] = str(clangdir)
output = compiler("find", "--scope=site") output = compiler("find", "--scope=site")
assert "clang@=11.0.0" in output assert "clang@11.0.0" in output
assert "gcc@=8.4.0" in output assert "gcc@8.4.0" in output
config = spack.compilers.get_compiler_config("site", False) config = spack.compilers.get_compiler_config("site", False)
clang = next(c["compiler"] for c in config if c["compiler"]["spec"] == "clang@=11.0.0") clang = next(c["compiler"] for c in config if c["compiler"]["spec"] == "clang@=11.0.0")
@ -246,8 +246,8 @@ def test_compiler_find_prefer_no_suffix(no_compilers_yaml, working_env, clangdir
os.environ["PATH"] = str(clangdir) os.environ["PATH"] = str(clangdir)
output = compiler("find", "--scope=site") output = compiler("find", "--scope=site")
assert "clang@=11.0.0" in output assert "clang@11.0.0" in output
assert "gcc@=8.4.0" in output assert "gcc@8.4.0" in output
config = spack.compilers.get_compiler_config("site", False) config = spack.compilers.get_compiler_config("site", False)
clang = next(c["compiler"] for c in config if c["compiler"]["spec"] == "clang@=11.0.0") clang = next(c["compiler"] for c in config if c["compiler"]["spec"] == "clang@=11.0.0")