2.5. 附加参数#

有时,一些工具需要额外的命令行选项,但我们无法让它们与 (CWL) 输入参数一一对应。

本例中,我们将包装 Java 编译器,将 java 源文件编译为类 (class) 文件。 默认情况下,“javac” 将在源文件所在目录中创建类文件。 然而,CWL 输入文件(及其所在目录)可能是只读的,因此我们需要令 “javac” 将类文件写入指定的输出目录。

arguments.cwl#
#!/usr/bin/env cwl-runner
cwlVersion: v1.2
class: CommandLineTool
label: Example trivial wrapper for Java 9 compiler
hints:
  DockerRequirement:
    dockerPull: openjdk:9.0.1-11-slim
baseCommand: javac
arguments: ["-d", $(runtime.outdir)]
inputs:
  src:
    type: File
    inputBinding:
      position: 1
outputs:
  classfile:
    type: File
    outputBinding:
      glob: "*.class"
arguments-job.yml#
src:
  class: File
  path: Hello.java

接下来,创建一个示例 Java 文件,用来让命令行工具处理它。

$ echo "public class Hello {}" > Hello.java

现在,将刚才创建的工具描述和输入对象通过命令行传递给 cwltool

$ cwltool arguments.cwl arguments-job.yml
INFO /opt/hostedtoolcache/Python/3.9.19/x64/bin/cwltool 3.1.20240508115724
INFO Resolved 'arguments.cwl' to 'file:///home/runner/work/user_guide/user_guide/src/_includes/cwl/additional-arguments-and-parameters/arguments.cwl'
INFO [job arguments.cwl] /tmp/qrzf2pie$ docker \
    run \
    -i \
    --mount=type=bind,source=/tmp/qrzf2pie,target=/QcZvyH \
    --mount=type=bind,source=/tmp/k6ozzdc4,target=/tmp \
    --mount=type=bind,source=/home/runner/work/user_guide/user_guide/src/_includes/cwl/additional-arguments-and-parameters/Hello.java,target=/var/lib/cwl/stg9cd876b9-783c-4667-b0e8-0ed44d0a2e05/Hello.java,readonly \
    --workdir=/QcZvyH \
    --read-only=true \
    --net=none \
    --user=1001:127 \
    --rm \
    --cidfile=/tmp/4wr6f__3/20240518114716-285148.cid \
    --env=TMPDIR=/tmp \
    --env=HOME=/QcZvyH \
    openjdk:9.0.1-11-slim \
    javac \
    -d \
    /QcZvyH \
    /var/lib/cwl/stg9cd876b9-783c-4667-b0e8-0ed44d0a2e05/Hello.java
INFO [job arguments.cwl] completed success
{
    "classfile": {
        "location": "file:///home/runner/work/user_guide/user_guide/src/_includes/cwl/additional-arguments-and-parameters/Hello.class",
        "basename": "Hello.class",
        "class": "File",
        "checksum": "sha1$fdb876b40ad9ebc7fee873212e02d5940588642e",
        "size": 184,
        "path": "/home/runner/work/user_guide/user_guide/src/_includes/cwl/additional-arguments-and-parameters/Hello.class"
    }
}INFO Final process status is success

此处我们使用 arguments 字段,给命令行添加一个与任何具体输入参数都无关的附加参数。

arguments: ["-d", $(runtime.outdir)]

此示例用到了运行时 (runtime) 参数,它们提供的是工具实际执行时的硬件或软件环境信息。 $(runtime.outdir) 参数是指定输出目录的路径。其他运行时参数还有 $(runtime.tmpdir)$(runtime.ram)$(runtime.cores)$(runtime.outdirSize), 以及 $(runtime.tmpdirSize) 等,详见 CWL 规约的 Runtime Environment(运行环境)部分。