* Final changes in logic to make man page processing work as intended. ihse-manpages-branch
authorihse
Mon, 26 Nov 2018 18:50:55 +0100
branchihse-manpages-branch
changeset 57045 9c7f4a3c4139
parent 57044 37a5eb9384d3
child 57046 bb6e39ffd206
* Final changes in logic to make man page processing work as intended. * Add support for macosx pandoc bundle * Fix race for generating pandoc filter wrapper
make/CompileToolsJdk.gmk
make/ToolsJdk.gmk
make/common/ProcessMarkdown.gmk
make/devkit/createPandocBundle.sh
make/launcher/LauncherCommon.gmk
--- a/make/CompileToolsJdk.gmk	Mon Nov 26 14:18:32 2018 +0100
+++ b/make/CompileToolsJdk.gmk	Mon Nov 26 18:50:55 2018 +0100
@@ -29,6 +29,7 @@
 include MakeBase.gmk
 include JavaCompilation.gmk
 include SetupJavaCompilers.gmk
+include TextFileProcessing.gmk
 
 ################################################################################
 
@@ -87,4 +88,30 @@
 
 ################################################################################
 
+# To be able to call the javascript filter when generating man pages using
+# pandoc, we need to create this executable wrapper script.
+ifneq ($(PANDOC), )
+  # PANDOC_FILTER is duplicated for export in ToolsJdk.gmk.
+  PANDOC_FILTER := $(BUILDTOOLS_OUTPUTDIR)/manpages/pandoc-manpage-filter
+  PANDOC_FILTER_SETUP := $(BUILDTOOLS_OUTPUTDIR)/manpages/_pandoc_filter_setup.marker
+
+  # Create a usable instance of the wrapper script that calls the pandoc filter
+  # (which is written in javascript).
+  $(eval $(call SetupTextFileProcessing, CREATE_PANDOC_FILTER, \
+      SOURCE_FILES := $(TOPDIR)/make/scripts/pandoc-manpage-filter.sh.template, \
+      OUTPUT_FILE := $(PANDOC_FILTER), \
+      REPLACEMENTS := \
+          @@BOOT_JDK@@ => $(BOOT_JDK) ; \
+          @@TOPDIR@@ => $(TOPDIR) ; \
+          @@JJS_FLAGS@@ => $(addprefix -J, $(JAVA_FLAGS_SMALL)), \
+  ))
+
+  # Created script must be made executable
+  $(PANDOC_FILTER_SETUP): $(CREATE_PANDOC_FILTER)
+		$(CHMOD) a+rx $(PANDOC_FILTER)
+		$(TOUCH) $@
+
+  TARGETS += $(PANDOC_FILTER_SETUP)
+endif
+
 all: $(TARGETS)
--- a/make/ToolsJdk.gmk	Mon Nov 26 14:18:32 2018 +0100
+++ b/make/ToolsJdk.gmk	Mon Nov 26 18:50:55 2018 +0100
@@ -116,4 +116,10 @@
 
 ##########################################################################################
 
+# Executable javascript filter for man page generation using pandoc.
+
+PANDOC_FILTER := $(BUILDTOOLS_OUTPUTDIR)/manpages/pandoc-manpage-filter
+
+##########################################################################################
+
 endif # _TOOLS_GMK
--- a/make/common/ProcessMarkdown.gmk	Mon Nov 26 14:18:32 2018 +0100
+++ b/make/common/ProcessMarkdown.gmk	Mon Nov 26 18:50:55 2018 +0100
@@ -30,11 +30,12 @@
 
 # Helper function for SetupProcessMarkdown
 # $1: The $1 from SetupProcessMarkdown
-# $2: The name of the current source file, relative to $1_SRC
+# $2: The name of the current source file, relative to the dir given in $3
+# $3: The directory of the current source file
 define ProcessMarkdown
   $1_$2_OUTPUT_FILE := $$($1_DEST)/$$(basename $2)$$($1_FILE_EXT)
   $1_$2_TARGET_DIR := $$(dir $$($1_$2_OUTPUT_FILE))
