2.15. Staging Input Files#

Normally, input files are located in a read-only directory separate from the output directory. This causes problems if the underlying tool expects to write its output files alongside the input file in the same directory. You use InitialWorkDirRequirement to stage input files into the output directory. In this example, we use a JavaScript expression to extract the base name of the input file from its leading directory path.

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

Now invoke cwltool with the tool description and the input object on the command line:

$ cwltool linkfile.cwl arguments-job.yml
INFO /opt/hostedtoolcache/Python/3.9.19/x64/bin/cwltool 3.1.20240508115724
INFO Resolved 'linkfile.cwl' to 'file:///home/runner/work/user_guide/user_guide/src/_includes/cwl/staging-input-files/linkfile.cwl'
INFO [job linkfile.cwl] /tmp/4lbxkg_x$ docker \
    run \
    -i \
    --mount=type=bind,source=/tmp/4lbxkg_x,target=/ltnJFi \
    --mount=type=bind,source=/tmp/sn3gu1d4,target=/tmp \
    --mount=type=bind,source=/home/runner/work/user_guide/user_guide/src/_includes/cwl/staging-input-files/Hello.java,target=/ltnJFi/Hello.java,readonly \
    --workdir=/ltnJFi \
    --read-only=true \
    --net=none \
    --user=1001:127 \
    --rm \
    --cidfile=/tmp/x586ngx1/20240518114119-964156.cid \
    --env=TMPDIR=/tmp \
    --env=HOME=/ltnJFi \
    openjdk:9.0.1-11-slim \
    javac \
    Hello.java
INFO [job linkfile.cwl] completed success
{
    "classfile": {
        "location": "file:///home/runner/work/user_guide/user_guide/src/_includes/cwl/staging-input-files/Hello.class",
        "basename": "Hello.class",
        "class": "File",
        "checksum": "sha1$fdb876b40ad9ebc7fee873212e02d5940588642e",
        "size": 184,
        "path": "/home/runner/work/user_guide/user_guide/src/_includes/cwl/staging-input-files/Hello.class"
    }
}INFO Final process status is success