From aea6bd4816fa9303c1e2bcc568f7ee0d6505442f Mon Sep 17 00:00:00 2001 From: Kenneth Hoste Date: Thu, 6 Jan 2022 18:09:47 +0100 Subject: [PATCH] avoid excessively long shebang line in compile script for WRF --- easybuild/easyblocks/w/wrf.py | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/easybuild/easyblocks/w/wrf.py b/easybuild/easyblocks/w/wrf.py index 3751a66c049..7f62d68b184 100644 --- a/easybuild/easyblocks/w/wrf.py +++ b/easybuild/easyblocks/w/wrf.py @@ -44,7 +44,8 @@ from easybuild.framework.easyconfig import CUSTOM, MANDATORY from easybuild.tools.build_log import EasyBuildError from easybuild.tools.config import build_option -from easybuild.tools.filetools import apply_regex_substitutions, change_dir, patch_perl_script_autoflush, read_file +from easybuild.tools.filetools import apply_regex_substitutions, change_dir +from easybuild.tools.filetools import patch_perl_script_autoflush, read_file, which from easybuild.tools.filetools import remove_file, symlink from easybuild.tools.modules import get_software_root from easybuild.tools.run import run_cmd, run_cmd_qa @@ -252,11 +253,26 @@ def build_step(self): if par: self.par = "-j %s" % par - # fix compile script shebang + # fix compile script shebang to use provided tcsh cmpscript = os.path.join(self.start_dir, 'compile') - cmpsh_root = get_software_root('tcsh') - if cmpsh_root: - regex_subs = [('/bin/csh', os.path.join(cmpsh_root, 'bin/tcsh'))] + tcsh_root = get_software_root('tcsh') + if tcsh_root: + tcsh_path = os.path.join(tcsh_root, 'bin', 'tcsh') + # avoid using full path to tcsh if possible, since it may be too long to be used as shebang line + which_tcsh = which('tcsh') + if which_tcsh and os.path.samefile(which_tcsh, tcsh_path): + env_path = os.path.join('/usr', 'bin', 'env') + # use env command from alternate sysroot, if available + sysroot = build_option('sysroot') + if sysroot: + sysroot_env_path = os.path.join(sysroot, 'usr', 'bin', 'env') + if os.path.exists(sysroot_env_path): + env_path = sysroot_env_path + new_shebang = env_path + ' tcsh' + else: + new_shebang = tcsh_path + + regex_subs = [('^#!/bin/csh.*', '#!' + new_shebang)] apply_regex_substitutions(cmpscript, regex_subs) # build wrf