• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/sh
2#
3# Copyright (C) 2013 The Android Open Source Project
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9#      http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16#
17
18# include common function and variable definitions
19. `dirname $0`/prebuilt-common.sh
20
21DEFAULT_OUT_DIR=/tmp/ndk-$USER/docs
22
23IN_DIR=
24OUT_DIR=$DEFAULT_OUT_DIR
25FORCE=
26RUN_CHECKS=
27
28PROGRAM_PARAMETERS=""
29PROGRAM_DESCRIPTION="Rebuild the HTML documentation from the Markdown text.
30
31Rebuild the NDK html documentation from the Markdown input source files
32in \$NDK/docs/text. See \$NDK/docs/tools/README for the input file format.
33
34Builds are incremental, but you can use --force to rebuild everything.
35
36Output files are placed in $DEFAULT_OUT_DIR, unless --out-dir=<path>
37is used."
38
39register_var_option "--force" FORCE "Rebuild all documentation"
40
41register_var_option "--run-checks" RUN_CHECKS "Run internal consistency checks"
42
43register_option "--in-dir=<path>" do_in_dir "Specify input directory" "\$NDK/docs/text"
44do_in_dir () {
45  IN_DIR=$1
46}
47
48register_var_option "--out-dir=<path>" OUT_DIR "Specify output directory"
49
50MARKDOWN=markdown_py
51register_var_option "--markdown=<executable>" MARKDOWN "Specify markdown executable to use"
52
53extract_parameters "$@"
54
55# Path to a Markdown filter program that is used to perform a few NDK-specific
56# substitution in the input .text files. Note that this tool generates Markdown
57# text, not HTML. TODO(digit): Use Markdown Extensions API to perform something
58# similar, which is a lot more work though.
59SUBST_PROGRAM=$ANDROID_NDK_ROOT/docs/tools/ndk-markdown-substitutions.py
60
61if [ "$RUN_CHECKS" ]; then
62  # Run unit tests for our $SUBST_PROGRAM
63  $SUBST_PROGRAM --run-checks
64  exit $?
65fi
66
67if [ -z "$IN_DIR" ]; then
68  IN_DIR=$ANDROID_NDK_ROOT/docs/text
69fi
70IN_DIR=${IN_DIR%%/}
71log "Input directory: $IN_DIR"
72
73if [ -z "$OUT_DIR" ]; then
74  OUT_DIR=$ANDROID_NDK_ROOT/docs
75fi
76OUT_DIR=${OUT_DIR%%/}
77log "Output directory: $OUT_DIR"
78
79TEMP_DIR=$NDK_TMPDIR/build-docs
80mkdir -p "$TEMP_DIR"
81fail_panic "Could not create temporary directory"
82
83SRC_FILES=$(find "$IN_DIR" -name "*.text")
84for SRC_FILE in $SRC_FILES; do
85  # Compute destination file.
86  DST_FILE=${SRC_FILE%%.text}.html
87  DST_FILE=$OUT_DIR${DST_FILE##$IN_DIR}
88  DST_DIR=$(dirname "$DST_FILE")
89  # Only rebuild file is source is older than destination, unless --force
90  # is being used.
91  if [ -z "$FORCE" -a -f "$DST_FILE" -a "$SRC_FILE" -ot "$DST_FILE" ]; then
92    log "Skipping: $SRC_FILE --> $DST_FILE"
93  else
94    log "Converting: $SRC_FILE --> $DST_FILE"
95    mkdir -p "$DST_DIR"
96    fail_panic "Could not create output directory: $DST_DIR"
97    # Apply custom substitutions.
98    TMP_FILE=$TEMP_DIR/$(basename "$DST_FILE").temp
99    run $SUBST_PROGRAM --output "$TMP_FILE" "$SRC_FILE"
100    fail_panic "Could not pre-process $SRC_FILE!"
101    # Process with Markdown.
102    run run $MARKDOWN --file="$DST_FILE" "$TMP_FILE"
103    fail_panic "Could not convert $SRC_FILE!"
104  fi
105done
106
107run rm -rf "$TEMP_DIR"
108
109if [ "$OUT_DIR" != "$DEFAULT_OUT_DIR" ]; then
110  dump "Done!"
111else
112  dump "Done, see $OUT_DIR"
113fi
114
115