Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(688)

Side by Side Diff: native_client_sdk/src/doc/doxygen/generate_docs.py

Issue 136033007: [NaCl SDK Docs] Simplify PPAPI documentation generation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 #!/usr/bin/python
2
3 # Copyright (c) 2014 The Chromium Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file.
6
7 import json
8 import optparse
9 import os
10 import shutil
11 import subprocess
12 import sys
13 import urllib2
14
15
16 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
17 DOC_DIR = os.path.dirname(SCRIPT_DIR)
18
19
20 def Trace(msg):
21 if Trace.verbose:
22 sys.stderr.write(str(msg) + '\n')
23
24 Trace.verbose = False
25
26
27 def GetChannelBranches():
28 url = 'http://omahaproxy.appspot.com/json'
29 u = urllib2.urlopen(url)
30 try:
31 data = json.loads(u.read())
32 finally:
33 u.close()
34
35 channel_branch = {}
36 for os_row in data:
37 os = os_row['os']
38 if os not in ('win', 'mac', 'linux'):
39 continue
40 for version_row in os_row['versions']:
41 channel = version_row['channel']
42 # We don't display canary docs.
43 if channel == 'canary':
44 continue
45
46 branch = version_row['true_branch']
47 if channel in channel_branch:
48 existing_branch = channel_branch[channel]
49 if branch != existing_branch:
50 sys.stderr.write('Warning: found different branch numbers for '
51 'channel %s: %s vs %s. Using %s.\n' % (
52 channel, branch, existing_branch, existing_branch))
53 else:
54 channel_branch[channel] = branch
55
56 return channel_branch
57
58
59 def RemoveFile(filename):
60 try:
61 os.remove(filename)
62 except OSError:
63 pass
Sam Clegg 2014/01/15 23:22:59 Why ignore these errors?
binji 2014/01/15 23:56:16 I don't want to error when the file or directory d
binji 2014/01/16 22:27:08 Done.
64
65
66 def RemoveDir(dirname):
67 try:
68 shutil.rmtree(dirname)
69 except OSError:
70 pass
71
72
73 def CheckoutPepperDocs(branch, doc_dirname):
74 Trace('Removing directory %s' % doc_dirname)
75 RemoveDir(doc_dirname)
76
77 for subdir in ('c', 'cpp', 'utility'):
78 url = 'http://src.chromium.org/chrome/branches/%s/src/ppapi/%s' % (
79 branch, subdir)
80 cmd = ['svn', 'co', url, os.path.join(doc_dirname, subdir)]
81 Trace('Checking out docs into %s:\n %s' % (doc_dirname, ' '.join(cmd)))
82 subprocess.check_call(cmd)
83
84
85 def GenerateDoxyfile(template_filename, out_dirname, doc_dirname, doxyfile):
86 Trace('Writing Doxyfile "%s" (from template %s)' % (
87 doxyfile, template_filename))
88
89 with open(template_filename) as f:
90 data = f.read()
91
92 with open(doxyfile, 'w') as f:
93 f.write(data % {'out_dirname': out_dirname, 'doc_dirname': doc_dirname})
94
95
96 def RunDoxygen(out_dirname, doxyfile):
97 Trace('Removing old output directory %s' % out_dirname)
98 RemoveDir(out_dirname)
99
100 Trace('Making new output directory %s' % out_dirname)
101 os.makedirs(out_dirname)
102
103 cmd = ['doxygen', doxyfile]
104 Trace('Running Doxygen:\n %s' % ' '.join(cmd))
105 subprocess.check_call(cmd)
106
107
108 def RunDoxyCleanup(out_dirname):
109 cmd = [sys.executable, 'doxy_cleanup.py', out_dirname]
110 if Trace.verbose:
111 cmd.append('-v')
112 Trace('Running doxy_cleanup:\n %s' % ' '.join(cmd))
113 subprocess.check_call(cmd)
114
115
116 def RunRstIndex(kind, channel, out_dirname, out_rst_filename):
117 assert kind in ('root', 'c', 'cpp')
118 cmd = [sys.executable, 'rst_index.py',
119 '--' + kind,
120 '--channel', channel,
121 out_dirname,
122 '-o', out_rst_filename]
123 Trace('Running rst_index:\n %s' % ' '.join(cmd))
124 subprocess.check_call(cmd)
125
126
127 def GenerateDocs(channel, branch):
128 Trace('Generating docs for %s (branch %s)' % (channel, branch))
129 pepper_dirname = 'pepper_%s' % channel
130 # i.e. ../_build/chromesite/pepper_beta
131 chromesite_dir = os.path.join(DOC_DIR, '_build', 'chromesite', pepper_dirname)
132
133 CheckoutPepperDocs(branch, pepper_dirname)
134
135 doxyfile_c = ''
136 doxyfile_cpp = ''
137
138 try:
139 # Generate Root index
140 rst_index_root = os.path.join(DOC_DIR, pepper_dirname, 'index.rst')
141 RunRstIndex('root', channel, chromesite_dir, rst_index_root)
142
143 # Generate C docs
144 out_dirname_c = os.path.join(chromesite_dir, 'c')
145 doxyfile_c = 'Doxyfile.c.%s' % channel
146 rst_index_c = os.path.join(DOC_DIR, pepper_dirname, 'c', 'index.rst')
147 GenerateDoxyfile('Doxyfile.c.template', out_dirname_c, pepper_dirname,
148 doxyfile_c)
149 RunDoxygen(out_dirname_c, doxyfile_c)
150 RunDoxyCleanup(out_dirname_c)
151 RunRstIndex('c', channel, out_dirname_c, rst_index_c)
152
153 # Generate C++ docs
154 out_dirname_cpp = os.path.join(chromesite_dir, 'cpp')
155 doxyfile_cpp = 'Doxyfile.cpp.%s' % channel
156 rst_index_cpp = os.path.join(DOC_DIR, pepper_dirname, 'cpp', 'index.rst')
157 GenerateDoxyfile('Doxyfile.cpp.template', out_dirname_cpp, pepper_dirname,
158 doxyfile_cpp)
159 RunDoxygen(out_dirname_cpp, doxyfile_cpp)
160 RunDoxyCleanup(out_dirname_cpp)
161 RunRstIndex('cpp', channel, out_dirname_cpp, rst_index_cpp)
162 finally:
163 # Cleanup
164 RemoveDir(pepper_dirname)
165 RemoveFile(doxyfile_c)
166 RemoveFile(doxyfile_cpp)
167
168
169 def main(argv):
170 parser = optparse.OptionParser(usage='Usage: %prog [options]')
171 parser.add_option('-v', '--verbose',
172 help='Verbose output', action='store_true')
173 options, files = parser.parse_args(argv)
174
175 if options.verbose:
176 Trace.verbose = True
177
178 channel_branch = GetChannelBranches()
179 for channel, branch in channel_branch.iteritems():
180 GenerateDocs(channel, branch)
181
182 return 0
183
184
185 if __name__ == '__main__':
186 try:
187 rtn = main(sys.argv[1:])
188 except KeyboardInterrupt:
189 sys.stderr.write('%s: interrupted\n' % os.path.basename(__file__))
190 rtn = 1
191 sys.exit(rtn)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698