summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Wolf <matthias.wolf@epfl.ch>2022-12-07 09:51:02 -0500
committerGitHub <noreply@github.com>2022-12-07 15:51:02 +0100
commit795031176700c7b1e51cdb198a9aef7db2ce994d (patch)
tree6e1167757b47e9535670b28ef2842a46c6098f2e
parent194f9a9ca97063c302a6fb0e4456b653a876315a (diff)
downloadspack-795031176700c7b1e51cdb198a9aef7db2ce994d.tar.gz
spack-795031176700c7b1e51cdb198a9aef7db2ce994d.tar.bz2
spack-795031176700c7b1e51cdb198a9aef7db2ce994d.tar.xz
spack-795031176700c7b1e51cdb198a9aef7db2ce994d.zip
likwid: add a permission fixing script a la singularity (#33503)
-rw-r--r--var/spack/repos/builtin/packages/likwid/package.py55
-rwxr-xr-xvar/spack/repos/builtin/packages/likwid/spack_perms_fix.sh.j211
2 files changed, 61 insertions, 5 deletions
diff --git a/var/spack/repos/builtin/packages/likwid/package.py b/var/spack/repos/builtin/packages/likwid/package.py
index 8b42efd0ba..20710f183c 100644
--- a/var/spack/repos/builtin/packages/likwid/package.py
+++ b/var/spack/repos/builtin/packages/likwid/package.py
@@ -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 @@ class Likwid(Package):
)
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 @@ class Likwid(Package):
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
+ )
+ )
diff --git a/var/spack/repos/builtin/packages/likwid/spack_perms_fix.sh.j2 b/var/spack/repos/builtin/packages/likwid/spack_perms_fix.sh.j2
new file mode 100755
index 0000000000..a3413d4d29
--- /dev/null
+++ b/var/spack/repos/builtin/packages/likwid/spack_perms_fix.sh.j2
@@ -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