forked from project-oak/oak
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild_gh_pages
executable file
·120 lines (104 loc) · 2.62 KB
/
build_gh_pages
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/usr/bin/env bash
#
# Script to generate documentation for Rust crates to publish as gh-pages.
#
# Usage:
#
# ./scipts/build_gh_pages <target_dir>
#
# Where <target_dir> must be an empty directory.
readonly SCRIPTS_DIR="$(dirname "$0")"
# shellcheck source=scripts/common
source "$SCRIPTS_DIR/common"
readonly TARGET_DIR="${1:-}"
if [[ -z "${TARGET_DIR}" ]]; then
echo 'target dir not specified'
exit 1
fi
if [[ ! -d "${TARGET_DIR}" ]]; then
echo 'target not a directory'
exit 1
fi
if [[ -n "$(ls "${TARGET_DIR}"/*)" ]]; then
echo 'target dir not empty'
exit 1
fi
# Absolute path to the target directory, to make sure that docs are generated into the correct directory.
readonly TARGET_ABS_PATH="$(realpath "${TARGET_DIR}")"
# All the dirs that we want to generate docs for.
declare -ar SOURCE_PATHS=(
'oak_abi'
'oak_derive'
'oak_io'
'oak_loader'
'oak_runtime'
'oak_services'
'oak_sign'
'oak_utils'
'runner'
'sdk'
)
declare -ar TARGET_SUBDIRS=(
'oak_abi'
'oak_derive'
'oak_io'
'oak_loader'
'oak_runtime'
'oak_services'
'oak_sign'
'oak_utils'
'runner'
'oak'
)
# Titles used in the top-level index.html files.
declare -ar PAGE_TITLES=(
'ABI'
'Derive'
'IO'
'Loader'
'Runtime'
'Services'
'Sign'
'Utils'
'Runner'
'SDK'
)
readonly LEN=${#SOURCE_PATHS[@]}
for ((i=0;i<LEN;i++)); do
(
cd "${SOURCE_PATHS[$i]}"
target_dir="${TARGET_ABS_PATH}/${SOURCE_PATHS[$i]}"
mkdir --parent "${target_dir}"
# Generate docs directly into the target dir.
cargo doc --no-deps --target-dir="${target_dir}"
# Remove non-doc artifacts from the target dir.
rm --recursive --force "${target_dir}/debug"
# Remove non-deterministic files.
rm "${target_dir}/.rustc_info.json"
# The docs generated from the Cargo workspace do not include a workspace-level index, so we generate
# one here and redirect to the appropriate documentation.
cat <<-END > "${target_dir}/index.html"
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Refresh" content="0; url=./doc/${TARGET_SUBDIRS[$i]}/index.html" />
</head>
<body>
<p><a href="./doc/${TARGET_SUBDIRS[$i]}/index.html">Oak ${PAGE_TITLES[$i]} main page</a></p>
</body>
</html>
END
)
done
# A top-level index so that visiting https://project-oak.github.io/oak/ goes somewhere helpful.
cat <<-END > "${TARGET_ABS_PATH}/index.html"
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Refresh" content="0; url=./sdk/doc/oak/index.html" />
</head>
<body>
<p><a href="./sdk/doc/oak/index.html">Oak SDK main page</a></p>
</body>
</html>
END