-  $1_$2_INPUT_FILE := $$($1_SRC)/$2
+  $1_$2_INPUT_FILE := $3/$2
   $1_$2_MARKER := $$(subst /,_,$1_$2)
 
   ifneq ($$($1_REPLACEMENTS), )
@@ -64,7 +65,7 @@
     endif
   endif
 
-  $1_$2_OPTIONS := $$(shell $$(GREP) _pandoc-options_: $$($1_SRC)/$2 | $$(CUT) -d : -f 2-)
+  $1_$2_OPTIONS := $$(shell $$(GREP) _pandoc-options_: $3/$2 | $$(CUT) -d : -f 2-)
 
   ifneq ($$($1_FILTER), )
     $1_$2_OPTIONS += --filter $$($1_FILTER)
@@ -111,10 +112,10 @@
 # and the targets generated are listed in a variable by that name.
 #
 # Remaining parameters are named arguments. These include:
-#   SRC      : Source root dir (defaults to dir of first file)
-#   DEST     : Dest root dir
+#   DEST     : Destination root dir
 #   FILES    : List of files to copy with absolute paths, or path relative to SRC.
-#              Must be in SRC.
+#   SRC      : Source root dir; if given keep input files hierarchy relative to
+#              SRC in DEST, otherwise flatten structure into DEST.
 #   FORMAT   : The target format (defaults to html5)
 #   FILE_EXT : The file extension to replace .md with (defaults to .html)
 #   OPTIONS  : Additional options to pandoc
@@ -133,11 +134,6 @@
     $$(error DEST is missing in SetupProcessMarkdown $1)
   endif
 
-  # Default SRC to the dir of the first file.
-  ifeq ($$($1_SRC), )
-    $1_SRC := $$(dir $$(firstword $$($1_FILES)))
-  endif
-
   # If no target format is specified, default to html5.
   ifeq ($$($1_FORMAT), )
     $1_FORMAT := html5
@@ -158,11 +154,23 @@
     endif
   endif
 
-  # Remove any trailing slash from SRC and DEST
-  $1_SRC := $$(patsubst %/,%,$$($1_SRC))
+  # Remove any trailing slash
   $1_DEST := $$(patsubst %/,%,$$($1_DEST))
 
-  $$(foreach f, $$(patsubst $$($1_SRC)/%,%,$$($1_FILES)), \
-    $$(eval $$(call ProcessMarkdown,$1,$$f)) \
-  )
+  ifeq ($$($1_SRC), )
+    # No SRC given, assume we're flattening all files into output dir.
+    $$(foreach f, $$($1_FILES), \
+      $$(eval $$(call ProcessMarkdown,$1,$$(notdir $$f),$$(patsubst %/,%,$$(dir $$f)))) \
+    )
+  else
+    # Remove any trailing slash
+    $1_SRC := $$(patsubst %/,%,$$($1_SRC))
+
+    $$(foreach f, $$(patsubst $$($1_SRC)/%,%,$$($1_FILES)), \
+      $$(eval $$(call ProcessMarkdown,$1,$$f,$$($1_SRC))) \
+    )
+  endif
+
+
+
 endef
--- a/make/devkit/createPandocBundle.sh	Mon Nov 26 14:18:32 2018 +0100
+++ b/make/devkit/createPandocBundle.sh	Mon Nov 26 18:50:55 2018 +0100
@@ -33,14 +33,29 @@
 cd "$TMPDIR"
 PANDOC_VERSION=2.3.1
 PACKAGE_VERSION=1.0
-TARGET_PLATFORM=linux_x64
+TARGET_PLATFORM=macosx_x64
+
+if [[ $TARGET_PLATFORM == linux_x64 ]] ; then
+  PANDOC_PLATFORM=linux
+  PANDOC_SUFFIX=tar.gz
+elif [[ $TARGET_PLATFORM == macosx_x64 ]] ; then
+  PANDOC_PLATFORM=macOS
+  PANDOC_SUFFIX=zip
+else
+  echo "Unknown platform"
+  exit 1
+fi
 BUNDLE_NAME=pandoc-$TARGET_PLATFORM-$PANDOC_VERSION+$PACKAGE_VERSION.tar.gz
 
