Rework doc generation to simplify and centralize

Just do all doc generation in the hack::util::gen-docs instead of spread
around. We also only track the generated docs in a single file for the
whole tree.
This commit is contained in:
Eric Paris
2015-08-20 19:17:26 -07:00
parent 9cf7bb6b4f
commit 58d6b29e97
7 changed files with 120 additions and 143 deletions

View File

@@ -155,60 +155,49 @@ kube::util::wait-for-jobs() {
return ${fail}
}
# Takes a binary to run $1 and then copies the results to $2.
# If the generated and original files are the same after filtering lines
# that match $3, copy is skipped.
kube::util::gen-doc() {
local cmd="$1"
local base_dest="$(kube::util::realpath $2)"
local relative_doc_dest="$(echo $3 | sed 's/\/$//')"
local dest="${base_dest}/${relative_doc_dest}"
local skipprefix="${4:-}"
# Run all known doc generators (today gendocs, genman, and genbashcomp for kubectl)
# $1 is the directory to put those generated documents
kube::util::gen-docs() {
local dest="$1"
# Find binary
gendocs=$(kube::util::find-binary "gendocs")
genman=$(kube::util::find-binary "genman")
genbashcomp=$(kube::util::find-binary "genbashcomp")
mkdir -p "${dest}/docs/user-guide/kubectl/"
"${gendocs}" "${dest}/docs/user-guide/kubectl/"
mkdir -p "${dest}/docs/man/man1/"
"${genman}" "${dest}/docs/man/man1/"
mkdir -p "${dest}/contrib/completions/bash/"
"${genbashcomp}" "${dest}/contrib/completions/bash/"
# We do this in a tmpdir in case the dest has other non-autogenned files
# We don't want to include them in the list of gen'd files
local tmpdir="${KUBE_ROOT}/doc_tmp"
mkdir -p "${tmpdir}"
# generate the new files
${cmd} "${tmpdir}"
# create the list of generated files
ls "${tmpdir}" | LC_ALL=C sort > "${tmpdir}/.files_generated"
pushd "${dest}" > /dev/null
touch .generated_docs
find -type f | cut -sd / -f 2- | LC_ALL=C sort > .generated_docs
popd > /dev/null
while read file; do
# Don't add analytics link to generated .md files -- that is done (and
# checked) by mungedocs.
# Remove all old generated files from the destination
if [[ -e "${tmpdir}/${file}" ]]; then
local original generated
# Copy out of KUBE_ROOT if we didn't really change anything
if [[ -e "${dest}/${file}" && -e "${KUBE_ROOT}/${file}" ]]; then
# Filter all munges from original content.
original=$(cat "${dest}/${file}" | sed '/^<!-- BEGIN MUNGE:.*/,/^<!-- END MUNGE:.*/d')
generated=$(cat "${tmpdir}/${file}")
# If this function was asked to filter lines with a prefix, do so.
if [[ -n "${skipprefix}" ]]; then
original=$(echo "${original}" | grep -v "^${skipprefix}" || :)
generated=$(echo "${generated}" | grep -v "^${skipprefix}" || :)
fi
original=$(cat "${KUBE_ROOT}/${file}" | sed '/^<!-- BEGIN MUNGE:.*/,/^<!-- END MUNGE:.*/d')
generated=$(cat "${dest}/${file}")
# Filter out meaningless lines with timestamps
original=$(echo "${original}" | grep -v "Auto generated by spf13/cobra" || :)
generated=$(echo "${generated}" | grep -v "Auto generated by spf13/cobra" || :)
# By now, the contents should be normalized and stripped of any
# auto-managed content. We also ignore whitespace here because of
# markdown strictness fixups later in the pipeline.
if diff -Bw <(echo "${original}") <(echo "${generated}") > /dev/null; then
if diff -Bw >/dev/null <(echo "${original}") <(echo "${generated}"); then
# actual contents same, overwrite generated with original.
mv "${dest}/${file}" "${tmpdir}/${file}"
cp "${KUBE_ROOT}/${file}" "${dest}/${file}"
fi
else
rm "${dest}/${file}" || true
fi
done <"${dest}/.files_generated"
# put the new generated file into the destination
# the shopt is so that we get .files_generated from the glob.
shopt -s dotglob
cp -af "${tmpdir}"/* "${dest}"
shopt -u dotglob
#cleanup
rm -rf "${tmpdir}"
done <"${KUBE_ROOT}/.generated_docs"
}
# Takes a path $1 to traverse for md files to append the ga-beacon tracking