1 | #!/usr/bin/env bash
|
2 | #
|
3 | # Usage:
|
4 | # build/doc.sh <function name>
|
5 |
|
6 | set -o nounset
|
7 | set -o pipefail
|
8 | set -o errexit
|
9 |
|
10 | # https://oilshell.org/release/$VERSION/
|
11 | # doc/
|
12 | # index.html
|
13 | # INSTALL.html
|
14 | # INSTALL-old.html
|
15 |
|
16 | readonly OIL_VERSION=$(head -n 1 oil-version.txt)
|
17 | export OIL_VERSION # for quick_ref.py
|
18 |
|
19 | THIS_DIR=$(readlink -f $(dirname $0))
|
20 | readonly THIS_DIR
|
21 | REPO_ROOT=$(cd $THIS_DIR/.. && pwd)
|
22 | readonly REPO_ROOT
|
23 |
|
24 |
|
25 | readonly HTML_BASE_DIR=_release/VERSION
|
26 |
|
27 |
|
28 | log() {
|
29 | echo "$@" 1>&2
|
30 | }
|
31 |
|
32 | #
|
33 | # Deps (similar to doctools/cmark.sh and build/codegen.sh)
|
34 | #
|
35 |
|
36 | readonly MANDOC_DIR='_deps/mdocml-1.14.1'
|
37 |
|
38 | download-mandoc() {
|
39 | mkdir -p _deps
|
40 | wget --no-clobber --directory _deps \
|
41 | https://mandoc.bsd.lv/snapshots/mdocml-1.14.1.tar.gz
|
42 | }
|
43 |
|
44 | build-mandoc() {
|
45 | cd $MANDOC_DIR
|
46 | ./configure
|
47 | make
|
48 | }
|
49 |
|
50 | mandoc() {
|
51 | $MANDOC_DIR/mandoc "$@"
|
52 | }
|
53 |
|
54 | # Places version is used
|
55 | #
|
56 | # - in --version
|
57 | # - in URL for every page? inside the binary
|
58 | # - in titles for index, install, osh-quick-ref TOC, etc.
|
59 | # - in deployment script
|
60 |
|
61 | # Run with environment variable
|
62 | help-gen() {
|
63 | PYTHONPATH=. doctools/help_gen.py "$@"
|
64 | }
|
65 |
|
66 | cmark() {
|
67 | # h2 and h3 are shown in TOC. The blog uses "legacy" h3 and h4.
|
68 | PYTHONPATH=. doctools/cmark.py --toc-tag h2 --toc-tag h3 --toc-pretty-href "$@"
|
69 | }
|
70 |
|
71 | readonly MARKDOWN_DOCS=(
|
72 | published
|
73 |
|
74 | # polished
|
75 | getting-started
|
76 | portability
|
77 | known-differences
|
78 | ysh-error
|
79 | error-handling
|
80 | error-catalog
|
81 | json
|
82 | hay
|
83 | simple-word-eval
|
84 | quirks
|
85 | warts
|
86 |
|
87 | eggex
|
88 | ysh-regex-api
|
89 | upgrade-breakage
|
90 | ysh-tour
|
91 |
|
92 | style-guide
|
93 | novelties
|
94 |
|
95 | proc-func
|
96 | block-literals
|
97 |
|
98 | # Data language
|
99 | qsn
|
100 | qtt
|
101 | j8-notation
|
102 | pretty-printing
|
103 | stream-table-process
|
104 |
|
105 | doc-toolchain
|
106 | doc-plugins
|
107 | idioms
|
108 | shell-idioms
|
109 | ysh-faq
|
110 |
|
111 | language-influences
|
112 | ysh-vs-python
|
113 | ysh-vs-shell
|
114 |
|
115 | syntactic-concepts
|
116 | syntax-feelings
|
117 | command-vs-expression-mode
|
118 |
|
119 | # needs polish
|
120 | # Note: docs about the YSH are prefixed 'ysh-'.
|
121 | # data-model and command-vs-expression-mode span both OSH and YSH
|
122 |
|
123 | index
|
124 | faq-doc
|
125 |
|
126 | options
|
127 |
|
128 | old/index
|
129 | old/project-tour
|
130 | old/legacy-array
|
131 | old/ysh-keywords
|
132 | old/modules
|
133 | old/expression-language
|
134 | old/word-language
|
135 | old/errors
|
136 | old/ysh-builtins
|
137 |
|
138 | io-builtins
|
139 | unicode
|
140 | framing
|
141 | xtrace
|
142 | headless
|
143 | completion
|
144 | strings
|
145 | variables
|
146 |
|
147 | # Internal stuff
|
148 | interpreter-state
|
149 | process-model
|
150 | architecture-notes
|
151 | parser-architecture
|
152 | )
|
153 |
|
154 | # Bug fix: Plain $(date) can output unicode characters (e.g. in Japanese
|
155 | # locale), which is loaded by Python into say u'\u5e74'. But the default
|
156 | # encoding in Python 2 is still 'ascii', which means that '%s' % u_str may
|
157 | # fail.
|
158 | #
|
159 | # I believe --rfc-e-mail should never output a Unicode character.
|
160 | #
|
161 | # A better fix would be to implement json_utf8.load(f), which doesn't decode
|
162 | # into unicode instances. This would remove useless conversions.
|
163 |
|
164 | readonly TIMESTAMP=$(date --rfc-email)
|
165 |
|
166 | split-and-render() {
|
167 | local src=${1:-doc/known-differences.md}
|
168 |
|
169 | local rel_path=${src%'.md'} # doc/known-differences
|
170 | local tmp_prefix=_tmp/$rel_path # temp dir for splitting
|
171 |
|
172 | local out=${2:-$HTML_BASE_DIR/$rel_path.html}
|
173 | local web_url=${3:-'../web'}
|
174 |
|
175 | mkdir -v -p $(dirname $out) $tmp_prefix
|
176 |
|
177 | # Also add could add css_files. The one in the file takes precedence always?
|
178 |
|
179 | # css_files: a space-separated list
|
180 | # all_docs_url: so we link from doc/foo.html -> doc/
|
181 |
|
182 | local css_files="$web_url/base.css $web_url/manual.css $web_url/toc.css $web_url/language.css $web_url/code.css"
|
183 |
|
184 | doctools/split_doc.py \
|
185 | -v build_timestamp="$TIMESTAMP" \
|
186 | -v oil_version="$OIL_VERSION" \
|
187 | -v css_files="$css_files" \
|
188 | -v all_docs_url='.' \
|
189 | -v repo_url="$src" \
|
190 | $src $tmp_prefix
|
191 |
|
192 | #ls -l _tmp/doc
|
193 | #head _tmp/doc/*
|
194 | #return
|
195 |
|
196 | # for ysh-tour code blocks
|
197 | local code_out=_tmp/code-blocks/$rel_path.txt
|
198 | mkdir -v -p $(dirname $code_out)
|
199 |
|
200 | cmark \
|
201 | --code-block-output $code_out \
|
202 | ${tmp_prefix}_meta.json ${tmp_prefix}_content.md > $out
|
203 |
|
204 | log "$tmp_prefix -> (doctools/cmark) -> $out"
|
205 | }
|
206 |
|
207 | render-from-kate() {
|
208 | ### Make it easier to configure Kate editor
|
209 |
|
210 | # It want to pass an absolute path
|
211 | # TODO: I can't figure out how to run this from Kate?
|
212 |
|
213 | local full_path=$1
|
214 |
|
215 | case $full_path in
|
216 | $REPO_ROOT/*)
|
217 | rel_path=${full_path#"$REPO_ROOT/"}
|
218 | echo "relative path = $rel_path"
|
219 | ;;
|
220 | *)
|
221 | die "$full_path should start with repo root $REPO_ROOT"
|
222 | ;;
|
223 | esac
|
224 |
|
225 | split-and-render $rel_path
|
226 | }
|
227 |
|
228 | # Special case for README
|
229 | # Do NOT split because we don't want front matter in the markdown source.
|
230 | render-only() {
|
231 | local src=${1:-README.md}
|
232 |
|
233 | local name
|
234 | case $src in
|
235 | *.md)
|
236 | name=$(basename $src .md)
|
237 | ;;
|
238 | *.txt)
|
239 | name=$(basename $src .txt)
|
240 | ;;
|
241 | *)
|
242 | name=$(basename $src)
|
243 | ;;
|
244 | esac
|
245 |
|
246 | local out=${2:-$HTML_BASE_DIR/doc/$name.html}
|
247 | local css_files=${3:-'../web/manual.css ../web/toc.css'}
|
248 | local title=${4:-'Oils Source Code'}
|
249 |
|
250 | local prefix=_tmp/doc/$name
|
251 |
|
252 | local meta=${prefix}_meta.json
|
253 | cat >$meta <<EOF
|
254 | { "title": "$title",
|
255 | "repo_url": "$src",
|
256 | "css_files": "$css_files",
|
257 | "all_docs_url": ".",
|
258 |
|
259 | "build_timestamp": "$TIMESTAMP",
|
260 | "oil_version": "$OIL_VERSION"
|
261 | }
|
262 | EOF
|
263 |
|
264 | cmark $meta $src > $out
|
265 | log "Wrote $out"
|
266 | }
|
267 |
|
268 | special() {
|
269 | # TODO: do all READMEs
|
270 | split-and-render mycpp/README.md \
|
271 | $HTML_BASE_DIR/doc/oils-repo/mycpp/README.html \
|
272 | ../../../web
|
273 |
|
274 | local web_dir='../../web'
|
275 | render-only 'README.md' $HTML_BASE_DIR/doc/oils-repo/README.html \
|
276 | "$web_dir/base.css $web_dir/manual.css $web_dir/toc.css" 'Oils Source Code'
|
277 |
|
278 | local web_dir='../web'
|
279 | render-only INSTALL.txt '' \
|
280 | "$web_dir/base.css $web_dir/install.css" 'Installing Oils'
|
281 |
|
282 | render-only INSTALL-old.txt '' \
|
283 | "$web_dir/base.css $web_dir/install.css" 'Installing Oils - old CPython build'
|
284 |
|
285 | # These pages aren't in doc/
|
286 | split-and-render doc/release-index.md _tmp/release-index.html
|
287 | split-and-render doc/release-quality.md _tmp/release-quality.html
|
288 | }
|
289 |
|
290 | all-markdown() {
|
291 | make-dirs
|
292 |
|
293 | # TODO: We can set repo_url here! Then we don't need it for most docs.
|
294 | # split_doc.py can return {} if the doc doesn't start with ---
|
295 |
|
296 | #for d in doc/index.md doc/known-differences.md doc/*-manual.md \
|
297 | # doc/eggex.md doc/oil-options.md doc/oil-func-proc-block.md; do
|
298 | for d in "${MARKDOWN_DOCS[@]}"; do
|
299 | split-and-render doc/$d.md
|
300 | done
|
301 |
|
302 | special
|
303 | }
|
304 |
|
305 | redir-body() {
|
306 | local to_url=$1 # WARNING: no escaping
|
307 | cat <<EOF
|
308 | <head>
|
309 | <meta http-equiv="Refresh" content="0; URL=$to_url" />
|
310 | </head>
|
311 | EOF
|
312 | }
|
313 |
|
314 | redirect-pairs() {
|
315 | # we want want /release/latest/ URLs to still work
|
316 | cat <<EOF
|
317 | oil-language-tour ysh-tour
|
318 | oil-language-faq ysh-faq
|
319 | oil-help ysh-help
|
320 | oil-help-topics ysh-help-topics
|
321 | ysh-help ref/toc-ysh
|
322 | ysh-help-topics ref/toc-ysh
|
323 | EOF
|
324 | }
|
325 |
|
326 | all-redirects() {
|
327 | redirect-pairs | while read -r from_page to_page; do
|
328 | redir-body "$to_page.html" | tee "_release/VERSION/doc/$from_page.html"
|
329 | done
|
330 | }
|
331 |
|
332 | # TODO: This could use some CSS.
|
333 | man-page() {
|
334 | local root_dir=${1:-_release/VERSION}
|
335 | mandoc -T html doc/osh.1 > $root_dir/osh.1.html
|
336 | ls -l $root_dir
|
337 | }
|
338 |
|
339 | # I want to ship the INSTALL file literally, so just mutate things
|
340 | _sed-ext() {
|
341 | sed --regexp-extended -i "$@"
|
342 | }
|
343 |
|
344 | update-src-versions() {
|
345 | # Update tarball names, etc.
|
346 | _sed-ext \
|
347 | "s/[0-9]+\.[0-9]+\.[a-z0-9]+/$OIL_VERSION/g" \
|
348 | doc/release-*.md INSTALL.txt INSTALL-old.txt
|
349 |
|
350 | # Update /release/0.8.4/ URL, etc.
|
351 | _sed-ext \
|
352 | "s;/release/[0-9]+\.[0-9]+\.[a-z0-9]+/;/release/$OIL_VERSION/;g" \
|
353 | doc/osh.1
|
354 | }
|
355 |
|
356 | #
|
357 | # Test Tools
|
358 | #
|
359 |
|
360 | split-doc-demo() {
|
361 | cat > _tmp/testdoc.md <<EOF
|
362 | ---
|
363 | title: foo
|
364 | ---
|
365 |
|
366 | Title
|
367 | =====
|
368 |
|
369 | hello
|
370 |
|
371 | EOF
|
372 |
|
373 | doctools/split_doc.py _tmp/testdoc.md _tmp/testdoc
|
374 |
|
375 | head _tmp/testdoc*
|
376 | }
|
377 |
|
378 | #
|
379 | # Help is both markdown and text
|
380 | #
|
381 |
|
382 | readonly TMP_DIR=_tmp/doc
|
383 | readonly CODE_BLOCK_DIR=_tmp/code-blocks
|
384 | readonly TEXT_DIR=_devbuild/help
|
385 | readonly HTML_DIR=_release/VERSION
|
386 | readonly CODE_DIR=_devbuild/gen
|
387 |
|
388 | cards-from-indices() {
|
389 | ### Make help cards
|
390 |
|
391 | for lang in osh ysh data; do
|
392 | help-gen cards-from-index $lang $TEXT_DIR \
|
393 | < $HTML_DIR/doc/ref/toc-$lang.html
|
394 | done
|
395 | }
|
396 |
|
397 | cards-from-chapters() {
|
398 | ### Turn h3 topics into cards
|
399 |
|
400 | local py_out=$CODE_DIR/help_meta.py
|
401 |
|
402 | mkdir -p _gen/frontend
|
403 | local cc_prefix=_gen/frontend/help_meta
|
404 |
|
405 | help-gen cards-from-chapters $TEXT_DIR $py_out $cc_prefix \
|
406 | $HTML_DIR/doc/ref/chap-*.html
|
407 | }
|
408 |
|
409 | ref-check() {
|
410 | help-gen ref-check \
|
411 | doc/ref/toc-*.md \
|
412 | _release/VERSION/doc/ref/chap-*.html
|
413 | }
|
414 |
|
415 |
|
416 | write-metrics() {
|
417 | ### Check indexes and chapters against each other
|
418 |
|
419 | local out=_release/VERSION/doc/metrics.txt
|
420 |
|
421 | # send stderr to the log file too
|
422 | ref-check > $out 2>&1
|
423 |
|
424 | echo "Wrote $out"
|
425 | }
|
426 |
|
427 | tour() {
|
428 | ### Build the Tour of YSH, and execute code as validation
|
429 | local name=${1:-ysh-tour}
|
430 |
|
431 | split-and-render doc/$name.md
|
432 |
|
433 | local work_dir=$REPO_ROOT/_tmp/code-blocks/doc
|
434 |
|
435 | mkdir -p $work_dir/lib
|
436 |
|
437 | # Files used by module example
|
438 | touch $work_dir/{build,test}.sh
|
439 |
|
440 | cat >$work_dir/lib/util.ysh <<EOF
|
441 | log() { echo "$@" 1>&2; }
|
442 | EOF
|
443 |
|
444 | pushd $work_dir
|
445 | $REPO_ROOT/bin/ysh $name.txt
|
446 | popd
|
447 |
|
448 | # My own dev tools
|
449 | # if test -d ~/vm-shared; then
|
450 | if false; then
|
451 | local path=_release/VERSION/doc/$name.html
|
452 | cp -v $path ~/vm-shared/$path
|
453 | fi
|
454 | }
|
455 |
|
456 | one() {
|
457 | ### Iterate on one doc quickly
|
458 |
|
459 | local name=${1:-options}
|
460 |
|
461 | split-and-render doc/$name.md
|
462 |
|
463 | # Make sure the doc has valid YSH code?
|
464 | # TODO: Maybe need an attribute for OSH or YSH
|
465 | pushd _tmp/code-blocks/doc
|
466 | $REPO_ROOT/bin/ysh $name.txt
|
467 | popd
|
468 |
|
469 | if test -d ~/vm-shared; then
|
470 | local out="${name%.md}.html"
|
471 | local path=_release/VERSION/$out
|
472 | cp -v $path ~/vm-shared/$path
|
473 | fi
|
474 | }
|
475 |
|
476 | make-dirs() {
|
477 | mkdir -p $TMP_DIR $CODE_BLOCK_DIR $TEXT_DIR $HTML_DIR/doc
|
478 | }
|
479 |
|
480 | one-ref() {
|
481 | local md=${1:-doc/ref/index.md}
|
482 | split-and-render $md '' '../../web'
|
483 | }
|
484 |
|
485 | all-ref() {
|
486 | ### Build doc/ref in text and HTML. Depends on libcmark.so
|
487 |
|
488 | log "Removing $TEXT_DIR/*"
|
489 | rm -f $TEXT_DIR/*
|
490 | make-dirs
|
491 |
|
492 | # Make the indexes and chapters
|
493 | for d in doc/ref/*.md; do
|
494 | split-and-render $d '' '../../web'
|
495 | done
|
496 |
|
497 | # Note: if we want a $ref-topic shortcut, we might want to use Ninja to
|
498 | # extract topics from all chapters first, and then make help_meta.json, like
|
499 | # we have _devbuild/gen/help_meta.py.
|
500 |
|
501 | # Text cards
|
502 | cards-from-indices
|
503 | # A few text cards, and HELP_TOPICS dict for URLs, for flat namespace
|
504 | cards-from-chapters
|
505 |
|
506 | if command -v pysum; then
|
507 | # 19 KB of embedded help, seems OK. Biggest card is 'ysh-option'. Could
|
508 | # compress it.
|
509 | echo 'Size of embedded help:'
|
510 | ls -l $TEXT_DIR | tee /dev/stderr | awk '{print $5}' | pysum
|
511 | fi
|
512 |
|
513 | # Better sorting
|
514 | #LANG=C ls -l $TEXT_DIR
|
515 | }
|
516 |
|
517 | _copy-path() {
|
518 | local src=$1 dest=$2
|
519 | mkdir -p $(dirname $dest)
|
520 | cp -v $src $dest
|
521 | }
|
522 |
|
523 | copy-web() {
|
524 | find web \
|
525 | \( -name _tmp -a -prune \) -o \
|
526 | \( -name '*.css' -o -name '*.js' \) -a -printf '%p _release/VERSION/%p\n' |
|
527 | xargs -n 2 -- $0 _copy-path
|
528 | }
|
529 |
|
530 | pretty-size() {
|
531 | local path=$1
|
532 | stat --format '%s' "$path" | python -c '
|
533 | import sys
|
534 | num_bytes = int(sys.stdin.read())
|
535 | print "{:,}".format(num_bytes)
|
536 | '
|
537 | }
|
538 |
|
539 | # NOTE: It might be better to link to files like this in the /release/ tree.
|
540 | # Although I am not signing them.
|
541 |
|
542 | # https://nodejs.org/dist/v8.11.4/SHASUMS256.txt.asc
|
543 |
|
544 | tarball-links-row-html() {
|
545 | local version=$1
|
546 |
|
547 | cat <<EOF
|
548 | <tr class="file-table-heading">
|
549 | <td></td>
|
550 | <td>File / SHA256 checksum</td>
|
551 | <td class="size">Size</td>
|
552 | <td></td>
|
553 | </tr>
|
554 | EOF
|
555 |
|
556 | # we switched to .gz for oils-for-unix
|
557 | # note: legacy names for old releases
|
558 | for name in \
|
559 | oils-for-unix-$version.tar.{gz,xz} \
|
560 | oil-$version.tar.{gz,xz} \
|
561 | oil-native-$version.tar.xz; do
|
562 |
|
563 | local url="/download/$name" # The server URL
|
564 | local path="../oilshell.org__deploy/download/$name"
|
565 |
|
566 | # Don't show tarballs that don't exist
|
567 | if [[ $name == oils-for-unix-* && ! -f $path ]]; then
|
568 | continue
|
569 | fi
|
570 | if [[ $name == oil-native-* && ! -f $path ]]; then
|
571 | continue
|
572 | fi
|
573 |
|
574 | local checksum
|
575 | checksum=$(sha256sum $path | awk '{print $1}')
|
576 | local size
|
577 | size=$(pretty-size $path)
|
578 |
|
579 | # TODO: Port this to oil with "commas" extension.
|
580 |
|
581 | # Three columns: date, version, and links
|
582 | cat <<EOF
|
583 | <tr>
|
584 | <td></td>
|
585 | <td class="filename"><a href="$url">$name</a></td>
|
586 | <td class="size">$size</td>
|
587 | </tr>
|
588 | <tr>
|
589 | <td></td>
|
590 | <td colspan=2 class="checksum">$checksum</td>
|
591 | </tr>
|
592 | EOF
|
593 | done
|
594 | }
|
595 |
|
596 | this-release-links() {
|
597 | echo '<div class="file-table">'
|
598 | echo '<table>'
|
599 | tarball-links-row-html "$OIL_VERSION"
|
600 | echo '</table>'
|
601 | echo '</div>'
|
602 | }
|
603 |
|
604 | # Turn HTML comment into a download link
|
605 | add-date-and-links() {
|
606 | local snippet
|
607 | snippet=$(this-release-links)
|
608 |
|
609 | awk -v date=$1 -v snippet="$snippet" '
|
610 | /<!-- REPLACE_WITH_DOWNLOAD_LINKS -->/ {
|
611 | print(snippet)
|
612 | next
|
613 | }
|
614 |
|
615 | /<!-- REPLACE_WITH_DATE -->/ {
|
616 | print(date)
|
617 | next
|
618 | }
|
619 |
|
620 | # Everything else
|
621 | { print }
|
622 | '
|
623 | }
|
624 |
|
625 | patch-release-pages() {
|
626 | local release_date
|
627 | release_date=$(cat _build/release-date.txt)
|
628 |
|
629 | local root=_release/VERSION
|
630 |
|
631 | add-date-and-links $release_date < _tmp/release-index.html > $root/index.html
|
632 | add-date-and-links $release_date < _tmp/release-quality.html > $root/quality.html
|
633 | }
|
634 |
|
635 | copy-release-pages() {
|
636 | ### For testing without releasing
|
637 |
|
638 | cat < _tmp/release-index.html > $root/index.html
|
639 | cat < _tmp/release-quality.html > $root/quality.html
|
640 | }
|
641 |
|
642 | run-for-release() {
|
643 | ### Build a tree. Requires _build/release-date.txt to exist
|
644 |
|
645 | local root=_release/VERSION
|
646 | mkdir -p $root/{doc,test,pub}
|
647 |
|
648 | tour
|
649 |
|
650 | # Metadata
|
651 | cp -v _build/release-date.txt oil-version.txt $root
|
652 |
|
653 | # Docs
|
654 | # Writes _release/VERSION and _tmp/release-index.html
|
655 | all-markdown
|
656 | all-ref
|
657 | all-redirects # backward compat
|
658 |
|
659 | patch-release-pages
|
660 |
|
661 | write-metrics
|
662 |
|
663 | # Problem: You can't preview it without .wwz!
|
664 | # Maybe have local redirects VERSION/test/wild/ to
|
665 | #
|
666 | # Instead of linking, I should compress them all here.
|
667 |
|
668 | copy-web
|
669 |
|
670 | if command -v tree >/dev/null; then
|
671 | tree $root
|
672 | else
|
673 | find $root
|
674 | fi
|
675 | }
|
676 |
|
677 | soil-run() {
|
678 | build/stamp.sh write-release-date
|
679 |
|
680 | run-for-release
|
681 | }
|
682 |
|
683 | "$@"
|
684 |
|