likwid: add a permission fixing script a la singularity (#33503)

This commit is contained in:
Matthias Wolf 2022-12-07 09:51:02 -05:00 committed by GitHub
parent 194f9a9ca9
commit 7950311767
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 61 additions and 5 deletions

View File

@ -6,6 +6,8 @@
import glob
import os
import llnl.util.tty as tty
from spack.package import *
@ -64,6 +66,13 @@ class Likwid(Package):
variant("fortran", default=True, description="with fortran interface")
variant("cuda", default=False, description="with Nvidia GPU profiling support")
variant(
"accessmode",
default="perf_event",
values=("perf_event", "accessdaemon"),
description="the default mode for MSR access",
)
# NOTE: There is no way to use an externally provided hwloc with Likwid.
# The reason is that the internal hwloc is patched to contain extra
# functionality and functions are prefixed with "likwid_".
@ -126,11 +135,17 @@ def install(self, spec, prefix):
)
filter_file("^PREFIX .*", "PREFIX = " + prefix, "config.mk")
# FIXME: once https://github.com/spack/spack/issues/4432 is
# resolved, install as root by default and remove this
filter_file("^ACCESSMODE .*", "ACCESSMODE = perf_event", "config.mk")
filter_file("^BUILDFREQ .*", "BUILDFREQ = false", "config.mk")
filter_file("^BUILDDAEMON .*", "BUILDDAEMON = false", "config.mk")
filter_file(
"^ACCESSMODE .*",
"ACCESSMODE = {}".format(spec.variants["accessmode"].value),
"config.mk",
)
if "accessmode=accessdaemon" in spec:
# Disable the chown, see the `spack_perms_fix` template and script
filter_file("^INSTALL_CHOWN .*", "INSTALL_CHOWN =", "config.mk")
else:
filter_file("^BUILDFREQ .*", "BUILDFREQ = false", "config.mk")
filter_file("^BUILDDAEMON .*", "BUILDDAEMON = false", "config.mk")
if "+fortran" in self.spec:
filter_file("^FORTRAN_INTERFACE .*", "FORTRAN_INTERFACE = true", "config.mk")
@ -187,3 +202,33 @@ def install(self, spec, prefix):
env["PWD"] = os.getcwd()
make()
make("install")
# Until tty output works better from build steps, this ends up in
# the build log. See https://github.com/spack/spack/pull/10412.
@run_after("install")
def caveats(self):
if "accessmode=accessdaemon" in self.spec:
perm_script = "spack_perms_fix.sh"
perm_script_path = join_path(self.spec.prefix, perm_script)
daemons = glob.glob(join_path(self.spec.prefix, "sbin", "*"))
with open(perm_script_path, "w") as f:
env = spack.tengine.make_environment(dirs=self.package_dir)
t = env.get_template(perm_script + ".j2")
f.write(
t.render({"prefix": self.spec.prefix, "chowns": daemons, "chmods": daemons})
)
tty.warn(
"""
For full functionality, you'll need to chown and chmod some files
after installing the package. This has security implications.
We've installed a script that will make the necessary changes;
read through it and then execute it as root (e.g. via sudo).
The script is named:
{0}
""".format(
perm_script_path
)
)

View File

@ -0,0 +1,11 @@
#!/bin/sh -eu
{% for cf in chowns %}
chown root:root {{ prefix }}/{{ cf }}
{% endfor %}
{% for sf in chmods %}
chmod 4755 {{ prefix }}/{{ sf }}
{% endfor %}
# end