-
Notifications
You must be signed in to change notification settings - Fork 676
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use /usr/bin/env -S bash
instead of /bin/bash
on the host system
#5684
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,6 +65,8 @@ class BashWrapperBuilder { | |
|
||
static final public List<String> BASH | ||
|
||
static final public List<String> ENV_BASH | ||
|
||
static private int level | ||
|
||
@PackageScope | ||
|
@@ -85,6 +87,7 @@ class BashWrapperBuilder { | |
log.warn "Invalid value for `NXF_DEBUG` variable: $str -- See http://www.nextflow.io/docs/latest/config.html#environment-variables" | ||
} | ||
BASH = Collections.unmodifiableList( level > 0 ? ['/bin/bash','-uex'] : ['/bin/bash','-ue'] ) | ||
ENV_BASH = Collections.unmodifiableList(['/usr/bin/env', '-S', 'bash', BASH[1]]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why introducing this variable instead of relying on There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for looking into this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My point is that after #4292 you should be able to use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, I still need clarification: Do you suggest this PR is not necessary at all because one could set There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "Yes", to my first or second interpretation? I feel like the are mutually exclusive. 🤷 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I suggest this PR is not necessary at all because one could set process.shell There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [Disclaimer: I assume that the additional usage of
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The use of I propose to address the problem of providing a custom Bash path in a more structural manner in this PR #5696 |
||
|
||
} | ||
|
||
|
@@ -563,12 +566,14 @@ class BashWrapperBuilder { | |
statsEnabled || fixOwnership() | ||
} | ||
|
||
protected String shellPath() { | ||
// keep the shell path as "/bin/bash" when a non-custom "shell" attribute is specified | ||
// to not introduce unexpected changes due to the fact BASH is defined as "/bin/bash -eu" by default | ||
return shell.is(BASH) | ||
? "/bin/bash" | ||
: shell.join(' ') | ||
protected String traceInterpreter() { | ||
// if no specific shell was defined, do not use the default one (i.e. "...bash -ue[x]") neither because | ||
// -ue[x] should not be used during tracing | ||
if( shell.is(BASH) || shell.is(ENV_BASH) ) { | ||
return shell.init().join(' ') | ||
} | ||
// otherwise, stick to the custom shell | ||
return shell.join(' ') | ||
} | ||
|
||
protected String getLaunchCommand(String interpreter, String env) { | ||
|
@@ -582,7 +587,7 @@ class BashWrapperBuilder { | |
final traceWrapper = isTraceRequired() | ||
if( traceWrapper ) { | ||
// executes the stub which in turn executes the target command | ||
launcher = "${shellPath()} ${fileStr(wrapperFile)} nxf_trace" | ||
launcher = "${traceInterpreter()} ${fileStr(wrapperFile)} nxf_trace" | ||
} | ||
else { | ||
launcher = "${interpreter} ${fileStr(scriptFile)}" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -131,7 +131,7 @@ class LocalTaskHandler extends TaskHandler implements FusionAwareTask { | |
} | ||
|
||
protected ProcessBuilder localProcessBuilder() { | ||
final cmd = new ArrayList<String>(BashWrapperBuilder.BASH) << wrapperFile.getName() | ||
final cmd = new ArrayList<String>(BashWrapperBuilder.ENV_BASH) << wrapperFile.getName() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This makes sure that |
||
log.debug "Launch cmd line: ${cmd.join(' ')}" | ||
// make sure it's a posix file system | ||
if( task.workDir.fileSystem != FileSystems.default ) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -136,7 +136,7 @@ class TaskBean implements Serializable, Cloneable { | |
this.useMicromamba = task.getCondaConfig()?.useMicromamba() | ||
this.spackEnv = task.getSpackEnv() | ||
this.moduleNames = task.config.getModule() | ||
this.shell = task.config.getShell() ?: BashWrapperBuilder.BASH | ||
this.shell = task.config.getShell(task.isContainerEnabled()) ?: BashWrapperBuilder.BASH | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. At this point, |
||
this.script = task.getScript() | ||
this.beforeScript = task.config.getBeforeScript() | ||
this.afterScript = task.config.getAfterScript() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -374,10 +374,10 @@ class TaskConfig extends LazyMap implements Cloneable { | |
return (List<String>) get('secret') | ||
} | ||
|
||
List<String> getShell() { | ||
List<String> getShell(boolean isContainerEnabled = true) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm happy to adapt the unit tests but I don't know how 🤷 . |
||
final value = get('shell') | ||
if( !value ) | ||
return BashWrapperBuilder.BASH | ||
return isContainerEnabled ? BashWrapperBuilder.BASH : BashWrapperBuilder.ENV_BASH | ||
|
||
if( value instanceof List ) | ||
return (List)value | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -125,7 +125,6 @@ class ProcessConfig implements Map<String,Object>, Cloneable { | |
static final Map<String,Object> DEFAULT_CONFIG = [ | ||
debug: false, | ||
cacheable: true, | ||
shell: BashWrapperBuilder.BASH, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The changes in this file and the next one make sure that Nextflow does not assume |
||
maxRetries: 1, | ||
maxErrors: -1, | ||
errorStrategy: ErrorStrategy.TERMINATE | ||
|
@@ -169,14 +168,15 @@ class ProcessConfig implements Map<String,Object>, Cloneable { | |
* | ||
* @param script The owner {@code BaseScript} configuration object | ||
*/ | ||
protected ProcessConfig( BaseScript script ) { | ||
protected ProcessConfig( BaseScript script, boolean isContainerEnabled = true) { | ||
ownerScript = script | ||
configProperties = new LinkedHashMap() | ||
configProperties.putAll( DEFAULT_CONFIG ) | ||
configProperties.put('shell', isContainerEnabled ? BashWrapperBuilder.BASH : BashWrapperBuilder.ENV_BASH) | ||
} | ||
|
||
ProcessConfig( BaseScript script, String name ) { | ||
this(script) | ||
ProcessConfig( BaseScript script, String name, boolean isContainerEnabled = true) { | ||
this(script, isContainerEnabled) | ||
this.processName = name | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest to rename
BASH
toBIN_BASH
to make the difference clear.