Skip to content

Commit fc3e4f6

Browse files
hcallahan-lowriscHU90mjwnrt
authored andcommitted
[doc] Setup unified build for mdbook based docs
There now exists a script `util/site/build-docs.sh`, which builds the complete site. Signed-off-by: Harry Callahan <[email protected]> Co-authored-by: Hugo McNally <[email protected]> Co-authored-by: James Wainwright <[email protected]>
1 parent 7bb573f commit fc3e4f6

14 files changed

+207
-33
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,6 @@ compile_commands.json
9090

9191
# mdbook builds into `./book` directories, let's ignore them
9292
book
93+
94+
# Hugo Lock
95+
.hugo_build.lock

book.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,6 @@ command = "./util/mdbook_dashboard.py"
5050

5151
[preprocessor.doxygen]
5252
command = "./util/mdbook_doxygen.py"
53-
out-dir = "docs/"
54-
html-out-dir = "doxy/"
53+
out-dir = "build-site/gen"
54+
html-out-dir = "gen/doxy"
5555
dif-src-py-regex = 'dif_\S*\.h'
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

site/landing/layouts/index.html

+8-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ <h1 class="logo">
3838
<nav id="main-nav" class="main-nav" aria-label="Main">
3939
<ul id="menu" class="main-nav__list">
4040
<li class="main-nav__item">
41-
<a href="https://docs.opentitan.org">Documentation</a>
41+
<a href="/book/doc/introduction.html">Documentation</a>
42+
</li>
43+
<li class="main-nav__item">
44+
<a href="/guides/getting_started">Getting&nbsp;Started</a>
4245
</li>
4346
<li class="main-nav__item">
4447
<a href="#partners">Partners</a>
@@ -312,7 +315,10 @@ <h2 class="sr-only">Join the Project</h2>
312315
<nav class="footer-nav" aria-label="Full">
313316
<ul class="footer-nav__list">
314317
<li class="footer-nav__item">
315-
<a href="https://docs.opentitan.org">Documentation</a>
318+
<a href="/book/doc/introduction.html">Documentation</a>
319+
</li>
320+
<li class="footer-nav__item">
321+
<a href="/guides/getting_started">Getting&nbsp;Started</a>
316322
</li>
317323
<li class="footer-nav__item">
318324
<a href="#partners">Partners</a>

util/doxygen/Doxyfile

+7-15
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ SHOW_NAMESPACES = NO
4646

4747
FILE_VERSION_FILTER = "git -C '$(SRCTREE_TOP)' log --format='%h' -1 --"
4848

49-
LAYOUT_FILE = "$(SRCTREE_TOP)/site/docs/doxygen/layout.xml"
49+
LAYOUT_FILE = "$(SRCTREE_TOP)/site/doxygen/layout.xml"
5050

5151
#---------------------------------------------------------------------------
5252
# Configuration options related to warning and progress messages
@@ -62,9 +62,9 @@ WARN_LOGFILE = "$(DOXYGEN_OUT)/doxygen_warnings.log"
6262
# Absolute path using $(SRCTREE_TOP)
6363
INPUT = "$(SRCTREE_TOP)/sw" \
6464
"$(SRCTREE_TOP)/hw/top_earlgrey/sw" \
65-
"$(SRCTREE_TOP)/site/docs/doxygen/main_page.md"
65+
"$(SRCTREE_TOP)/site/doxygen/main_page.md"
6666

67-
USE_MDFILE_AS_MAINPAGE = "$(SRCTREE_TOP)/site/docs/doxygen/main_page.md"
67+
USE_MDFILE_AS_MAINPAGE = "$(SRCTREE_TOP)/site/doxygen/main_page.md"
6868

6969
FILE_PATTERNS = *.h \
7070
*.c \
@@ -80,7 +80,7 @@ EXCLUDE = "$(SRCTREE_TOP)/sw/vendor" \
8080
EXCLUDE_SYMLINKS = YES
8181

8282
# Absolute path using $(SRCTREE_TOP)
83-
IMAGE_PATH = "$(SRCTREE_TOP)/site/docs/doxygen"
83+
IMAGE_PATH = "$(SRCTREE_TOP)/site/doxygen"
8484

