From 5505c443bf4dd939b94b02c441c8d28c6b3884fb Mon Sep 17 00:00:00 2001 From: Andrew-Dunning-NNL <67964561+Andrew-Dunning-NNL@users.noreply.github.com> Date: Wed, 27 Jul 2022 17:06:07 -0400 Subject: [PATCH] ZSH: add lmod and local etc variants (#29651) * zsh: add lmod and local etc support * zsh: fix indentation --- .../repos/builtin/packages/zsh/package.py | 36 ++++++++++++++++--- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/var/spack/repos/builtin/packages/zsh/package.py b/var/spack/repos/builtin/packages/zsh/package.py index 12979114c6..3624536119 100644 --- a/var/spack/repos/builtin/packages/zsh/package.py +++ b/var/spack/repos/builtin/packages/zsh/package.py @@ -27,16 +27,44 @@ class Zsh(AutotoolsPackage): # although the name of the option has evolved since then. variant('skip-tcsetpgrp-test', default=True, description="Skip configure's tcsetpgrp test") + variant('etcdir', default=False, + description='enable etc dir local to install, for global zsh scripts') + variant('lmod', default=False, + description='setup zshrc env for lmod support') depends_on("pcre") depends_on("ncurses") + conflicts('+lmod', when='~etcdir', msg='local etc required to setup env for lmod') + def configure_args(self): + args = [] + if '+skip-tcsetpgrp-test' in self.spec: # assert that we have a functional tcsetpgrp - args = ['--with-tcsetpgrp'] - else: - # let configure run it's test and see what's what - args = [] + args.append('--with-tcsetpgrp') + + if '+etcdir' in self.spec: + # enable etc dir under install prefix + mkdirp(self.prefix.etc) + args.append('--enable-etcdir={0}'.format(self.prefix.etc)) return args + + @run_after('install') + def setup_zshenv(self): + if '+lmod' in self.spec: + zsh_setup = """ +if [ -d /etc/profile.d ]; then + setopt no_nomatch + for i in /etc/profile.d/*.sh; do + if [ -r $i ]; then + . $i + fi + done + setopt nomatch +fi +""" + + with open('{0}/zshenv'.format(self.prefix.etc), 'w') as zshenv: + zshenv.write(zsh_setup)