Skip to content

Commit

Permalink
Fix shell directive with trace command in wrapper script (#4292)
Browse files Browse the repository at this point in the history

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>
  • Loading branch information
bentsherman and pditommaso authored Jan 17, 2025
1 parent 7439ce2 commit 8342889
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,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 getLaunchCommand(String interpreter, String env) {
/*
* process stats
Expand All @@ -574,7 +582,7 @@ class BashWrapperBuilder {
final traceWrapper = isTraceRequired()
if( traceWrapper ) {
// executes the stub which in turn executes the target command
launcher = "/bin/bash ${fileStr(wrapperFile)} nxf_trace"
launcher = "${shellPath()} ${fileStr(wrapperFile)} nxf_trace"
}
else {
launcher = "${interpreter} ${fileStr(scriptFile)}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,38 @@ class BashWrapperBuilderTest extends Specification {

}

def 'should enable trace feature with custom shell' () {
when:
def binding = newBashWrapperBuilder(statsEnabled: false, shell: ['/bin/bash', '-ue']).makeBinding()
then:
binding.launch_cmd == '/bin/bash -ue /work/dir/.command.sh'
binding.unstage_controls == null
binding.containsKey('unstage_controls')

when:
binding = newBashWrapperBuilder(statsEnabled: true, shell: ['/bin/bash', '-eu']).makeBinding()
then:
binding.launch_cmd == '/bin/bash -eu /work/dir/.command.run nxf_trace'
binding.unstage_controls == null
binding.containsKey('unstage_controls')

when:
binding = newBashWrapperBuilder(statsEnabled: true, scratch: true, shell: ['/bin/bash', '-eu']).makeBinding()
then:
binding.launch_cmd == '/bin/bash -eu /work/dir/.command.run nxf_trace'
binding.unstage_controls == '''\
cp .command.out /work/dir/.command.out || true
cp .command.err /work/dir/.command.err || true
cp .command.trace /work/dir/.command.trace || true
'''.stripIndent()

when:
binding = newBashWrapperBuilder(statsEnabled: true, shell: ['/usr/local/bin/bash', '-ue']).makeBinding()
then:
binding.launch_cmd == '/usr/local/bin/bash -ue /work/dir/.command.run nxf_trace'

}

def 'should create launcher command with input' () {

when:
Expand Down Expand Up @@ -1192,6 +1224,7 @@ class BashWrapperBuilderTest extends Specification {
given:
def bean = Mock(TaskBean) {
inputFiles >> [:]
shell >> BashWrapperBuilder.BASH
outputFiles >> []
}
def copy = Mock(ScriptFileCopyStrategy)
Expand Down

0 comments on commit 8342889

Please sign in to comment.