8585
#---------------------------------------------------------------------------
8686
# Configuration options related to source browsing
@@ -93,24 +93,18 @@ REFERENCES_LINK_SOURCE = NO
9393

9494
SOURCE_TOOLTIPS = NO
9595

96-
#---------------------------------------------------------------------------
97-
# Configuration options related to the alphabetical class index
98-
#---------------------------------------------------------------------------
99-
100-
COLS_IN_ALPHA_INDEX = 2
101-
10296
#---------------------------------------------------------------------------
10397
# Configuration options related to the HTML output
10498
#---------------------------------------------------------------------------
10599

106100
GENERATE_HTML = YES
107101

108102
# Relative to `OUTPUT_DIRECTORY`
109-
HTML_OUTPUT = "public-api/sw/apis"
103+
HTML_OUTPUT = "doxy/"
110104

111105
# Absolute paths using $(SRCTREE_TOP)
112-
HTML_HEADER = "$(SRCTREE_TOP)/site/docs/doxygen/header.html"
113-
HTML_FOOTER = "$(SRCTREE_TOP)/site/docs/doxygen/footer.html"
106+
HTML_HEADER = "$(SRCTREE_TOP)/site/doxygen/header.html"
107+
HTML_FOOTER = "$(SRCTREE_TOP)/site/doxygen/footer.html"
114108

115109
HTML_COLORSTYLE_HUE = 271
116110

@@ -193,8 +187,6 @@ SKIP_FUNCTION_MACROS = YES
193187
# Configuration options related to the dot tool
194188
#---------------------------------------------------------------------------
195189

196-
CLASS_DIAGRAMS = NO
197-
198190
HAVE_DOT = NO
199191
CLASS_GRAPH = NO
200192
COLLABORATION_GRAPH = NO

util/mdbook_doxygen.py

+1-6
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,9 @@ def main() -> None:
5454

5555
file_name = Path(src_path).name
5656

