Skip to content

Commit

Permalink
Take recursive includes into account for adoc filelist
Browse files Browse the repository at this point in the history
list-srcfiles on adoc MAINs now also lists docinfo-files and includes
from includes
  • Loading branch information
fsundermeyer committed Dec 20, 2022
1 parent 93fd0ab commit 7506323
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 9 deletions.
3 changes: 2 additions & 1 deletion bin/daps.in
Original file line number Diff line number Diff line change
Expand Up @@ -1678,9 +1678,10 @@ export SETFILES_TMP
if [[ "adoc" = "$SRC_FORMAT" ]]; then
ADOC_MAIN="$MAIN"
ADOC_RESULT_DIR="${BUILD_DIR}/.adoc"
ADOC_SRC_DIR="$SRC_DIR"
MAIN="${ADOC_RESULT_DIR}/${BOOK}.xml"

export ADOC_MAIN ADOC_RESULT_DIR MAIN
export ADOC_MAIN ADOC_RESULT_DIR ADOC_SRC_DIR MAIN
[[ 2 -gt $VERBOSITY ]] && MOPTS="$MOPTS --silent"
# we always want to create a fresh bigfile
#
Expand Down
31 changes: 31 additions & 0 deletions libexec/get_adoc_includes.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash
#
# Copyright (C) 2012-2022 SUSE Software Solutions Germany GmbH
#
# Author:
# Frank Sundermeyer <fsundermeyer at opensuse dot org>
#
# Recursively get include files from an asciidoc "main" file
#
# include statements always start at the begin of the line, no other
# characters (incl. space) are allowed before it, so a grep for
# /^include::/ seems to be a safe enough
#

main="$1"
includes=$(basename "$main")

function include_grep {
local f
f=$(grep -E '^include::' $@ 2>/dev/null | sed 's/.*::\.\/\([^\[]*\).*/\1/g' 2>/dev/null)
if [[ -n $f ]]; then
includes+=" $f"
include_grep $f
else
return
fi
}

include_grep $main

echo "${includes//$'\n'/ }"
13 changes: 5 additions & 8 deletions make/adoc2xml.mk
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,12 @@ endif

# Get the adoc sourcefiles
#
# include statements always start at the begin of the line, no other
# characters (incl. space) are allowed before it
# via external script $(LIBEXEC_DIR)/get_adoc_includes.sh
# (also gets includes within includes)
#
# If grep fails, we at least have ADOC_MAIN
#
ADOC_SRCFILES := $(ADOC_MAIN) $(wildcard $(addprefix \
$(SRC_DIR)/,$(shell grep -E '^include::' $(ADOC_MAIN) 2>/dev/null | sed 's/.*::\([^\[]*\).*/\1/g' 2>/dev/null)))
#ADOC_SRCFILES := $(wildcard $(PRJ_DIR)/adoc/*.adoc)

ADOC_DOCINFO := $(addsuffix -docinfo.xml,$(basename $(ADOC_MAIN)))
ADOC_SRCFILES := $(wildcard $(addprefix $(ADOC_SRC_DIR)/,$(shell $(LIBEXEC_DIR)/get_adoc_includes.sh $(ADOC_MAIN)))) $(wildcard $(ADOC_DOCINFO))

all: $(MAIN)

Expand All @@ -112,7 +110,6 @@ all: $(MAIN)
# set -o pipefail makes sure make exits when the asciidoctor command
# returns != 0

#all: $(MAIN)
$(MAIN): $(ADOC_SRCFILES) | $(ADOC_RESULT_DIR)
ifeq "$(VERBOSITY)" "2"
@ccecho "info" " Creating XML from AsciiDoc..."
Expand Down

0 comments on commit 7506323

Please sign in to comment.