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

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: 2013 -> 2014 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 collections
8 import json
9 import optparse
10 import os
11 import shutil
12 import subprocess
13 import sys
14 import urllib2
15
16
17 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
18 DOC_DIR = os.path.dirname(SCRIPT_DIR)
19
20
21 ChannelInfo = collections.namedtuple('ChannelInfo', ['branch', 'version'])
22
23
24 def Trace(msg):
25 if Trace.verbose:
26 sys.stderr.write(str(msg) + '\n')
27
28 Trace.verbose = False
29
30
31 def GetChannelInfo():
32 url = 'http://omahaproxy.appspot.com/json'
33 u = urllib2.urlopen(url)
34 try:
35 data = json.loads(u.read())
36 finally:
37 u.close()
38
39 channel_info = {}
40 for os_row in data:
41 osname = os_row['os']
42 if osname not in ('win', 'mac', 'linux'):
43 continue
44 for version_row in os_row['versions']:
45 channel = version_row['channel']
46 # We don't display canary docs.
47 if channel == 'canary':
48 continue
49
50 version = version_row['version'].split('.')[0] # Major version
51 branch = version_row['true_branch']
52 if branch is None:
53 branch = 'trunk'
54
55 if channel in channel_info:
56 existing_info = channel_info[channel]
57 if branch != existing_info.branch:
58 sys.stderr.write('Warning: found different branch numbers for '
59 'channel %s: %s vs %s. Using %s.\n' % (
60 channel, branch, existing_info.branch, existing_info.branch))
61 else:
62 channel_info[channel] = ChannelInfo(branch, version)
63
64 return channel_info
65
66
67 def RemoveFile(filename):
68 if os.path.exists(filename):
69 os.remove(filename)
70
71
72 def RemoveDir(dirname):
73 if os.path.exists(dirname):
74 shutil.rmtree(dirname)
75
76
77 def GetSVNRepositoryRoot(branch):
78 if branch == 'trunk':
79 return 'http://src.chromium.org/chrome/trunk/src'
80 return 'http://src.chromium.org/chrome/branches/%s/src' % branch
81
82
83 def CheckoutPepperDocs(branch, doc_dirname):
84 Trace('Removing directory %s' % doc_dirname)
85 RemoveDir(doc_dirname)
86
87 svn_root_url = GetSVNRepositoryRoot(branch)
88
89 for subdir in ('api', 'generators', 'cpp', 'utility'):
90 url = svn_root_url + '/ppapi/%s' % subdir
91 cmd = ['svn', 'co', url, os.path.join(doc_dirname, subdir)]
92 Trace('Checking out docs into %s:\n %s' % (doc_dirname, ' '.join(cmd)))
93 subprocess.check_call(cmd)
94
95 # The IDL generator needs PLY (a python lexing library); check it out into
96 # generators.
97 url = svn_root_url + '/third_party/ply'
98 ply_dirname = os.path.join(doc_dirname, 'generators', 'ply')
99 cmd = ['svn', 'co', url, ply_dirname]
100 Trace('Checking out PLY into %s:\n %s' % (ply_dirname, ' '.join(cmd)))
101 subprocess.check_call(cmd)
102
103
104 def GenerateCHeaders(pepper_version, doc_dirname):
105 script = os.path.join(os.pardir, 'generators', 'generator.py')
106 cwd = os.path.join(doc_dirname, 'api')
107 out_dirname = os.path.join(os.pardir, 'c')
108 cmd = [sys.executable, script, '--cgen', '--release', 'M' + pepper_version,
109 '--wnone', '--dstroot', out_dirname]
110 Trace('Generating C Headers for version %s\n %s' % (
111 pepper_version, ' '.join(cmd)))
112 subprocess.check_call(cmd, cwd=cwd)
113
114
115 def GenerateDoxyfile(template_filename, out_dirname, doc_dirname, doxyfile):
116 Trace('Writing Doxyfile "%s" (from template %s)' % (
117 doxyfile, template_filename))
118
119 with open(template_filename) as f:
120 data = f.read()
121
122 with open(doxyfile, 'w') as f:
123 f.write(data % {'out_dirname': out_dirname, 'doc_dirname': doc_dirname})
124
125
126 def RunDoxygen(out_dirname, doxyfile):
127 Trace('Removing old output directory %s' % out_dirname)
128 RemoveDir(out_dirname)
129
130 Trace('Making new output directory %s' % out_dirname)
131 os.makedirs(out_dirname)
132
133 cmd = ['doxygen', doxyfile]
134 Trace('Running Doxygen:\n %s' % ' '.join(cmd))
135 subprocess.check_call(cmd)
136
137
138 def RunDoxyCleanup(out_dirname):
139 cmd = [sys.executable, 'doxy_cleanup.py', out_dirname]
140 if Trace.verbose:
141 cmd.append('-v')
142 Trace('Running doxy_cleanup:\n %s' % ' '.join(cmd))
143 subprocess.check_call(cmd)
144
145
146 def RunRstIndex(kind, channel, pepper_version, out_dirname, out_rst_filename):
147 assert kind in ('root', 'c', 'cpp')
148 cmd = [sys.executable, 'rst_index.py',
149 '--' + kind,
150 '--channel', channel,
151 '--version', pepper_version,
152 out_dirname,
153 '-o', out_rst_filename]
154 Trace('Running rst_index:\n %s' % ' '.join(cmd))
155 subprocess.check_call(cmd)
156
157
158 def GenerateDocs(channel, pepper_version, branch):
159 Trace('Generating docs for %s (branch %s)' % (channel, branch))
160 pepper_dirname = 'pepper_%s' % channel
161 # i.e. ../_build/chromesite/pepper_beta
162 chromesite_dir = os.path.join(DOC_DIR, '_build', 'chromesite', pepper_dirname)
163
164 CheckoutPepperDocs(branch, pepper_dirname)
165 GenerateCHeaders(pepper_version, pepper_dirname)
166
167 doxyfile_c = ''
168 doxyfile_cpp = ''
169
170 try:
171 # Generate Root index
172 rst_index_root = os.path.join(DOC_DIR, pepper_dirname, 'index.rst')
173 RunRstIndex('root', channel, pepper_version, chromesite_dir, rst_index_root)
174
175 # Generate C docs
176 out_dirname_c = os.path.join(chromesite_dir, 'c')
177 doxyfile_c = 'Doxyfile.c.%s' % channel
178 rst_index_c = os.path.join(DOC_DIR, pepper_dirname, 'c', 'index.rst')
179 GenerateDoxyfile('Doxyfile.c.template', out_dirname_c, pepper_dirname,
180 doxyfile_c)
181 RunDoxygen(out_dirname_c, doxyfile_c)
182 RunDoxyCleanup(out_dirname_c)
183 RunRstIndex('c', channel, pepper_version, out_dirname_c, rst_index_c)
184
185 # Generate C++ docs
186 out_dirname_cpp = os.path.join(chromesite_dir, 'cpp')
187 doxyfile_cpp = 'Doxyfile.cpp.%s' % channel
188 rst_index_cpp = os.path.join(DOC_DIR, pepper_dirname, 'cpp', 'index.rst')
189 GenerateDoxyfile('Doxyfile.cpp.template', out_dirname_cpp, pepper_dirname,
190 doxyfile_cpp)
191 RunDoxygen(out_dirname_cpp, doxyfile_cpp)
192 RunDoxyCleanup(out_dirname_cpp)
193 RunRstIndex('cpp', channel, pepper_version, out_dirname_cpp, rst_index_cpp)
194 finally:
195 # Cleanup
196 RemoveDir(pepper_dirname)
197 RemoveFile(doxyfile_c)
198 RemoveFile(doxyfile_cpp)
199
200
201 def main(argv):
202 parser = optparse.OptionParser(usage='Usage: %prog [options]')
203 parser.add_option('-v', '--verbose',
204 help='Verbose output', action='store_true')
205 options, _ = parser.parse_args(argv)
206
207 if options.verbose:
208 Trace.verbose = True
209
210 channel_info = GetChannelInfo()
211 for channel, info in channel_info.iteritems():
212 GenerateDocs(channel, info.version, info.branch)
213
214 return 0
215
216
217 if __name__ == '__main__':
218 try:
219 rtn = main(sys.argv[1:])
220 except KeyboardInterrupt:
221 sys.stderr.write('%s: interrupted\n' % os.path.basename(__file__))
222 rtn = 1
223 sys.exit(rtn)
OLDNEW
« no previous file with comments | « native_client_sdk/src/doc/doxygen/footer.html ('k') | native_client_sdk/src/doc/doxygen/header.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698