@@ -4,6 +4,7 @@ RESOURCE_DIR="/" #default to root of pandoc container buildout
4
4
DO_GITVERSION=" yes"
5
5
DO_GITSTATUS=" yes"
6
6
PDF_OUTPUT=" "
7
+ DIFFPDF_OUTPUT=" "
7
8
DOCX_OUTPUT=" "
8
9
HTML_OUTPUT=" "
9
10
LATEX_OUTPUT=" "
@@ -41,7 +42,9 @@ print_usage() {
41
42
echo " --latex=output: enable output of latex and specify the output file name."
42
43
echo " --html=output: enable output of html and specify the output file name."
43
44
echo " --pdflog=output: enable logging of pdf engine and specify the output file name."
44
- echo " --diff=commit: create diff documents against the provided commit"
45
+ echo " --diffpdf=output: enable output of pdf diff and specify the output file name (requires --diffpdf)"
46
+ echo " --diffbase=ref: create diff documents against the provided commit (no effect if --diffpdf is not provided)"
47
+ echo " --diffpdflog=output: enable logging of pdf engine during diffing and specify the output file name."
45
48
echo
46
49
echo " Miscellaneous"
47
50
echo " --resourcedir=dir: Set the resource directory, defaults to root for pandoc containers"
@@ -57,7 +60,7 @@ print_usage() {
57
60
}
58
61
59
62
60
- if ! options=$( getopt --longoptions=help,puppeteer,gitversion,gitstatus,nogitversion,table_rules,plain_quotes,versioned_filenames,pr_number:,pr_repo:,diff :,pdf:,latex:,pdflog:,pdf_engine:,docx:,html:,resourcedir: --options=" " -- " $@ " ) ; then
63
+ if ! options=$( getopt --longoptions=help,puppeteer,gitversion,gitstatus,nogitversion,table_rules,plain_quotes,versioned_filenames,pr_number:,pr_repo:,diffbase :,pdf:,diffpdf:,diffpdflog :,latex:,pdflog:,pdf_engine:,docx:,html:,resourcedir: --options=" " -- " $@ " ) ; then
61
64
echo " Incorrect options provided"
62
65
print_usage
63
66
exit 1
66
69
eval set -- " ${options} "
67
70
while true ; do
68
71
case " $1 " in
69
- --diff )
72
+ --diffbase )
70
73
DIFFBASE=" ${2} "
71
74
shift 2
72
75
;;
@@ -115,6 +118,14 @@ while true; do
115
118
PDF_OUTPUT=" ${2} "
116
119
shift 2
117
120
;;
121
+ --diffpdf)
122
+ DIFFPDF_OUTPUT=" ${2} "
123
+ shift 2
124
+ ;;
125
+ --diffpdflog)
126
+ DIFFPDFLOG_OUTPUT=" ${2} "
127
+ shift 2
128
+ ;;
118
129
--html)
119
130
HTML_OUTPUT=" ${2} "
120
131
shift 2
@@ -157,6 +168,7 @@ readonly PR_REPO
157
168
readonly DIFFBASE
158
169
readonly PDF_ENGINE
159
170
readonly PDFLOG_OUTPUT
171
+ readonly DIFFPDFLOG_OUTPUT
160
172
161
173
shift " $(( OPTIND - 1 )) "
162
174
@@ -198,6 +210,25 @@ mkdir -p "${BUILD_DIR}"
198
210
cp -r . " ${BUILD_DIR} "
199
211
cd " ${BUILD_DIR} "
200
212
213
+ # Let git work
214
+ git config --global --add safe.directory " ${BUILD_DIR} "
215
+
216
+ # make sure the diff arguments make sense
217
+ if [ -n " ${DIFFPDF_OUTPUT} " ]; then
218
+ # --diff must be provided, and it must make sense to Git
219
+ if [ -z " ${DIFFBASE} " ]; then
220
+ >&2 echo " --diffpdf was provided, but --diffbase was not."
221
+ print_usage
222
+ exit 1
223
+ fi
224
+ git rev-parse --verify " ${DIFFBASE} " > /dev/null 2>&1
225
+ if [ $? -ne 0 ]; then
226
+ >&2 echo " --diffbase was provided, but it was not a valid Git commit, tag, or branch name."
227
+ print_usage
228
+ exit 1
229
+ fi
230
+ fi
231
+
201
232
# Get the default browser
202
233
if ! browser=$( command -v " chromium-browser" ) ; then
203
234
if ! browser=$( command -v " chromium" ) ; then
210
241
# figure out git version and revision if needed.
211
242
EXTRA_PANDOC_OPTIONS=" "
212
243
if test " ${DO_GITVERSION} " == " yes" ; then
213
- git config --global --add safe.directory /workspace
214
-
215
244
# TODO: Should we fail if dirty?
216
245
raw_version=" $( git describe --always --tags) "
217
246
echo " Git version: ${raw_version} "
@@ -348,6 +377,9 @@ if [ "${VERSIONED_FILENAMES}" == "yes" ]; then
348
377
if [ ! -z " ${PDF_OUTPUT} " ]; then
349
378
PDF_OUTPUT=$( prefix_filename " ${version_prefix} " " ${PDF_OUTPUT} " )
350
379
fi
380
+ if [ ! -z " ${DIFFPDF_OUTPUT} " ]; then
381
+ DIFFPDF_OUTPUT=$( prefix_filename " ${DIFFBASE} _to_${version_prefix} " " ${DIFFPDF_OUTPUT} " )
382
+ fi
351
383
if [ ! -z " ${LATEX_OUTPUT} " ]; then
352
384
LATEX_OUTPUT=$( prefix_filename " ${version_prefix} " " ${LATEX_OUTPUT} " )
353
385
fi
@@ -356,6 +388,7 @@ if [ "${VERSIONED_FILENAMES}" == "yes" ]; then
356
388
fi
357
389
fi
358
390
readonly PDF_OUTPUT
391
+ readonly DIFFPDF_OUTPUT
359
392
readonly DOCX_OUTPUT
360
393
readonly HTML_OUTPUT
361
394
readonly LATEX_OUTPUT
@@ -364,16 +397,15 @@ echo "Starting Build with"
364
397
echo " file: ${INPUT_FILE} "
365
398
echo " docx: ${DOCX_OUTPUT:- none} "
366
399
echo " pdf: ${PDF_OUTPUT:- none} (engine: ${PDF_ENGINE} )"
400
+ echo " diff pdf: ${DIFFPDF_OUTPUT:- none} (engine: ${PDF_ENGINE} )"
367
401
echo " latex: ${latex_ouput:- none} "
368
402
echo " html: ${html_ouput:- none} "
369
403
echo " resource dir: ${RESOURCE_DIR} "
370
404
echo " build dir: ${BUILD_DIR} "
371
405
echo " browser: ${browser} "
372
406
echo " use git version: ${DO_GITVERSION} "
373
- echo " use table rules: ${TABLE_RULES} "
374
- echo " make block quotes Informative Text: ${BLOCK_QUOTES_ARE_INFORMATIVE_TEXT} "
375
407
if [ ! -z " ${DIFFBASE} " ]; then
376
- echo " diff against: ${DIFFBASE} "
408
+ echo " diff against: ${DIFFBASE} ( $( git rev-parse --verify ${DIFFBASE} ) ) "
377
409
fi
378
410
if test " ${DO_GITVERSION} " == " yes" ; then
379
411
echo " Git Generated Document Version Information"
@@ -418,18 +450,27 @@ if [ "${BLOCK_QUOTES_ARE_INFORMATIVE_TEXT}" == "yes" ]; then
418
450
EXTRA_PANDOC_OPTIONS+=" --lua-filter=informative-quote-blocks.lua"
419
451
fi
420
452
421
- # Hacks
422
-
423
- # \newpage is rendered as the string "\newpage" in GitHub markdown.
424
- # Transform horizontal rules into \newpages.
425
- # Exception: the YAML front matter of the document, so undo the instance on the first line.
426
- # TODO: Turn this into a Pandoc filter.
427
- sed -i.bak ' s/^---$/\\newpage/g;1s/\\newpage/---/g' " ${BUILD_DIR} /${INPUT_FILE} "
428
-
429
- # Transform sections before the table of contents into section*, which does not number them.
430
- # While we're doing this, transform the case to all-caps.
431
- # TODO: Turn this into a Pandoc filter.
432
- sed -i.bak ' 0,/\\tableofcontents/s/^# \(.*\)/\\section*\{\U\1\}/g' " ${BUILD_DIR} /${INPUT_FILE} "
453
+ # Use sed to perform some basic fixups on certain input files.
454
+ do_md_fixups () {
455
+ local input=$1
456
+ # \newpage is rendered as the string "\newpage" in GitHub markdown.
457
+ # Transform horizontal rules into \newpages.
458
+ # Exception: the YAML front matter of the document, so undo the instance on the first line.
459
+ # TODO: Turn this into a Pandoc filter.
460
+ sed -i.bak ' s/^---$/\\newpage/g;1s/\\newpage/---/g' " ${input} "
461
+
462
+ # Transform sections before the table of contents into section*, which does not number them.
463
+ # While we're doing this, transform the case to all-caps.
464
+ # TODO: Turn this into a Pandoc filter.
465
+ sed -i.bak ' 0,/\\tableofcontents/s/^# \(.*\)/\\section*\{\U\1\}/g' " ${input} "
466
+ }
467
+ do_tex_fixups () {
468
+ local input=$1
469
+ # We have a "code" enviroment that displays everything, including comments.
470
+ # Sometimes latexdiff injects comments that it thinks won't be displayed.
471
+ # Delete those latexdiff comments.
472
+ sed -i.bak ' s/%DIFDELCMD.*//g' " ${input} "
473
+ }
433
474
434
475
if test " ${DO_GITVERSION} " == " yes" ; then
435
476
# If using the git information for versioning, grab the date from there
@@ -565,7 +606,7 @@ do_pdf() {
565
606
566
607
local logfile=$3
567
608
# LaTeX engines choose this filename based on TEMP_TEX_FILE's basename. It also emits a bunch of other files.
568
- readonly temp_pdf_file=" $( basename ${input% .* } ) .pdf"
609
+ local temp_pdf_file=" $( basename ${input% .* } ) .pdf"
569
610
570
611
echo " Rendering PDF"
571
612
local start=$( date +%s)
@@ -580,16 +621,15 @@ do_pdf() {
580
621
# Write any LaTeX errors to stderr.
581
622
>&2 grep -A 5 " ] ! " " ${logfile} "
582
623
583
- # Copy aux, lof, lot, and toc files back to the source directory so they can be cached and speed up future runs.
584
- if [ -n " ${PDFLOG_OUTPUT} " ]; then
585
- cp " ${logfile} " " ${SOURCE_DIR} /${PDFLOG_OUTPUT} "
586
- fi
587
- cp * .aux " ${SOURCE_DIR} "
588
- cp * .lof " ${SOURCE_DIR} "
589
- cp * .lot " ${SOURCE_DIR} "
590
- cp * .toc " ${SOURCE_DIR} "
624
+ # Copy aux, lof, lot, toc, upa, and upb files (if any) back to the source directory so they can be cached and speed up future runs.
625
+ cp * .aux " ${SOURCE_DIR} " 2> /dev/null
626
+ cp * .lof " ${SOURCE_DIR} " 2> /dev/null
627
+ cp * .lot " ${SOURCE_DIR} " 2> /dev/null
628
+ cp * .toc " ${SOURCE_DIR} " 2> /dev/null
629
+ cp * .upa " ${SOURCE_DIR} " 2> /dev/null
630
+ cp * .upb " ${SOURCE_DIR} " 2> /dev/null
591
631
# Copy converted images so they can be cached as well.
592
- cp * .convert.pdf " ${SOURCE_DIR} "
632
+ cp * .convert.pdf " ${SOURCE_DIR} " 2> /dev/null
593
633
echo " Elapsed time: $(( $end - $start )) seconds"
594
634
# Write any LaTeX errors to stderr.
595
635
>&2 grep -A 5 " ! " " ${logfile} "
@@ -700,7 +740,8 @@ do_html() {
700
740
# Generate .tex output if either latex or pdf formats were requested, because
701
741
# the .tex is an intermediate requirement to the pdf.
702
742
readonly TEMP_TEX_FILE=" ${BUILD_DIR} /${INPUT_FILE} .tex"
703
- if [ -n " ${PDF_OUTPUT} " -o -n " ${LATEX_OUTPUT} " ]; then
743
+ if [ -n " ${PDF_OUTPUT} " -o -n " ${LATEX_OUTPUT} " -o -n " ${DIFFPDF_OUTPUT} " ]; then
744
+ do_md_fixups " ${BUILD_DIR} /${INPUT_FILE} "
704
745
do_latex " ${BUILD_DIR} /${INPUT_FILE} " " ${TEMP_TEX_FILE} "
705
746
fi
706
747
if [ -n " ${LATEX_OUTPUT} " ]; then
711
752
readonly LATEX_LOG=" ${BUILD_DIR} /latex.log"
712
753
if [ -n " ${PDF_OUTPUT} " ]; then
713
754
do_pdf " ${TEMP_TEX_FILE} " " ${SOURCE_DIR} /${PDF_OUTPUT} " " ${LATEX_LOG} "
755
+
756
+ # Copy the logs, if requested.
757
+ if [ -n " ${PDFLOG_OUTPUT} " ]; then
758
+ mkdir -p " $( dirname ${SOURCE_DIR} /${PDFLOG_OUTPUT} ) "
759
+ cp " ${LATEX_LOG} " " ${SOURCE_DIR} /${PDFLOG_OUTPUT} "
760
+ fi
714
761
fi
715
762
716
763
# Generate the docx output
@@ -724,6 +771,32 @@ if [ -n "${HTML_OUTPUT}" ]; then
724
771
do_html " ${BUILD_DIR} /${INPUT_FILE} " " ${SOURCE_DIR} /${HTML_OUTPUT} "
725
772
fi
726
773
774
+ # Generate the diff output
775
+ # Do this last so we can do whatever we want to the build directory
776
+ readonly TEMP_DIFFBASE_TEX_FILE=" ${BUILD_DIR} /${INPUT_FILE} .diffbase.tex"
777
+ readonly TEMP_DIFF_TEX_FILE=" ${BUILD_DIR} /${INPUT_FILE} .diff.tex"
778
+ readonly TEMP_LATEXDIFF_LOG=" ${BUILD_DIR} /latexdiff.log"
779
+ export MERMAID_FILTER_FORMAT=" pdf"
780
+ if [ -n " ${DIFFPDF_OUTPUT} " ]; then
781
+ git reset --hard ${DIFFBASE}
782
+
783
+ do_md_fixups " ${BUILD_DIR} /${INPUT_FILE} "
784
+ do_latex " ${BUILD_DIR} /${INPUT_FILE} " " ${TEMP_DIFFBASE_TEX_FILE} "
785
+ latexdiff --type PDFCOMMENT --driver " ${PDF_ENGINE} " " ${TEMP_DIFFBASE_TEX_FILE} " " ${TEMP_TEX_FILE} " > " ${TEMP_DIFF_TEX_FILE} " 2> " ${TEMP_LATEXDIFF_LOG} "
786
+ do_tex_fixups " ${TEMP_DIFF_TEX_FILE} "
787
+ do_pdf " ${TEMP_DIFF_TEX_FILE} " " ${SOURCE_DIR} /${DIFFPDF_OUTPUT} " " ${LATEX_LOG} "
788
+
789
+ # Copy the logs, if requested. Note that this file gets the latexdiff and PDF driver output.
790
+ if [ -n " ${DIFFPDFLOG_OUTPUT} " ]; then
791
+ mkdir -p " $( dirname ${SOURCE_DIR} /${DIFFPDFLOG_OUTPUT} ) "
792
+ echo " latexdiff output:" > " ${SOURCE_DIR} /${DIFFPDFLOG_OUTPUT} "
793
+ cat " ${TEMP_LATEXDIFF_LOG} " >> " ${SOURCE_DIR} /${DIFFPDFLOG_OUTPUT} "
794
+ echo " " >> " ${SOURCE_DIR} /${DIFFPDFLOG_OUTPUT} "
795
+ echo " ${PDF_ENGINE} output:" >> " ${SOURCE_DIR} /${DIFFPDFLOG_OUTPUT} "
796
+ cat " ${LATEX_LOG} " >> " ${SOURCE_DIR} /${DIFFPDFLOG_OUTPUT} "
797
+ fi
798
+ fi
799
+
727
800
if [ " ${FAILED} " = " true" ]; then
728
801
echo " Overall workflow failed"
729
802
exit 1
0 commit comments