Skip to content

Commit 588e314

Browse files
committed
8331886: Allow markdown src file overrides
Reviewed-by: ihse
1 parent 0d1216c commit 588e314

File tree

2 files changed

+66
-63
lines changed

2 files changed

+66
-63
lines changed

make/Docs.gmk

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -681,28 +681,25 @@ ifeq ($(ENABLE_PANDOC), true)
681681
$(TOPDIR)/make/jdk/src/classes/build/tools/pandocfilter)
682682

683683
$(foreach m, $(ALL_MODULES), \
684-
$(eval MAN_$m := $(call FindModuleManDirs, $m)) \
685-
$(foreach d, $(MAN_$m), \
686-
$(foreach f, $(call ApplySpecFilter, $(filter %.md, $(call FindFiles, $d))), \
687-
$(eval $m_$f_NAME := MAN_TO_HTML_$m_$(strip $(call RelativePath, $f, $(TOPDIR)))) \
688-
$(eval $(call SetupProcessMarkdown, $($m_$f_NAME), \
689-
SRC := $d, \
690-
FILES := $f, \
691-
DEST := $(DOCS_OUTPUTDIR)/specs/man, \
692-
FILTER := $(PANDOC_HTML_MANPAGE_FILTER), \
693-
CSS := $(GLOBAL_SPECS_DEFAULT_CSS_FILE), \
694-
REPLACEMENTS := \
695-
@@COPYRIGHT_YEAR@@ => $(COPYRIGHT_YEAR) ; \
696-
@@VERSION_SHORT@@ => $(VERSION_SHORT) ; \
697-
@@VERSION_SPECIFICATION@@ => $(VERSION_SPECIFICATION), \
698-
OPTIONS := --toc -V include-before='$(SPECS_TOP)' -V include-after='$(SPECS_BOTTOM_1)', \
699-
POST_PROCESS := $(TOOL_FIXUPPANDOC) --insert-nav --nav-right-info '$(HEADER_RIGHT_SIDE_INFO)' \
700-
--nav-subdirs 1 --nav-link-guides, \
701-
EXTRA_DEPS := $(PANDOC_HTML_MANPAGE_FILTER) \
702-
$(PANDOC_HTML_MANPAGE_FILTER_SOURCE), \
703-
)) \
704-
$(eval JDK_SPECS_TARGETS += $($($m_$f_NAME))) \
705-
) \
684+
$(eval MAN_$m := $(call ApplySpecFilter, $(filter %.md, $(call FindFiles, \
685+
$(call FindModuleManDirs, $m))))) \
686+
$(if $(MAN_$m), \
687+
$(eval $(call SetupProcessMarkdown, MAN_TO_HTML_$m, \
688+
FILES := $(MAN_$m), \
689+
DEST := $(DOCS_OUTPUTDIR)/specs/man, \
690+
FILTER := $(PANDOC_HTML_MANPAGE_FILTER), \
691+
CSS := $(GLOBAL_SPECS_DEFAULT_CSS_FILE), \
692+
REPLACEMENTS := \
693+
@@COPYRIGHT_YEAR@@ => $(COPYRIGHT_YEAR) ; \
694+
@@VERSION_SHORT@@ => $(VERSION_SHORT) ; \
695+
@@VERSION_SPECIFICATION@@ => $(VERSION_SPECIFICATION), \
696+
OPTIONS := --toc -V include-before='$(SPECS_TOP)' -V include-after='$(SPECS_BOTTOM_1)', \
697+
POST_PROCESS := $(TOOL_FIXUPPANDOC) --insert-nav --nav-right-info '$(HEADER_RIGHT_SIDE_INFO)' \
698+
--nav-subdirs 1 --nav-link-guides, \
699+
EXTRA_DEPS := $(PANDOC_HTML_MANPAGE_FILTER) \
700+
$(PANDOC_HTML_MANPAGE_FILTER_SOURCE), \
701+
)) \
702+
$(eval JDK_SPECS_TARGETS += $(MAN_TO_HTML_$m)) \
706703
) \
707704
)
708705

make/common/ProcessMarkdown.gmk

Lines changed: 47 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -38,48 +38,53 @@ define ProcessMarkdown
3838
$1_$2_INPUT_FILE := $3/$2
3939
$1_$2_MARKER := $$(subst /,_,$1_$2)
4040

41-
ifneq ($$($1_REPLACEMENTS), )
42-
$1_$2_PANDOC_INPUT := $$(SUPPORT_OUTPUTDIR)/markdown/$$($1_$2_MARKER)_pre.tmp
43-
44-
$$(eval $$(call SetupTextFileProcessing, $1_$2_PREPROCESSED, \
45-
SOURCE_FILES := $$($1_$2_INPUT_FILE), \
46-
OUTPUT_FILE := $$($1_$2_PANDOC_INPUT), \
47-
REPLACEMENTS := $$($1_REPLACEMENTS), \
48-
))
49-
else
50-
$1_$2_PANDOC_INPUT := $$($1_$2_INPUT_FILE)
51-
endif
52-
53-
ifneq ($$($1_POST_PROCESS), )
54-
$1_$2_PANDOC_OUTPUT := $$(SUPPORT_OUTPUTDIR)/markdown/$$($1_$2_MARKER)_post.tmp
55-
else
56-
$1_$2_PANDOC_OUTPUT := $$($1_$2_OUTPUT_FILE)
57-
endif
41+
# Only continue if this target file hasn't been processed already. This lets
42+
# the first found source file override any other with the same name.
43+
ifeq ($$($1_$2_OUTPUT_FILE_PROCESSED), )
44+
$1_$2_OUTPUT_FILE_PROCESSED := true
45+
46+
ifneq ($$($1_REPLACEMENTS), )
47+
$1_$2_PANDOC_INPUT := $$(SUPPORT_OUTPUTDIR)/markdown/$$($1_$2_MARKER)_pre.tmp
48+
49+
$$(eval $$(call SetupTextFileProcessing, $1_$2_PREPROCESSED, \
50+
SOURCE_FILES := $$($1_$2_INPUT_FILE), \
51+
OUTPUT_FILE := $$($1_$2_PANDOC_INPUT), \
52+
REPLACEMENTS := $$($1_REPLACEMENTS), \
53+
))
54+
else
55+
$1_$2_PANDOC_INPUT := $$($1_$2_INPUT_FILE)
56+
endif
5857

59-
ifneq ($$($1_CSS), )
60-
ifneq ($$(findstring https:/, $$($1_CSS)), )
61-
$1_$2_CSS_OPTION := --css '$$($1_CSS)'
58+
ifneq ($$($1_POST_PROCESS), )
59+
$1_$2_PANDOC_OUTPUT := $$(SUPPORT_OUTPUTDIR)/markdown/$$($1_$2_MARKER)_post.tmp
6260
else
63-
$1_$2_CSS := $$(strip $$(call RelativePath, $$($1_CSS), $$($1_$2_TARGET_DIR)))
64-
$1_$2_CSS_OPTION := --css '$$($1_$2_CSS)'
61+
$1_$2_PANDOC_OUTPUT := $$($1_$2_OUTPUT_FILE)
6562
endif
66-
endif
6763

68-
# This does not need to be included in VARDEPS since it's from the actual
69-
# source file. Only run the shell if the recipe gets executed below.
70-
$1_$2_OPTIONS_FROM_SRC = \
71-
$$(shell $$(GREP) _pandoc-options_: $3/$2 | $$(CUT) -d : -f 2-)
64+
ifneq ($$($1_CSS), )
65+
ifneq ($$(findstring https:/, $$($1_CSS)), )
66+
$1_$2_CSS_OPTION := --css '$$($1_CSS)'
67+
else
68+
$1_$2_CSS := $$(strip $$(call RelativePath, $$($1_CSS), $$($1_$2_TARGET_DIR)))
69+
$1_$2_CSS_OPTION := --css '$$($1_$2_CSS)'
70+
endif
71+
endif
7272

73-
ifneq ($$($1_FILTER), )
74-
$1_$2_OPTIONS := --filter $$($1_FILTER)
75-
endif
73+
# This does not need to be included in VARDEPS since it's from the actual
74+
# source file. Only run the shell if the recipe gets executed below.
75+
$1_$2_OPTIONS_FROM_SRC = \
76+
$$(shell $$(GREP) _pandoc-options_: $3/$2 | $$(CUT) -d : -f 2-)
77+
78+
ifneq ($$($1_FILTER), )
79+
$1_$2_OPTIONS := --filter $$($1_FILTER)
80+
endif
7681

77-
$1_$2_VARDEPS := $$($1_OPTIONS) $$($1_$2_OPTIONS) $$($1_CSS) \
78-
$$($1_REPLACEMENTS) $$($1_POST_PROCESS)
79-
$1_$2_VARDEPS_FILE := $$(call DependOnVariable, $1_$2_VARDEPS, \
80-
$$(SUPPORT_OUTPUTDIR)/markdown/$$($1_$2_MARKER).vardeps)
82+
$1_$2_VARDEPS := $$($1_OPTIONS) $$($1_$2_OPTIONS) $$($1_CSS) \
83+
$$($1_REPLACEMENTS) $$($1_POST_PROCESS)
84+
$1_$2_VARDEPS_FILE := $$(call DependOnVariable, $1_$2_VARDEPS, \
85+
$$(SUPPORT_OUTPUTDIR)/markdown/$$($1_$2_MARKER).vardeps)
8186

82-
$$($1_$2_PANDOC_OUTPUT): $$($1_$2_PANDOC_INPUT) $$($1_$2_VARDEPS_FILE) $$($1_EXTRA_DEPS)
87+
$$($1_$2_PANDOC_OUTPUT): $$($1_$2_PANDOC_INPUT) $$($1_$2_VARDEPS_FILE) $$($1_EXTRA_DEPS)
8388
$$(call LogInfo, Converting $2 to $$($1_FORMAT))
8489
$$(call MakeDir, $$(SUPPORT_OUTPUTDIR)/markdown $$(dir $$($1_$2_PANDOC_OUTPUT)))
8590
$$(call ExecuteWithLog, $$(SUPPORT_OUTPUTDIR)/markdown/$$($1_$2_MARKER), \
@@ -96,17 +101,18 @@ define ProcessMarkdown
96101
fi
97102
endif
98103

99-
# If we have no post processing, PANDOC_OUTPUT is set to OUTPUT_FILE. Otherwise
100-
# PANDOC_OUTPUT is a temporary file, and we must now create the real OUTPUT_FILE.
101-
ifneq ($$($1_POST_PROCESS), )
102-
$$($1_$2_OUTPUT_FILE): $$($1_$2_PANDOC_OUTPUT)
104+
# If we have no post processing, PANDOC_OUTPUT is set to OUTPUT_FILE. Otherwise
105+
# PANDOC_OUTPUT is a temporary file, and we must now create the real OUTPUT_FILE.
106+
ifneq ($$($1_POST_PROCESS), )
107+
$$($1_$2_OUTPUT_FILE): $$($1_$2_PANDOC_OUTPUT)
103108
$$(call LogInfo, Post-processing markdown file $2)
104109
$$(call MakeDir, $$(SUPPORT_OUTPUTDIR)/markdown $$($1_$2_TARGET_DIR))
105110
$$(call ExecuteWithLog, $$(SUPPORT_OUTPUTDIR)/markdown/$$($1_$2_MARKER)_post, \
106111
( $$($1_POST_PROCESS) $$($1_$2_PANDOC_OUTPUT) > $$($1_$2_OUTPUT_FILE) ) )
107-
endif
112+
endif
108113

109-
$1 += $$($1_$2_OUTPUT_FILE)
114+
$1 += $$($1_$2_OUTPUT_FILE)
115+
endif
110116
endef
111117

112118
################################################################################

0 commit comments

Comments
 (0)