Skip to content

Commit 282230c

Browse files
authored
Merge branch 'master' into 3129-fix-workflow-complete-handler
2 parents da5acd8 + 24903f2 commit 282230c

4 files changed

Lines changed: 73 additions & 7 deletions

File tree

modules/nextflow/src/main/groovy/nextflow/processor/TaskProcessor.groovy

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1946,7 +1946,7 @@ class TaskProcessor {
19461946
if( item instanceof Path || coerceToPath ) {
19471947
final path = resolvePath(item)
19481948
final target = executor.isForeignFile(path) ? foreignFiles.addToForeign(path) : path
1949-
final holder = new FileHolder(target)
1949+
final holder = new FileHolder(path, target)
19501950
files << holder
19511951
}
19521952
else {
@@ -2211,6 +2211,13 @@ class TaskProcessor {
22112211
keys.add( it.value )
22122212
}
22132213

2214+
// add all eval commands (they are part of the script)
2215+
for( Map.Entry<OutParam,Object> it : task.outputs ) {
2216+
if( it.key instanceof CmdEvalParam ) {
2217+
keys.add(((CmdEvalParam) it.key).getTarget(task.context))
2218+
}
2219+
}
2220+
22142221
// add all variable references in the task script but not declared as input/output
22152222
def vars = getTaskGlobalVars(task)
22162223
if( vars ) {
@@ -2245,6 +2252,7 @@ class TaskProcessor {
22452252
}
22462253
}
22472254

2255+
// add stub-run flag
22482256
if( session.stubRun && task.config.getStubBlock() ) {
22492257
keys.add('stub-run')
22502258
}

modules/nextflow/src/test/groovy/nextflow/processor/TaskProcessorTest.groovy

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import nextflow.script.BodyDef
4141
import nextflow.script.ProcessConfig
4242
import nextflow.script.ScriptType
4343
import nextflow.script.bundle.ResourcesBundle
44+
import nextflow.script.params.CmdEvalParam
4445
import nextflow.script.params.FileInParam
4546
import nextflow.script.params.FileOutParam
4647
import nextflow.util.ArrayBag
@@ -1218,4 +1219,52 @@ class TaskProcessorTest extends Specification {
12181219
0 * collector.collect(task)
12191220
1 * exec.submit(task)
12201221
}
1222+
1223+
def 'should use eval outputs in hash' () {
1224+
given:
1225+
def session = Mock(Session) {
1226+
getDumpHashes() >> 'json'
1227+
getUniqueId() >> UUID.fromString('b69b6eeb-b332-4d2c-9957-c291b15f498c')
1228+
getBinEntries() >> ['foo.sh': Paths.get('/some/path/foo.sh'), 'bar.sh': Paths.get('/some/path/bar.sh')]
1229+
}
1230+
def outParam = Mock(CmdEvalParam) {
1231+
getTarget( _ as Map) >> 'foo --version'
1232+
}
1233+
def task1 = Spy(TaskRun) {
1234+
getSource() >> 'hello world'
1235+
lazyName() >> 'hello'
1236+
isContainerEnabled() >> false
1237+
getContainer() >> null
1238+
getSpackEnv() >> null
1239+
getCondaEnv() >> null
1240+
getConfig() >> Mock(TaskConfig)
1241+
getContext() >> [:]
1242+
}
1243+
def task2 = Spy(TaskRun) {
1244+
getSource() >> 'hello world'
1245+
lazyName() >> 'hello'
1246+
isContainerEnabled() >> false
1247+
getContainer() >> null
1248+
getSpackEnv() >> null
1249+
getCondaEnv() >> null
1250+
getConfig() >> Mock(TaskConfig)
1251+
getContext() >> [:]
1252+
}
1253+
task2.setOutput(outParam)
1254+
1255+
def processor = Spy(TaskProcessor){
1256+
getTaskGlobalVars( _ as TaskRun) >> [foo:'a', bar:'b']
1257+
}
1258+
processor.@session = session
1259+
processor.@config = Mock(ProcessConfig)
1260+
1261+
when:
1262+
def uuid1 = processor.createTaskHashKey(task1)
1263+
def uuid2 = processor.createTaskHashKey(task2)
1264+
1265+
then:
1266+
uuid1 != uuid2
1267+
1268+
}
1269+
12211270
}

modules/nf-commons/src/main/nextflow/file/FileHolder.groovy

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,23 @@ package nextflow.file
2020
import java.nio.file.FileSystems
2121
import java.nio.file.Path
2222

23+
import com.google.common.hash.Hasher
2324
import groovy.transform.CompileStatic
2425
import groovy.transform.EqualsAndHashCode
2526
import groovy.transform.PackageScope
2627
import groovy.transform.ToString
2728
import groovy.util.logging.Slf4j
29+
import nextflow.util.CacheFunnel
30+
import nextflow.util.CacheHelper
31+
import nextflow.util.CacheHelper.HashMode
2832
/**
2933
* Implements a special {@code Path} used to stage files in the work area
3034
*/
3135
@Slf4j
3236
@ToString(includePackage = false, includeNames = true)
3337
@EqualsAndHashCode
3438
@CompileStatic
35-
class FileHolder {
39+
class FileHolder implements CacheFunnel {
3640

3741
final def sourceObj
3842

@@ -52,7 +56,7 @@ class FileHolder {
5256
assert path != null
5357

5458
this.sourceObj = origin
55-
this.storePath = path
59+
this.storePath = real(path)
5660
this.stageName = norm(path.getFileName())
5761
}
5862

@@ -66,10 +70,19 @@ class FileHolder {
6670
new FileHolder( this.sourceObj, this.storePath, stageName )
6771
}
6872

73+
Path getSourcePath() {
74+
sourceObj instanceof Path ? sourceObj : null
75+
}
76+
6977
Path getStorePath() { storePath }
7078

7179
String getStageName() { stageName }
7280

81+
@Override
82+
Hasher funnel(Hasher hasher, HashMode mode) {
83+
return CacheHelper.hasher(hasher, sourceObj, mode)
84+
}
85+
7386
@PackageScope
7487
static FileHolder get( def path, def name = null ) {
7588
Path storePath = path as Path

modules/nf-commons/src/main/nextflow/util/HashBuilder.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
import nextflow.ISession;
4545
import nextflow.extension.Bolts;
4646
import nextflow.extension.FilesEx;
47-
import nextflow.file.FileHolder;
4847
import nextflow.io.SerializableMarker;
4948
import org.slf4j.Logger;
5049
import org.slf4j.LoggerFactory;
@@ -162,9 +161,6 @@ else if( value instanceof Collection)
162161
for( Object item : ((Collection)value) )
163162
with(item);
164163

165-
else if( value instanceof FileHolder )
166-
with(((FileHolder) value).getSourceObj());
167-
168164
else if( value instanceof Path )
169165
hashFile(hasher, (Path)value, mode, basePath);
170166

0 commit comments

Comments
 (0)