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
121
122
123
124
125
126
127
128
129
130
131
132
|
#!/usr/bin/env bash
# Usage: write-dev-docs [FILE..]
#
# A file can be a tool name like "pt-archiver" or a module name like
# "Advisor.pm"; the ".pm" suffix is required. A file can be with
# or without a path. One or more file can be specified. If no files
# are specified, then dev docs for lib/* and bin/* are written.
# Files are only written if the original (e.g. bin/pt-archiver) is
# newer than the dev doc copy (e.g. docs/dev/tools/pt-archiver).
# Dev doc copies are necessary so that NaturalDocs does not write
# absolute paths in config/NaturalDocs/Menu.txt.
# ############################################################################
# Standard startup, find the branch's root directory
# ############################################################################
exit_status=0
die() {
echo $1 >&2
exit 1
}
warn() {
echo $1 >&2
exit_status=1
}
if [ -n "$PERCONA_TOOLKIT_BRANCH" ]; then
BRANCH=$PERCONA_TOOLKIT_BRANCH
else
while [ ! -f Makefile.PL ] && [ $(pwd) != "/" ]; do
cd ..
done
if [ ! -f Makefile.PL ]; then
die "Cannot find the root directory of the Percona Toolkit branch"
fi
BRANCH=`pwd`
fi
# ############################################################################
# Paths
# ############################################################################
DEV_DOCS=$BRANCH/docs/dev
# ############################################################################
# Subroutines
# ############################################################################
write_dev_doc() {
file=$1
pkg=$(basename $file)
pkg=${pkg/%.pm/}
# Modules begin with a capital letter.
if [ $(expr "$pkg" : "[A-Z]") -eq 1 ]; then
outfile=$DEV_DOCS/modules/$pkg.pm
else
outfile=$DEV_DOCS/tools/$pkg.pm
fi
# Don't write unless the file is newer than its dev doc copy.
if [ ! $file -nt $outfile ]; then
echo "$file has not been modified"
return
fi
# Extract the package from the file (Advisor from Advisor.pm,
# pt_kill from pt-kill, etc.).
$BRANCH/util/extract-package $pkg $file > $outfile
if [ $? -ne 0 ]; then
rm $outfile
warn "Error extracting package $pkg from $file"
else
echo "Wrote $outfile"
fi
}
find_file() {
if [ -f $file ]; then
return
fi
if [ -f "$BRANCH/bin/$file" ]; then
file="$BRANCH/bin/$file"
return
fi
if [ -f "$BRANCH/lib/$file" ]; then
file="$BRANCH/lib/$file"
return
fi
warn "$file does not exist"
}
# ############################################################################
# Script starts here
# ############################################################################
if [ -z $@ ]; then
cd $BRANCH
for file in bin/*; do
write_dev_doc $file
done
for file in lib/*.pm; do
write_dev_doc $file
done
else
# Do not cd $BRANCH because user may be using relative paths to a file
# like write-dev-docs ../bin/pt-kill.
for file; do
find_file
write_dev_doc $file
done
fi
# By default NaturalDocs only updates modified files; it only rebuilds
# the menu, indexes, etc. if necessary. To make that necessary, delete
# config/NaturalDocs/Data/, config/NaturalDocs/Menu.txt, and
# docs/dev/html/*, then re-run this tool and NaturalDocs will reuibld
# the html output.
cd $BRANCH
util/NaturalDocs/NaturalDocs \
--project config/NaturalDocs/ \
--input docs/dev/ \
--output HTML docs/dev/html/
exit_status=$(( exit_status | $? ))
exit $exit_status
|