Fix race in ProcessMarkdown. ihse-manpages-branch
authorihse
Fri, 23 Nov 2018 12:19:38 +0100
branchihse-manpages-branch
changeset 57035 f7a879e76ab8
parent 57034 6f85b6e0f8f8
child 57036 7f3d846038fc
Fix race in ProcessMarkdown.
make/common/ProcessMarkdown.gmk
--- a/make/common/ProcessMarkdown.gmk	Fri Nov 23 11:32:02 2018 +0100
+++ b/make/common/ProcessMarkdown.gmk	Fri Nov 23 12:19:38 2018 +0100
@@ -75,17 +75,13 @@
   $1_$2_VARDEPS_FILE := $$(call DependOnVariable, $1_$2_VARDEPS, \
       $$(SUPPORT_OUTPUTDIR)/markdown/$$($1_$2_MARKER).vardeps)
 
-$$($1_$2_OUTPUT_FILE): $$($1_$2_PANDOC_INPUT) $$($1_$2_VARDEPS_FILE) $$($1_EXTRA_DEPS)
+$$($1_$2_PANDOC_OUTPUT): $$($1_$2_PANDOC_INPUT) $$($1_$2_VARDEPS_FILE) $$($1_EXTRA_DEPS)
 	$$(call LogInfo, Converting $2 to $$($1_FORMAT))
-	$$(call MakeDir, $$($1_$2_TARGET_DIR) $$(SUPPORT_OUTPUTDIR)/markdown)
+	$$(call MakeDir, $$(SUPPORT_OUTPUTDIR)/markdown $$(dir $$($1_$2_PANDOC_OUTPUT)))
 	$$(call ExecuteWithLog, $$(SUPPORT_OUTPUTDIR)/markdown/$$($1_$2_MARKER), \
 	    $$(PANDOC) $$($1_OPTIONS) -f markdown -t $$($1_FORMAT) --standalone \
 	    $$($1_$2_CSS_OPTION) $$($1_$2_OPTIONS) '$$($1_$2_PANDOC_INPUT)' \
 	    -o '$$($1_$2_PANDOC_OUTPUT)')
-        ifneq ($$($1_POST_PROCESS), )
-	  $$(call ExecuteWithLog, $$(SUPPORT_OUTPUTDIR)/markdown/$$($1_$2_MARKER)_post, \
-	      $$($1_POST_PROCESS) < $$($1_$2_PANDOC_OUTPUT) > $$($1_$2_OUTPUT_FILE))
-        endif
         ifneq ($$(findstring $$(LOG_LEVEL), debug trace),)
 	  TOO_LONG_LINES=`$$(GREP) -E -e '^.{80}.+$$$$' $$<` || true ; \
 	  if [ "x$$$$TOO_LONG_LINES" != x ]; then \
@@ -95,6 +91,16 @@
 	  fi
         endif
 
+  # If we have no post processing, PANDOC_OUTPUT is set to OUTPUT_FILE. Otherwise
+  # PANDOC_OUTPUT is a temporary file, and we must now create the real OUTPUT_FILE.
+  ifneq ($$($1_POST_PROCESS), )
+$$($1_$2_OUTPUT_FILE): $$($1_$2_PANDOC_OUTPUT)
+	$$(call LogInfo, Post-processing markdown file $2)
+	$$(call MakeDir, $$(SUPPORT_OUTPUTDIR)/markdown $$($1_$2_TARGET_DIR))
+	$$(call ExecuteWithLog, $$(SUPPORT_OUTPUTDIR)/markdown/$$($1_$2_MARKER)_post, \
+	    $$($1_POST_PROCESS) < $$($1_$2_PANDOC_OUTPUT) > $$($1_$2_OUTPUT_FILE))
+  endif
+
   $1 += $$($1_$2_OUTPUT_FILE)
 endef