57-
# First calculate the path to the generated dif header,
58-
# relative to the root of the project. This is the form ingested
59-
# by the difgen library scripts.
60-
rel_dif_h = (book_root / src_path).relative_to(SRCTREE_TOP)
61-
6257
buffer = io.StringIO()
6358
buffer.write(f"# {file_name}\n")
64-
difgen.gen_listing_html(html_out_dir, combined_xml, str(rel_dif_h),
59+
difgen.gen_listing_html(html_out_dir, combined_xml, str(book_root / src_path),
6560
buffer)
6661
buffer.write(
6762
"\n<details><summary>\nGenerated from <a href=\"{}\">{}</a></summary>\n"

util/site/build-docs.sh

+179
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
#!/usr/bin/env bash
2+
# Copyright lowRISC contributors.
3+
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
4+
# SPDX-License-Identifier: Apache-2.0
5+
6+
set -e
7+
8+
# Get the project directory from the location of this script
9+
this_dir=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
10+
proj_root=$( realpath "${this_dir}/../.." )
11+
build_dir="${proj_root}/build-site"
12+
13+
#######
14+
# CLI #
15+
#######
16+
declare command="build"
17+
# The following are only used for "command='serve-proxy'" ------------------------|
18+
declare public_domain="" # (optional) The public-facing domain <-|
19+
declare public_port="" # (optional)The port added to the public-facing domain <-|
20+
21+
case "$1" in
22+
"build"|"build-local"|"build-staging"|"serve"|"serve-proxy")
23+
command="$1"
24+
public_domain="${2}"
25+
public_port="${3}"
26+
;;
27+
"help"|*)
28+
echo "USAGE: $0 <command> [public_domain] [public_port]"
29+
echo ""
30+
echo "commands:"
31+
echo " help prints this message."
32+
echo " build build the site and docs for prod"
33+
echo " build-local build the site and docs for a localhost server"
34+
echo " build-staging build the site and docs for staging.opentitan.org"
35+
echo " serve build and serve the site locally"
36+
echo " serve-proxy build and serve the site, with a public url"
37+
echo ""
38+
echo "Optional arguments [public_domain] and [public_port] are only used when command='serve-proxy'"
39+
exit 0
40+
;;
41+
esac
42+
43+
################
44+
# DEPENDENCIES #
45+
################
46+
47+
checkDeps () {
48+
# Check for mdbook dep
49+
if ! command -v mdbook >/dev/null; then
50+
echo "E: mdbook not found, please install from your package manager or with:" >&2
51+
echo "E: $ cargo install mdbook" >&2
52+
exit 1
53+
fi
54+
55+
# Check for hugo dep
56+
if ! command -v hugo >/dev/null; then
57+
echo "E: hugo not found, please install from your package manager" >&2
58+
exit 1
59+
fi
60+
}
61+
checkDeps
62+
63+
#################
64+
# CONFIGURATION #
65+
#################
66+
declare base_url
67+
declare serve_port # The port used by the local webserver (using "build-docs.sh serve/serve-proxy")
68+
69+
getURLs () {
70+
# Defaults here are for production ("build-docs.sh build")
71+
local scheme="https"
72+
local domain="opentitan.org"
73+
local port=""
74+
75+
# Use un-encrypted localhost URLs when building/serving locally
76+
# - serve on port 9000.
77+
if [ "$command" = "build-local" ] || \
78+
[ "$command" = "serve" ]; then
79+
scheme="http"
80+
domain="localhost"
81+
port=":9000"
82+
serve_port=":9000"
83+
fi
84+
# "serve-proxy" gives us some simple defaults for serving behind a proxy:
85+
# - set the public_domain/public_port appropriately (see $2/$3)
86+
# - serve on port 8000.
87+
if [ "$command" = "serve-proxy" ] ; then
88+
scheme="http"
89+
domain="${public_domain}"
90+
port=":${public_port}"
91+
serve_port=":8000"
92+
fi
93+
if [ "$command" = "build-staging" ] ; then
94+
scheme="https"
95+
domain="staging.opentitan.org"
96+
fi
97+
98+
base_url="${scheme}://${domain}${port}"
99+
}
100+
getURLs
101+
102+
# Export some environment variables that tools will pick up
103+
export HUGO_PARAMS_DOCSURL="${base_url}/book" # hugo
104+
export URL_ROOT="${base_url}/book" # earlgrey_diagram
105+
106+
# Build up doxygen command
107+
doxygen_env="env"
108+
doxygen_env+=" SRCTREE_TOP=${proj_root}"
109+
doxygen_env+=" DOXYGEN_OUT=${build_dir}/gen"
110+
doxygen_args="${proj_root}/util/doxygen/Doxyfile"
111+
112+
# Build up mdbook arguments
113+
mdbook_args="build"
114+
mdbook_args+=" --dest-dir ${build_dir}/book/"
115+
mdbook_args+=" ${proj_root}"
116+
117+
mdbook_guides_args="build"
118+
mdbook_guides_args+=" --dest-dir ${build_dir}/guides/getting_started"
119+
mdbook_guides_args+=" ${proj_root}/doc/guides/getting_started"
120+
121+
# Register the pre-processors
122+
# Each book should only be passed the preprocessors it specifies inside the book.toml
123+
# ./book.toml
124+
book_env="env"
125+
book_env+=" MDBOOK_PREPROCESSOR__TESTPLAN__COMMAND=${proj_root}/util/mdbook_testplan.py"
126+
book_env+=" MDBOOK_PREPROCESSOR__OTBN__COMMAND=${proj_root}/util/mdbook_otbn.py"
127+
book_env+=" MDBOOK_PREPROCESSOR__DOXYGEN__COMMAND=${proj_root}/util/mdbook_doxygen.py"
128+
book_env+=" MDBOOK_PREPROCESSOR__REGGEN__COMMAND=${proj_root}/util/mdbook_reggen.py"
129+
book_env+=" MDBOOK_PREPROCESSOR__WAVEJSON__COMMAND=${proj_root}/util/mdbook_wavejson.py"
130+
book_env+=" MDBOOK_PREPROCESSOR__README2INDEX__COMMAND=${proj_root}/util/mdbook_readme2index.py"
131+
book_env+=" MDBOOK_PREPROCESSOR__DASHBOARD__COMMAND=${proj_root}/util/mdbook_dashboard.py"
132+
# ./doc/guides/getting_started/book.toml
133+
book_guides_env="env"
134+
book_guides_env+=" MDBOOK_PREPROCESSOR__TOOLVERSION__COMMAND=${proj_root}/util/mdbook_toolversion.py"
135+
136+
# Build up Hugo arguments
137+
hugo_args=""
138+
hugo_args+=" --source ${proj_root}/site/landing/"
139+
hugo_args+=" --destination ${build_dir}/"
140+
hugo_args+=" --baseURL ${base_url}"
141+
142+
############
143+
# BUILDING #
144+
############
145+
146+
buildSite () {
147+
mkdir -p "${build_dir}"
148+
mkdir -p "${build_dir}/gen/doxy"
149+
150+
echo "Building doxygen..."
151+
pushd "${this_dir}" >/dev/null
152+
# shellcheck disable=SC2086
153+
${doxygen_env} doxygen ${doxygen_args}
154+
popd >/dev/null
155+
echo "Doxygen build complete."
156+
157+
# shellcheck disable=SC2086
158+
${book_env} mdbook ${mdbook_args}
159+
# shellcheck disable=SC2086
160+
${book_guides_env} mdbook ${mdbook_guides_args}
161+
# shellcheck disable=SC2086
162+
hugo ${hugo_args}
163+
}
164+
buildSite
165+
166+
###########
167+
# SERVING #
168+
###########
169+
170+
# If serving, run the python HTTP server
171+
if [ "$command" = "serve" ] || [ "$command" = "serve-proxy" ]; then
172+
echo "--------------------------------------------"
173+
echo
174+
echo "Website being served at : ${base_url}"
175+
echo
176+
echo "--------------------------------------------"
177+
python3 -m http.server -d "$build_dir" ${serve_port:1}
178+
# strip leading :
179+
fi

