Skip to content
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 shell directive with trace command in wrapper script #4292

Merged
merged 4 commits into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading