Skip to content

Commit 8342889

Browse files
Fix shell directive with trace command in wrapper script (#4292)
Signed-off-by: Ben Sherman <bentshermann@gmail.com> Signed-off-by: Paolo Di Tommaso <paolo.ditommaso@gmail.com> Co-authored-by: Paolo Di Tommaso <paolo.ditommaso@gmail.com>
1 parent 7439ce2 commit 8342889

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

modules/nextflow/src/main/groovy/nextflow/executor/BashWrapperBuilder.groovy

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,14 @@ class BashWrapperBuilder {
563563
statsEnabled || fixOwnership()
564564
}
565565

566+
protected String shellPath() {
567+
// keep the shell path as "/bin/bash" when a non-custom "shell" attribute is specified
568+
// to not introduce unexpected changes due to the fact BASH is defined as "/bin/bash -eu" by default
569+
return shell.is(BASH)
570+
? "/bin/bash"
571+
: shell.join(' ')
572+
}
573+
566574
protected String getLaunchCommand(String interpreter, String env) {
567575
/*
568576
* process stats
@@ -574,7 +582,7 @@ class BashWrapperBuilder {
574582
final traceWrapper = isTraceRequired()
575583
if( traceWrapper ) {
576584
// executes the stub which in turn executes the target command
577-
launcher = "/bin/bash ${fileStr(wrapperFile)} nxf_trace"
585+
launcher = "${shellPath()} ${fileStr(wrapperFile)} nxf_trace"
578586
}
579587
else {
580588
launcher = "${interpreter} ${fileStr(scriptFile)}"

modules/nextflow/src/test/groovy/nextflow/executor/BashWrapperBuilderTest.groovy

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -688,6 +688,38 @@ class BashWrapperBuilderTest extends Specification {
688688

689689
}
690690

691+
def 'should enable trace feature with custom shell' () {
692+
when:
693+
def binding = newBashWrapperBuilder(statsEnabled: false, shell: ['/bin/bash', '-ue']).makeBinding()
694+
then:
695+
binding.launch_cmd == '/bin/bash -ue /work/dir/.command.sh'
696+
binding.unstage_controls == null
697+
binding.containsKey('unstage_controls')
698+
699+
when:
700+
binding = newBashWrapperBuilder(statsEnabled: true, shell: ['/bin/bash', '-eu']).makeBinding()
701+
then:
702+
binding.launch_cmd == '/bin/bash -eu /work/dir/.command.run nxf_trace'
703+
binding.unstage_controls == null
704+
binding.containsKey('unstage_controls')
705+
706+
when:
707+
binding = newBashWrapperBuilder(statsEnabled: true, scratch: true, shell: ['/bin/bash', '-eu']).makeBinding()
708+
then:
709+
binding.launch_cmd == '/bin/bash -eu /work/dir/.command.run nxf_trace'
710+
binding.unstage_controls == '''\
711+
cp .command.out /work/dir/.command.out || true
712+
cp .command.err /work/dir/.command.err || true
713+
cp .command.trace /work/dir/.command.trace || true
714+
'''.stripIndent()
715+
716+
when:
717+
binding = newBashWrapperBuilder(statsEnabled: true, shell: ['/usr/local/bin/bash', '-ue']).makeBinding()
718+
then:
719+
binding.launch_cmd == '/usr/local/bin/bash -ue /work/dir/.command.run nxf_trace'
720+
721+
}
722+
691723
def 'should create launcher command with input' () {
692724

693725
when:
@@ -1192,6 +1224,7 @@ class BashWrapperBuilderTest extends Specification {
11921224
given:
11931225
def bean = Mock(TaskBean) {
11941226
inputFiles >> [:]
1227+
shell >> BashWrapperBuilder.BASH
11951228
outputFiles >> []
11961229
}
11971230
def copy = Mock(ScriptFileCopyStrategy)

0 commit comments

Comments
 (0)