site/docs/README.md util/site/site-builder/README.md

+3-6
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,13 @@ python requirements pre-installed. This cuts the deployment from several
1111
minutes to around twenty seconds. To rebuild and deploy the image use the
1212
`deploy-builder.sh` script.
1313

14-
# Update Hugo version
15-
16-
The Hugo version is defined by variable `HUGO_EXTENDED_VERSION` in `util/build_docs.py`.
17-
To ensure syntax highlighting is working correctly the CSS stylesheet must be updated following a version update.
14+
# Appendix
1815

1916
## Update CSS stylesheet
2017

21-
Setting the option `noClasses = false` for `[markup.highlight]` in `site/docs/config.toml` requires a stylesheet to be available.
18+
Setting the option `noClasses = false` for `[markup.highlight]` in `site/landing/config.toml` requires a stylesheet to be available.
2219
This option is used in order to have two styles for light and dark mode of the documentation site.
23-
The stylesheet is stored in `site/docs/assets/scss/_chroma.scss`.
20+
The stylesheet is stored in `site/landing/assets/scss/_chroma.scss`.
2421
Update the style if the Hugo version is changed:
2522

2623
- Replace the content of `[data-user-color-scheme='light']` with the output of `hugo gen chromastyles --style=colorful`, but keep the first line containing the setting of the background.

site/docs/builder.Dockerfile util/site/site-builder/builder.Dockerfile

+4-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
FROM ubuntu:18.04
66

77
RUN apt-get update && \
8-
apt-get install -y locales locales-all git curl doxygen python3 python3-pip xsltproc && \
9-
apt-get clean; rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/*
8+
apt-get install -y \
9+
locales locales-all git curl doxygen python3 python3-pip xsltproc && \
10+
apt-get clean && \
11+
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/*
1012

1113
ENV LC_ALL en_US.UTF-8
1214
ENV LANG en_US.UTF-8
File renamed without changes.

0 commit comments

Comments
 (0)