From 4b898a0a437f7d0c58e3766202a48c2c2d5f70d2 Mon Sep 17 00:00:00 2001
From: Arun Isaac
Date: Mon, 16 Aug 2021 18:21:30 +0530
Subject: Makefile: Generate sample output when building documentation.

* Makefile.am (CLEANFILES): Add doc/*.out.
(CLEAN_DIRECTORIES): Add doc/cwl-output.
(GENERATE_CWL_OUTPUT): New variable.
(doc/capture-output-file.out,
doc/capture-output-file-with-parameter-reference.out,
doc/capture-stdout.out, doc/checksum.out,
doc/decompress-compile-run.out, doc/hello-world.out,
doc/pass-stdin.out, doc/hello.tar.out): New targets.
* doc/capture-output-file-with-parameter-reference.out,
doc/capture-output-file.out, doc/capture-stdout.out, doc/checksum.out,
doc/decompress-compile-run.out, doc/hello-world.out,
doc/hello.tar.out, doc/pass-stdin.out: Delete files.
* build-aux/generate-cwl-output.sh.in, doc/hello.c.gz, doc/hello.tar,
doc/hello.txt: New files.
* configure.ac: Configure build-aux/generate-cwl-output.sh.
* doc/ccwl.skb (Tutorial)[Passing input into the standard input stream
of a command]: Replace file "foo" with "hello.txt".
* .gitignore: Add build-aux/generate-cwl-output.sh, doc/*.out and
doc/cwl-output.
---
 .gitignore                                         |   3 ++
 Makefile.am                                        |  32 +++++++++++++-
 build-aux/generate-cwl-output.sh.in                |  37 ++++++++++++++++
 configure.ac                                       |   1 +
 ...apture-output-file-with-parameter-reference.out |  24 ----------
 doc/capture-output-file.out                        |  23 ----------
 doc/capture-stdout.out                             |  21 ---------
 doc/ccwl.skb                                       |   4 +-
 doc/checksum.out                                   |  49 ---------------------
 doc/decompress-compile-run.out                     |  36 ---------------
 doc/hello-world.out                                |  13 ------
 doc/hello.c.gz                                     | Bin 0 -> 101 bytes
 doc/hello.tar                                      | Bin 0 -> 10240 bytes
 doc/hello.tar.out                                  |   2 -
 doc/hello.txt                                      |   1 +
 doc/pass-stdin.out                                 |  13 ------
 16 files changed, 74 insertions(+), 185 deletions(-)
 create mode 100755 build-aux/generate-cwl-output.sh.in
 delete mode 100644 doc/capture-output-file-with-parameter-reference.out
 delete mode 100644 doc/capture-output-file.out
 delete mode 100644 doc/capture-stdout.out
 delete mode 100644 doc/checksum.out
 delete mode 100644 doc/decompress-compile-run.out
 delete mode 100644 doc/hello-world.out
 create mode 100644 doc/hello.c.gz
 create mode 100644 doc/hello.tar
 delete mode 100644 doc/hello.tar.out
 create mode 100644 doc/hello.txt
 delete mode 100644 doc/pass-stdin.out

diff --git a/.gitignore b/.gitignore
index 39264fb..b9cb0fd 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,6 +4,7 @@ Makefile
 Makefile.in
 aclocal.m4
 autom4te.cache
+build-aux/generate-cwl-output.sh
 build-aux/install-sh
 build-aux/missing
 build-aux/test-driver.scm
@@ -13,8 +14,10 @@ configure
 doc/*.cwl
 doc/*.html
 doc/*.info
+doc/*.out
 doc/*.png
 doc/.dirstamp
+doc/cwl-output
 doc/stamp-vti
 pre-inst-env
 scripts/ccwl
diff --git a/Makefile.am b/Makefile.am
index f96a43e..b53ac21 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -95,11 +95,39 @@ EXTRA_DIST +=			\
 
 include .depends
 
-CLEANFILES += doc/*.cwl doc/*.dot doc/*.png
+CLEANFILES += doc/*.cwl doc/*.dot doc/*.out doc/*.png
+CLEAN_DIRECTORIES = doc/cwl-output
 
 %.cwl: %.scm
 	$(CCWL_GEN)$(builddir)/pre-inst-env ccwl compile $< > $@
 
+GENERATE_CWL_OUTPUT = ./build-aux/generate-cwl-output.sh
+
+doc/capture-output-file.out: doc/capture-output-file.cwl doc/hello.tar $(GENERATE_CWL_OUTPUT)
+	$(CWLTOOL_GEN)$(GENERATE_CWL_OUTPUT) $< --archive hello.tar
+
+doc/capture-output-file-with-parameter-reference.out: doc/capture-output-file-with-parameter-reference.cwl doc/hello.tar $(GENERATE_CWL_OUTPUT)
+	$(CWLTOOL_GEN)$(GENERATE_CWL_OUTPUT) $< --archive hello.tar --extractfile hello.txt
+
+doc/capture-stdout.out: doc/capture-stdout.cwl $(GENERATE_CWL_OUTPUT)
+	$(CWLTOOL_GEN)$(GENERATE_CWL_OUTPUT) $< --message '"Hello World!"'
+
+doc/checksum.out: doc/checksum.cwl doc/hello.txt $(GENERATE_CWL_OUTPUT)
+	$(CWLTOOL_GEN)$(GENERATE_CWL_OUTPUT) $< --file hello.txt
+
+doc/decompress-compile-run.out: doc/decompress-compile-run.cwl doc/hello.c.gz $(GENERATE_CWL_OUTPUT)
+	$(CWLTOOL_GEN)$(GENERATE_CWL_OUTPUT) $< --compressed-source hello.c.gz
+
+doc/hello-world.out: doc/hello-world.cwl $(GENERATE_CWL_OUTPUT)
+	$(CWLTOOL_GEN)$(GENERATE_CWL_OUTPUT) $< --message '"Hello World!"'
+
+doc/pass-stdin.out: doc/pass-stdin.cwl doc/hello.txt $(GENERATE_CWL_OUTPUT)
+	$(CWLTOOL_GEN)$(GENERATE_CWL_OUTPUT) $< --file hello.txt
+
+doc/hello.tar.out: doc/hello.tar
+	echo "$$ tar --list --file $(notdir $<)" > $@
+	tar --list --file $< >> $@
+
 # Print out graph for graphviz's dot, but remove file path prefix from
 # workflow step identifiers.
 %.dot: %.cwl
@@ -116,7 +144,7 @@ html-local: doc/ccwl.html
 
 SKRIBILO_FLAGS = --source-path=$(srcdir) --image-path=$(builddir)
 CLEANFILES += doc/ccwl.info doc/skribilo.go
-CLEAN_DIRECTORIES = doc/ccwl.html
+CLEAN_DIRECTORIES += doc/ccwl.html
 
 doc/ccwl.info: doc/ccwl.skb doc/skribilo.go $(DOC_IMAGES) $(DOC_OTHER)
 	$(SKRIBILO_GEN)$(builddir)/pre-inst-env $(SKRIBILO) $(SKRIBILO_FLAGS) -t info $< -o $@
diff --git a/build-aux/generate-cwl-output.sh.in b/build-aux/generate-cwl-output.sh.in
new file mode 100755
index 0000000..6f56996
--- /dev/null
+++ b/build-aux/generate-cwl-output.sh.in
@@ -0,0 +1,37 @@
+#! /bin/sh -e
+
+# ccwl --- Concise Common Workflow Language
+# Copyright © 2021 Arun Isaac <arunisaac@systemreboot.net>
+#
+# This file is part of ccwl.
+#
+# ccwl is free software: you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# ccwl is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with ccwl.  If not, see <https://www.gnu.org/licenses/>.
+
+set -o pipefail
+
+cwl_file=$(basename $1)
+shift
+
+cd doc
+output_file=$(basename $cwl_file .cwl).out
+{
+    echo "\$ ccwl compile $(basename $cwl_file .cwl).scm > $cwl_file"
+    echo "\$ cwltool $cwl_file $@"
+    # On Guix, workflows involving gcc need the
+    # --preserve-entire-environment flag.
+    @CWLTOOL@ --preserve-entire-environment --outdir cwl-output $cwl_file "$@" 2>&1 \
+        | @SED@ '1,2d' \
+        | @SED@ 's|\[1;30mINFO\[0m ||g' \
+        | @SED@ "s|$(pwd)|/home/manimekalai|g"
+} > $output_file
diff --git a/configure.ac b/configure.ac
index e40d794..024b4a6 100644
--- a/configure.ac
+++ b/configure.ac
@@ -32,5 +32,6 @@ AC_PATH_PROG([SKRIBILO], [skribilo])
 AC_CONFIG_FILES([Makefile])
 AC_CONFIG_FILES([pre-inst-env], [chmod +x pre-inst-env])
 AC_CONFIG_FILES([build-aux/test-driver.scm])
+AC_CONFIG_FILES([build-aux/generate-cwl-output.sh], [chmod +x build-aux/generate-cwl-output.sh])
 AC_CONFIG_FILES([scripts/ccwl], [chmod +x scripts/ccwl])
 AC_OUTPUT
diff --git a/doc/capture-output-file-with-parameter-reference.out b/doc/capture-output-file-with-parameter-reference.out
deleted file mode 100644
index 57369d2..0000000
--- a/doc/capture-output-file-with-parameter-reference.out
+++ /dev/null
@@ -1,24 +0,0 @@
-$ ccwl compile capture-output-file.scm > capture-output-file.cwl
-$ cwltool capture-output-file.cwl --archive hello.tar --extractfile hello.txt
-[workflow ] start
-[workflow ] starting step extract-specific-file
-[step extract-specific-file] start
-[job extract-specific-file] /tmp/751nydd1$ tar \
-    --extract \
-    --file \
-    /tmp/1zzw2n6m/stgc851e003-b5bd-437e-844b-311f6f66a7f1/hello.tar \
-    hello.txt
-[job extract-specific-file] completed success
-[step extract-specific-file] completed success
-[workflow ] completed success
-{
-    "extracted-file": {
-        "location": "file:///home/manimekalai/hello.txt",
-        "basename": "hello.txt",
-        "class": "File",
-        "checksum": "sha1$a0b65939670bc2c010f4d5d6a0b3e4e4590fb92b",
-        "size": 13,
-        "path": "/home/manimekalai/hello.txt"
-    }
-}
-Final process status is success
diff --git a/doc/capture-output-file.out b/doc/capture-output-file.out
deleted file mode 100644
index 32ee625..0000000
--- a/doc/capture-output-file.out
+++ /dev/null
@@ -1,23 +0,0 @@
-$ ccwl compile capture-output-file.scm > capture-output-file.cwl
-$ cwltool capture-output-file.cwl --archive hello.tar
-[workflow ] start
-[workflow ] starting step extract
-[step extract] start
-[job extract] /tmp/nrolttex$ tar \
-    --extract \
-    --file \
-    /tmp/z7pp7qwh/stg3ac272aa-3459-4f20-a033-86f53ba72caf/hello.tar
-[job extract] completed success
-[step extract] completed success
-[workflow ] completed success
-{
-    "extracted-file": {
-        "location": "file:///home/manimekalai/hello.txt",
-        "basename": "hello.txt",
-        "class": "File",
-        "checksum": "sha1$a0b65939670bc2c010f4d5d6a0b3e4e4590fb92b",
-        "size": 13,
-        "path": "/home/manimekalai/hello.txt"
-    }
-}
-Final process status is success
diff --git a/doc/capture-stdout.out b/doc/capture-stdout.out
deleted file mode 100644
index 19568af..0000000
--- a/doc/capture-stdout.out
+++ /dev/null
@@ -1,21 +0,0 @@
-$ ccwl compile capture-stdout.scm > capture-stdout.cwl
-$ cwltool capture-stdout.cwl --message "Hello World!"
-[workflow ] start
-[workflow ] starting step print
-[step print] start
-[job print] /tmp/7zksx3xm$ echo \
-    'Hello World!' > /tmp/7zksx3xm/51fe79d15e7790a9ded795304220d7a44aa84b48
-[job print] completed success
-[step print] completed success
-[workflow ] completed success
-{
-    "printed-message": {
-        "location": "file:///home/manimekalai/51fe79d15e7790a9ded795304220d7a44aa84b48",
-        "basename": "51fe79d15e7790a9ded795304220d7a44aa84b48",
-        "class": "File",
-        "checksum": "sha1$a0b65939670bc2c010f4d5d6a0b3e4e4590fb92b",
-        "size": 13,
-        "path": "/home/manimekalai/51fe79d15e7790a9ded795304220d7a44aa84b48"
-    }
-}
-Final process status is success
diff --git a/doc/ccwl.skb b/doc/ccwl.skb
index 41b1642..c948b53 100644
--- a/doc/ccwl.skb
+++ b/doc/ccwl.skb
@@ -179,8 +179,8 @@ references the input ,(code "file").])
       (scheme-source "doc/pass-stdin.scm")
 
       (p [Compiling and running this workflow gives us the following
-output. Notice the file ,(file "foo") passed into the standard input
-of ,(command "wc"), and the file size reported in bytes.])
+output. Notice the file ,(file "hello.txt") passed into the standard
+input of ,(command "wc"), and the file size reported in bytes.])
 
       (prog :line #f (source :file "doc/pass-stdin.out")))
 
diff --git a/doc/checksum.out b/doc/checksum.out
deleted file mode 100644
index 01d7155..0000000
--- a/doc/checksum.out
+++ /dev/null
@@ -1,49 +0,0 @@
-$ ccwl compile checksum.scm > checksum.cwl
-$ cwltool checksum.cwl --file hello.txt
-[workflow ] start
-[workflow ] starting step sha256sum
-[step sha256sum] start
-[job sha256sum] /tmp/rjbcjppq$ sha256sum \
-    /tmp/pc2bbl6o/stg2f7cdda0-9d89-47b7-96b6-fa377cc61c49/hello.txt > /tmp/rjbcjppq/0d2eaa5619c14b43326101200d0f27b0d8a1a4b1
-[job sha256sum] completed success
-[step sha256sum] completed success
-[workflow ] starting step sha1sum
-[step sha1sum] start
-[job sha1sum] /tmp/1cjtot5q$ sha1sum \
-    /tmp/wliybbsp/stg993b2838-c803-4527-89d6-6a0cd7a0587a/hello.txt > /tmp/1cjtot5q/d2f19c786fcd3feb329004c8747803fba581a02d
-[job sha1sum] completed success
-[step sha1sum] completed success
-[workflow ] starting step md5sum
-[step md5sum] start
-[job md5sum] /tmp/z7fe89c7$ md5sum \
-    /tmp/41nnygw9/stgebdc428b-ec84-4283-88ae-682c7f4628ac/hello.txt > /tmp/z7fe89c7/112be1054505027982e64d56b0879049c12737c6
-[job md5sum] completed success
-[step md5sum] completed success
-[workflow ] completed success
-{
-    "md5": {
-        "location": "file:///home/manimekalai/112be1054505027982e64d56b0879049c12737c6",
-        "basename": "112be1054505027982e64d56b0879049c12737c6",
-        "class": "File",
-        "checksum": "sha1$dd2e54f3bd22a8bb4ffbf543151050ee9645baf2",
-        "size": 98,
-        "path": "/home/manimekalai/112be1054505027982e64d56b0879049c12737c6"
-    },
-    "sha1": {
-        "location": "file:///home/manimekalai/d2f19c786fcd3feb329004c8747803fba581a02d",
-        "basename": "d2f19c786fcd3feb329004c8747803fba581a02d",
-        "class": "File",
-        "checksum": "sha1$f4112d33f41bc98a114b35759c26eec9a9f4256c",
-        "size": 106,
-        "path": "/home/manimekalai/d2f19c786fcd3feb329004c8747803fba581a02d"
-    },
-    "sha256": {
-        "location": "file:///home/manimekalai/0d2eaa5619c14b43326101200d0f27b0d8a1a4b1",
-        "basename": "0d2eaa5619c14b43326101200d0f27b0d8a1a4b1",
-        "class": "File",
-        "checksum": "sha1$868ce04a610122b1c1f2846e5e9f9fc7a289d120",
-        "size": 130,
-        "path": "/home/manimekalai/0d2eaa5619c14b43326101200d0f27b0d8a1a4b1"
-    }
-}
-Final process status is success
diff --git a/doc/decompress-compile-run.out b/doc/decompress-compile-run.out
deleted file mode 100644
index 7ab832e..0000000
--- a/doc/decompress-compile-run.out
+++ /dev/null
@@ -1,36 +0,0 @@
-$ ccwl compile decompress-compile-run.scm > decompress-compile-run.cwl
-$ cwltool decompress-compile-run.cwl --compressed-source hello.c.gz
-[workflow ] start
-[workflow ] starting step decompress
-[step decompress] start
-[job decompress] /tmp/3bsk5yfm$ gzip \
-    --stdout \
-    --decompress \
-    /tmp/yn4wh0j8/stg1e0bc56d-f845-4a28-a685-1faf96129eac/hello.c.gz > /tmp/3bsk5yfm/eae8fb860f3b6eaf6ae2b9d9285b5c07cc457e90
-[job decompress] completed success
-[step decompress] completed success
-[workflow ] starting step compile
-[step compile] start
-[job compile] /tmp/lnjz1vik$ gcc \
-    -x \
-    c \
-    /tmp/rpf9g_lj/stg1be6bb98-7101-4f46-9885-fe0a985dee73/eae8fb860f3b6eaf6ae2b9d9285b5c07cc457e90
-[job compile] completed success
-[step compile] completed success
-[workflow ] starting step run
-[step run] start
-[job run] /tmp/fftn945x$ /tmp/favjw7d5/stg2576ae91-5240-4731-b98d-dee0f8ef7703/a.out > /tmp/fftn945x/c32c587f7afbdf87cf991c14a43edecf09cd93bf
-[job run] completed success
-[step run] completed success
-[workflow ] completed success
-{
-    "stdout": {
-        "location": "file:///home/manimekalai/c32c587f7afbdf87cf991c14a43edecf09cd93bf",
-        "basename": "c32c587f7afbdf87cf991c14a43edecf09cd93bf",
-        "class": "File",
-        "checksum": "sha1$a0b65939670bc2c010f4d5d6a0b3e4e4590fb92b",
-        "size": 13,
-        "path": "/home/manimekalai/c32c587f7afbdf87cf991c14a43edecf09cd93bf"
-    }
-}
-Final process status is success
diff --git a/doc/hello-world.out b/doc/hello-world.out
deleted file mode 100644
index 3a783a1..0000000
--- a/doc/hello-world.out
+++ /dev/null
@@ -1,13 +0,0 @@
-$ ccwl compile hello-world.scm > hello-world.cwl
-$ cwltool hello-world.cwl --message "Hello World!"
-[workflow ] start
-[workflow ] starting step echo
-[step echo] start
-[job echo] /tmp/zprgn3x0$ echo \
-    'Hello World!'
-Hello World!
-[job echo] completed success
-[step echo] completed success
-[workflow ] completed success
-{}
-Final process status is success
\ No newline at end of file
diff --git a/doc/hello.c.gz b/doc/hello.c.gz
new file mode 100644
index 0000000..81c4d84
Binary files /dev/null and b/doc/hello.c.gz differ
diff --git a/doc/hello.tar b/doc/hello.tar
new file mode 100644
index 0000000..edcc4a8
Binary files /dev/null and b/doc/hello.tar differ
diff --git a/doc/hello.tar.out b/doc/hello.tar.out
deleted file mode 100644
index 2d492b7..0000000
--- a/doc/hello.tar.out
+++ /dev/null
@@ -1,2 +0,0 @@
-$ tar --list --file hello.tar
-hello.txt
diff --git a/doc/hello.txt b/doc/hello.txt
new file mode 100644
index 0000000..980a0d5
--- /dev/null
+++ b/doc/hello.txt
@@ -0,0 +1 @@
+Hello World!
diff --git a/doc/pass-stdin.out b/doc/pass-stdin.out
deleted file mode 100644
index c4af7da..0000000
--- a/doc/pass-stdin.out
+++ /dev/null
@@ -1,13 +0,0 @@
-$ ccwl compile pass-stdin.scm > pass-stdin.cwl
-$ cwltool pass-stdin.cwl --file foo
-     [workflow ] start
-     [workflow ] starting step count-bytes
-     [step count-bytes] start
-     [job count-bytes] /tmp/wxi6_9jz$ wc \
-    -c < /tmp/siden6hu/stg51eaae41-52a5-4e69-a78e-caefd84f7af5/foo
-37
-     [job count-bytes] completed success
-     [step count-bytes] completed success
-     [workflow ] completed success
-{}
-     Final process status is success
\ No newline at end of file
-- 
cgit v1.2.3