-wget https://github.com/jgm/pandoc/releases/download/$PANDOC_VERSION/pandoc-$PANDOC_VERSION-linux.tar.gz
+wget https://github.com/jgm/pandoc/releases/download/$PANDOC_VERSION/pandoc-$PANDOC_VERSION-$PANDOC_PLATFORM.$PANDOC_SUFFIX
 
 mkdir tmp
 cd tmp
-tar xzf ../pandoc-$PANDOC_VERSION-linux.tar.gz
+if [[ $PANDOC_SUFFIX == zip ]]; then
+  unzip ../pandoc-$PANDOC_VERSION-$PANDOC_PLATFORM.$PANDOC_SUFFIX
+else
+  tar xzf ../pandoc-$PANDOC_VERSION-$PANDOC_PLATFORM.$PANDOC_SUFFIX
+fi
 cd ..
 
 mkdir pandoc
--- a/make/launcher/LauncherCommon.gmk	Mon Nov 26 14:18:32 2018 +0100
+++ b/make/launcher/LauncherCommon.gmk	Mon Nov 26 18:50:55 2018 +0100
@@ -26,7 +26,7 @@
 include Modules.gmk
 include JdkNativeCompilation.gmk
 include ProcessMarkdown.gmk
-include TextFileProcessing.gmk
+include ToolsJdk.gmk
 
 # Tell the compiler not to export any functions unless declared so in
 # the source code. On Windows, this is the default and cannot be changed.
@@ -199,40 +199,24 @@
 # relationship between executables and man pages (even if this is not always
 # the case), so piggyback man page generation on the launcher compilation.
 
-# Only build manpages on unix systems
-ifeq ($(TARGET_OS_TYPE), unix)
-  MAN_$(MODULE) := $(call FindModuleManDirs, $(MODULE))
+ifeq ($(OPENJDK_TARGET_OS_TYPE), unix)
+  # Only build manpages on unix systems.
+  # We assume all our man pages should reside in section 1.
 
