Skip to content

Commit

Permalink
docs.eclass: allow multiple doc builders in one ebuild
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Ammerlaan <[email protected]>
  • Loading branch information
Nowa-Ammerlaan committed Nov 16, 2022
1 parent e3914dd commit e22fee1
Showing 1 changed file with 28 additions and 18 deletions.
46 changes: 28 additions & 18 deletions eclass/docs.eclass
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 1999-2021 Gentoo Authors
# Copyright 1999-2022 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

# @ECLASS: docs.eclass
Expand Down Expand Up @@ -207,16 +207,15 @@ sphinx_deps() {
}

# @FUNCTION: sphinx_compile
# @INTERNAL
# @DESCRIPTION:
# Calls sphinx to build docs.
#
# If you overwrite python_compile_all do not call
# this function, call docs_compile instead
sphinx_compile() {
debug-print-function ${FUNCNAME}
use doc || return

: ${DOCS_DIR:="${S}"}
: ${DOCS_OUTDIR:="${S}/_build/html/sphinx"}

local confpy=${DOCS_DIR}/conf.py
[[ -f ${confpy} ]] ||
die "${FUNCNAME}: ${confpy} not found, DOCS_DIR=${DOCS_DIR} call wrong"
Expand All @@ -236,6 +235,12 @@ sphinx_compile() {
# not all packages include the Makefile in pypi tarball
sphinx-build -b html -d "${DOCS_OUTDIR}"/_build/doctrees "${DOCS_DIR}" \
"${DOCS_OUTDIR}" || die "${FUNCNAME}: sphinx-build failed"

HTML_DOCS+=( "${DOCS_OUTDIR}" )

# We don't need these any more, unset them in case we want to call a
# second documentation builder.
unset DOCS_DIR DOCS_OUTDIR
}

# @FUNCTION: mkdocs_deps
Expand Down Expand Up @@ -263,16 +268,15 @@ mkdocs_deps() {
}

# @FUNCTION: mkdocs_compile
# @INTERNAL
# @DESCRIPTION:
# Calls mkdocs to build docs.
#
# If you overwrite python_compile_all do not call
# this function, call docs_compile instead
mkdocs_compile() {
debug-print-function ${FUNCNAME}
use doc || return

: ${DOCS_DIR:="${S}"}
: ${DOCS_OUTDIR:="${S}/_build/html/mkdocs"}

local mkdocsyml=${DOCS_DIR}/mkdocs.yml
[[ -f ${mkdocsyml} ]] ||
die "${FUNCNAME}: ${mkdocsyml} not found, DOCS_DIR=${DOCS_DIR} wrong"
Expand All @@ -285,6 +289,12 @@ mkdocs_compile() {
# mkdocs currently has no option to disable this
# and portage complains: "Colliding files found by ecompress"
rm "${DOCS_OUTDIR}"/*.gz || die

HTML_DOCS+=( "${DOCS_OUTDIR}" )

# We don't need these any more, unset them in case we want to call a
# second documentation builder.
unset DOCS_DIR DOCS_OUTDIR
}

# @FUNCTION: doxygen_deps
Expand All @@ -299,14 +309,16 @@ doxygen_deps() {
}

# @FUNCTION: doxygen_compile
# @INTERNAL
# @DESCRIPTION:
# Calls doxygen to build docs.
doxygen_compile() {
debug-print-function ${FUNCNAME}
use doc || return

# This is the default name of the config file, upstream can change it.
: ${DOCS_CONFIG_NAME:="Doxyfile"}
: ${DOCS_DIR:="${S}"}
: ${DOCS_OUTDIR:="${S}/_build/html/doxygen"}

local doxyfile=${DOCS_DIR}/${DOCS_CONFIG_NAME}
[[ -f ${doxyfile} ]] ||
Expand All @@ -318,6 +330,12 @@ doxygen_compile() {
pushd "${DOCS_DIR}" || die
(cat "${DOCS_CONFIG_NAME}" ; echo "HTML_OUTPUT=${DOCS_OUTDIR}") | doxygen - || die "${FUNCNAME}: doxygen failed"
popd || die

HTML_DOCS+=( "${DOCS_OUTDIR}" )

# We don't need these any more, unset them in case we want to call a
# second documentation builder.
unset DOCS_DIR DOCS_OUTDIR DOCS_CONFIG_NAME
}

# @FUNCTION: docs_compile
Expand All @@ -343,16 +361,8 @@ docs_compile() {
debug-print-function ${FUNCNAME}
use doc || return

# Set a sensible default as DOCS_DIR
: ${DOCS_DIR:="${S}"}

# Where to put the compiled files?
: ${DOCS_OUTDIR:="${S}/_build/html"}

${DOCS_BUILDER}_compile

HTML_DOCS+=( "${DOCS_OUTDIR}/." )

# we need to ensure successful return in case we're called last,
# otherwise Portage may wrongly assume sourcing failed
return 0
Expand Down

0 comments on commit e22fee1

Please sign in to comment.