Skip to content

Commit 2eca5df

Browse files
committed
Make README more generation even more automated
We have generate-readme-help.sh, but that only generates the output to put in the code block, it doesn't actually put it there, requiring something like a visual select and %!./generate-readme-help.sh in vim. Instead, use some magic comments to mark the region and turn it into a script that automatically replaces everything between them.
1 parent ed02572 commit 2eca5df

File tree

3 files changed

+43
-10
lines changed

3 files changed

+43
-10
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ I would also suggest using `set autolist` to display all options.
292292

293293
**NOTE:** Since there are so many per-project options that are identical between all projects they are not all shown when running `--help`. To see the full list of options that can be specified, run `cheribuild.py --help-all`. Since this will generate lots of output it probably makes more sense to run `cheribuild.py --help-all | grep <target_name>`.
294294

295+
<!-- BEGIN HELP OUTPUT -->
295296
```
296297
usage: cheribuild.py [-h] [--config-file FILE] [--help-all] [--pretend] [--build] [--test] [--benchmark]
297298
[--build-and-test] [--list-targets] [--print-chosen-targets] [--dump-configuration]
@@ -691,3 +692,4 @@ Options for target 'webkit':
691692
Use offsets into the JS heap for object references instead of capabilities. This option only
692693
affects the purecap backends. (default: 'False')
693694
```
695+
<!-- END HELP OUTPUT -->

generate-readme-help.sh

Lines changed: 0 additions & 10 deletions
This file was deleted.

update-readme-help.sh

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/bin/sh
2+
set -e
3+
set -u
4+
5+
err() {
6+
echo >&2 "Error:" "$@"
7+
exit 1
8+
}
9+
10+
if [ ! -f cheribuild.py ] || [ ! -f README.md ]; then
11+
err "Not being run in cheribuild's source directory?"
12+
fi
13+
14+
TEMP=`mktemp`
15+
exec 3>"$TEMP" 4<"$TEMP"
16+
rm "$TEMP"
17+
18+
sed -n '
19+
p
20+
/<!-- BEGIN HELP OUTPUT -->/q
21+
' README.md >&3
22+
23+
echo '```' >&3
24+
PATH="$PWD:$PATH" HOME="\$HOME" XDG_CONFIG_HOME="\$HOME/.config" _GENERATING_README=1 cheribuild.py --help 2>&1 | sed "
25+
# XXX: Ideally the default would be printed as ~/.config/cheribuild.json rather
26+
# than the possibly-bundled file.
27+
s!$PWD/cheribuild.json!\$HOME/.config/cheribuild.json!
28+
" >&3
29+
echo '```' >&3
30+
31+
sed -n '
32+
/<!-- END HELP OUTPUT -->/b loop
33+
b
34+
35+
: loop
36+
p
37+
n
38+
b loop
39+
' README.md >&3
40+
41+
cat <&4 >README.md

0 commit comments

Comments
 (0)