2.15. 暂存输入文件#

通常,输入文件存放于只读目录中,而且位于输出目录之外。 然而,如果基础工具工作的惯例是将输出文件写到输入文件所在的同一目录,则会导致问题。 使用 InitialWorkDirRequirement 可以实现在输出目录中暂存输入文件。在此示例中,我们使用 JavaScript 表达式,提取输入文件去除前导目录路径后的基本文件名 (base name).

linkfile.cwl#
#!/usr/bin/env cwl-runner
cwlVersion: v1.2
class: CommandLineTool
hints:
  DockerRequirement:
    dockerPull: openjdk:9.0.1-11-slim
baseCommand: javac

requirements:
  InitialWorkDirRequirement:
    listing:
      - $(inputs.src)

inputs:
  src:
    type: File
    inputBinding:
      position: 1
      valueFrom: $(self.basename)

outputs:
  classfile:
    type: File
    outputBinding:
      glob: "*.class"
arguments-job.yml#
src:
  class: File
  path: Hello.java

现在,在命令行上以工具描述和输入对象为参数调用 cwltool:

$ cwltool linkfile.cwl arguments-job.yml
INFO /home/docs/checkouts/readthedocs.org/user_builds/common-workflow-languageuser-guide-zh-hans/envs/latest/bin/cwltool 3.1.20240508115724
INFO Resolved 'linkfile.cwl' to 'file:///home/docs/checkouts/readthedocs.org/user_builds/common-workflow-languageuser-guide-zh-hans/checkouts/latest/src/_includes/cwl/staging-input-files/linkfile.cwl'
ERROR Workflow error, try again with --debug for more information:
Docker is not available for this tool, try --no-container to disable Docker, or install a user space Docker replacement like uDocker with --user-space-docker-cmd.: docker executable is not available