-  MAN_FILES_MD := $(wildcard $(addsuffix /*.md, $(call FindModuleManDirs, $(MODULE)))
-  MAN_FILES_TROFF := $(wildcard $(addsuffix /*.1, $(call FindModuleManDirs, $(MODULE)))
+  MAN_FILES_MD := $(wildcard $(addsuffix /*.md, $(call FindModuleManDirs, $(MODULE))))
+  MAN_FILES_TROFF := $(wildcard $(addsuffix /*.1, $(call FindModuleManDirs, $(MODULE))))
 
   ifneq ($(MAN_FILES_MD), )
     # If we got markdown files, ignore the troff files
     ifeq ($(PANDOC), )
       $(info Warning: pandoc not found. Not generating man pages)
     else
-      # Create dynamic man pages from markdown using pandoc.
-      # We assume all man pages should reside in section 1.
-
-      PANDOC_FILTER := $(SUPPORT_OUTPUTDIR)/docs/pandoc-manpage-filter
-      PANDOC_FILTER_SETUP := $(SUPPORT_OUTPUTDIR)/docs/_pandoc_filter_setup.marker
-      PANDOC_FILTER_JAVASCRIPT := $(TOPDIR)/make/scripts/pandoc-manpage-filter.js
+      # Create dynamic man pages from markdown using pandoc. We need
+      # PANDOC_FILTER, a wrapper around PANDOC_FILTER_JAVASCRIPT. This is
+      # created by buildtools-jdk.
 
-      # Create a usable instance of the wrapper script that calls the pandoc filter
-      # (which is written in javascript).
-      $(eval $(call SetupTextFileProcessing, CREATE_PANDOC_FILTER, \
-          SOURCE_FILES := $(TOPDIR)/make/scripts/pandoc-manpage-filter.sh.template, \
-          OUTPUT_FILE := $(PANDOC_FILTER), \
-          REPLACEMENTS := \
-              @@BOOT_JDK@@ => $(BOOT_JDK) ; \
-              @@TOPDIR@@ => $(TOPDIR) ; \
-              @@JJS_FLAGS@@ => $(addprefix -J, $(JAVA_FLAGS_SMALL)), \
-      ))
-
-      # Created script must be made executable
-      $(PANDOC_FILTER_SETUP): $(CREATE_PANDOC_FILTER)
-		$(CHMOD) a+rx $(PANDOC_FILTER)
-		$(TOUCH) $@
+      # We should also depend on the source javascript filter
+      PANDOC_FILTER_JAVASCRIPT := $(TOPDIR)/make/scripts/pandoc-manpage-filter.js
 
       # The norm in man pages is to display code literals as bold, but pandoc
       # "correctly" converts these constructs (encoded in markdown using `...`
@@ -251,36 +235,28 @@
           -e 's/\\f\[\]/\\f\[R\]/g'
 
       # Now generate the man pages from markdown using pandoc
-      MAN_$(MODULE) := $(call FindModuleManDirs, $(MODULE))
+      $(eval $(call SetupProcessMarkdown, BUILD_MAN_PAGES, \
+          DEST := $(SUPPORT_OUTPUTDIR)/modules_man/$(MODULE)/man1, \
+          FILES := $(MAN_FILES_MD), \
+          FORMAT := man, \
+          FILTER := $(PANDOC_FILTER), \
+          POST_PROCESS := $(MAN_POST_PROCESS), \
+          REPLACEMENTS := @@VERSION_SHORT@@ => $(VERSION_SHORT), \
+          EXTRA_DEPS := $(PANDOC_FILTER) $(PANDOC_FILTER_JAVASCRIPT), \
+      ))
 
-      $(foreach d, $(MAN_$(MODULE)), \
-        $(if $(filter %.md, $(call CacheFind, $d)), \
-          $(eval $(MODULE)_$d_NAME := MAN_TO_TROFF_$(MODULE)_$(strip $(call RelativePath, $d, $(TOPDIR)))) \
-          $(eval $(call SetupProcessMarkdown, $($(MODULE)_$d_NAME), \
-              SRC := $d, \
-              FILES := $(filter %.md, $(call CacheFind, $d)), \
-              DEST := $(SUPPORT_OUTPUTDIR)/modules_man/$(MODULE)/man1, \
-              FORMAT := man, \
-              EXTRA_DEPS := $(PANDOC_FILTER_SETUP) \
-                  $(PANDOC_FILTER_JAVASCRIPT), \
-              FILTER := $(PANDOC_FILTER), \
-              POST_PROCESS := $(MAN_POST_PROCESS), \
-              REPLACEMENTS := @@VERSION_SHORT@@ => $(VERSION_SHORT), \
-          )) \
-          $(eval MAN_PAGE_TARGETS += $($($(MODULE)_$d_NAME))) \
-        ) \
-      )
-      TARGETS += $(MAN_PAGE_TARGETS)
+      TARGETS += $(BUILD_MAN_PAGES)
     endif
   else
     # No markdown man pages present
-    ifeq ($(MAN_PAGES_ENABLED), true)
-      # This is a mis-nomer. It really means "copy the pre-generated man pages".
-      $(eval $(call SetupCopyFiles, COPY_MAN_FILES,
-          DEST := $(SUPPORT_OUTPUTDIR)/modules_man/$(MODULE)/man1,
-          FILES := $(MAN_FILES_MD),
+    ifeq ($(BUILD_MANPAGES), true)
+      # BUILD_MANPAGES is a mis-nomer. It really means "copy the pre-generated man pages".
+      $(eval $(call SetupCopyFiles, COPY_MAN_PAGES, \
+          DEST := $(SUPPORT_OUTPUTDIR)/modules_man/$(MODULE)/man1, \
+          FILES := $(MAN_FILES_TROFF), \
       ))
-      TARGETS += $(COPY_MAN_FILES)
+
+      TARGETS += $(COPY_MAN_PAGES)
     endif
   endif
 endif