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

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

Issue 591683002: [NaCl SDK Docs] Fix many issues with the doc generator. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 6 years, 3 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
OLDNEW
1 #!/usr/bin/python 1 #!/usr/bin/python
2 2
3 # Copyright (c) 2014 The Chromium Authors. All rights reserved. 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 4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file. 5 # found in the LICENSE file.
6 6
7 import collections 7 import collections
8 import json 8 import json
9 import optparse 9 import optparse
10 import os 10 import os
11 import shutil 11 import shutil
12 import subprocess 12 import subprocess
13 import sys 13 import sys
14 import tempfile 14 import tempfile
15 import urllib2 15 import urllib2
16 16
17 17
18 if sys.version_info < (2, 7, 0):
19 sys.stderr.write("python 2.7 or later is required run this script\n")
20 sys.exit(1)
21
22
18 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) 23 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
19 DOC_DIR = os.path.dirname(SCRIPT_DIR) 24 DOC_DIR = os.path.dirname(SCRIPT_DIR)
20 25
21 26
22 ChannelInfo = collections.namedtuple('ChannelInfo', ['branch', 'version']) 27 ChannelInfo = collections.namedtuple('ChannelInfo', ['branch', 'version'])
23 28
24 29
25 def Trace(msg): 30 def Trace(msg):
26 if Trace.verbose: 31 if Trace.verbose:
27 sys.stderr.write(str(msg) + '\n') 32 sys.stderr.write(str(msg) + '\n')
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 def RemoveFile(filename): 73 def RemoveFile(filename):
69 if os.path.exists(filename): 74 if os.path.exists(filename):
70 os.remove(filename) 75 os.remove(filename)
71 76
72 77
73 def RemoveDir(dirname): 78 def RemoveDir(dirname):
74 if os.path.exists(dirname): 79 if os.path.exists(dirname):
75 shutil.rmtree(dirname) 80 shutil.rmtree(dirname)
76 81
77 82
78 def GetSVNRepositoryRoot(branch): 83 def HasBranchHeads():
79 if branch == 'trunk': 84 cmd = ['git', 'for-each-ref', '--format=%(refname)',
80 return 'http://src.chromium.org/chrome/trunk/src' 85 'refs/remotes/branch-heads']
81 return 'http://src.chromium.org/chrome/branches/%s/src' % branch 86 output = subprocess.check_output(cmd).splitlines()
87 return output != []
88
89
90 def CheckoutDirectories(dest_dirname, refname, root_path, patterns=None):
91 treeish = '%s:%s' % (refname, root_path)
92 cmd = ['git', 'ls-tree', '--full-tree', '-r', treeish]
93 if patterns:
94 cmd.extend(patterns)
95
96 Trace('Running \"%s\":' % ' '.join(cmd))
97 output = subprocess.check_output(cmd)
98 for line in output.splitlines():
99 info, rel_filename = line.split('\t')
100 sha = info.split(' ')[2]
101
102 Trace(' %s %s' % (sha, rel_filename))
103
104 cmd = ['git', 'show', sha]
105 blob = subprocess.check_output(cmd)
106 filename = os.path.join(dest_dirname, rel_filename)
107 dirname = os.path.dirname(filename)
108 if not os.path.exists(dirname):
109 os.makedirs(dirname)
110
111 Trace(' writing to %s' % filename)
112 with open(filename, 'w') as f:
113 f.write(blob)
82 114
83 115
84 def CheckoutPepperDocs(branch, doc_dirname): 116 def CheckoutPepperDocs(branch, doc_dirname):
85 Trace('Removing directory %s' % doc_dirname) 117 Trace('Removing directory %s' % doc_dirname)
86 RemoveDir(doc_dirname) 118 RemoveDir(doc_dirname)
87 119
88 svn_root_url = GetSVNRepositoryRoot(branch) 120 if branch == 'master':
121 refname = 'refs/remotes/origin/master'
122 else:
123 refname = 'refs/remotes/branch-heads/%s' % branch
89 124
90 for subdir in ('api', 'generators', 'cpp', 'utility'): 125 Trace('Checking out docs into %s' % doc_dirname)
91 url = svn_root_url + '/ppapi/%s' % subdir 126 subdirs = ['api', 'generators', 'cpp', 'utility']
92 cmd = ['svn', 'co', url, os.path.join(doc_dirname, subdir)] 127 CheckoutDirectories(doc_dirname, refname, 'ppapi', subdirs)
93 Trace('Checking out docs into %s:\n %s' % (doc_dirname, ' '.join(cmd)))
94 subprocess.check_call(cmd)
95 128
96 # The IDL generator needs PLY (a python lexing library); check it out into 129 # The IDL generator needs PLY (a python lexing library); check it out into
97 # generators. 130 # generators.
98 url = svn_root_url + '/third_party/ply'
99 ply_dirname = os.path.join(doc_dirname, 'generators', 'ply') 131 ply_dirname = os.path.join(doc_dirname, 'generators', 'ply')
100 cmd = ['svn', 'co', url, ply_dirname] 132 Trace('Checking out PLY into %s' % ply_dirname)
101 Trace('Checking out PLY into %s:\n %s' % (ply_dirname, ' '.join(cmd))) 133 CheckoutDirectories(ply_dirname, refname, 'third_party/ply')
102 subprocess.check_call(cmd)
103 134
104 135
105 def FixPepperDocLinks(doc_dirname): 136 def FixPepperDocLinks(doc_dirname):
106 # TODO(binji): We can remove this step when the correct links are in the 137 # TODO(binji): We can remove this step when the correct links are in the
107 # stable branch. 138 # stable branch.
108 Trace('Looking for links to fix in Pepper headers...') 139 Trace('Looking for links to fix in Pepper headers...')
109 for root, dirs, filenames in os.walk(doc_dirname): 140 for root, dirs, filenames in os.walk(doc_dirname):
110 # Don't recurse into .svn 141 # Don't recurse into .svn
111 if '.svn' in dirs: 142 if '.svn' in dirs:
112 dirs.remove('.svn') 143 dirs.remove('.svn')
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 cmd = [sys.executable, script, 225 cmd = [sys.executable, script,
195 '--' + kind, 226 '--' + kind,
196 '--channel', channel, 227 '--channel', channel,
197 '--version', pepper_version, 228 '--version', pepper_version,
198 out_dirname, 229 out_dirname,
199 '-o', out_rst_filename] 230 '-o', out_rst_filename]
200 Trace('Running rst_index:\n %s' % ' '.join(cmd)) 231 Trace('Running rst_index:\n %s' % ' '.join(cmd))
201 subprocess.check_call(cmd) 232 subprocess.check_call(cmd)
202 233
203 234
235 def GetRstName(kind, channel):
236 if channel == 'stable':
237 filename = '%s-api.rst' % kind
238 else:
239 filename = '%s-api-%s.rst' % (kind, channel)
240 return os.path.join(DOC_DIR, filename)
241
242
204 def GenerateDocs(root_dirname, channel, pepper_version, branch): 243 def GenerateDocs(root_dirname, channel, pepper_version, branch):
205 Trace('Generating docs for %s (branch %s)' % (channel, branch)) 244 Trace('Generating docs for %s (branch %s)' % (channel, branch))
206 pepper_dirname = 'pepper_%s' % channel 245 pepper_dirname = 'pepper_%s' % channel
207 out_dirname = os.path.join(root_dirname, pepper_dirname) 246 out_dirname = os.path.join(root_dirname, pepper_dirname)
208 247
209 try: 248 try:
210 svn_dirname = tempfile.mkdtemp(prefix=pepper_dirname) 249 svn_dirname = tempfile.mkdtemp(prefix=pepper_dirname)
211 doxyfile_dirname = tempfile.mkdtemp(prefix='%s_doxyfiles' % pepper_dirname) 250 doxyfile_dirname = tempfile.mkdtemp(prefix='%s_doxyfiles' % pepper_dirname)
212 251
213 CheckoutPepperDocs(branch, svn_dirname) 252 CheckoutPepperDocs(branch, svn_dirname)
214 FixPepperDocLinks(svn_dirname) 253 FixPepperDocLinks(svn_dirname)
215 GenerateCHeaders(pepper_version, svn_dirname) 254 GenerateCHeaders(pepper_version, svn_dirname)
216 255
217 doxyfile_c = '' 256 doxyfile_c = ''
218 doxyfile_cpp = '' 257 doxyfile_cpp = ''
219 258
220 # Generate Root index 259 # Generate Root index
221 rst_index_root = os.path.join(DOC_DIR, pepper_dirname, 'index.rst') 260 rst_index_root = os.path.join(DOC_DIR, pepper_dirname, 'index.rst')
222 RunRstIndex('root', channel, pepper_version, out_dirname, rst_index_root) 261 RunRstIndex('root', channel, pepper_version, out_dirname, rst_index_root)
223 262
224 # Generate C docs 263 # Generate C docs
225 out_dirname_c = os.path.join(out_dirname, 'c') 264 out_dirname_c = os.path.join(out_dirname, 'c')
226 doxyfile_c = os.path.join(doxyfile_dirname, 'Doxyfile.c.%s' % channel) 265 doxyfile_c = os.path.join(doxyfile_dirname, 'Doxyfile.c.%s' % channel)
227 doxyfile_c_template = os.path.join(SCRIPT_DIR, 'Doxyfile.c.template') 266 doxyfile_c_template = os.path.join(SCRIPT_DIR, 'Doxyfile.c.template')
228 rst_index_c = os.path.join(DOC_DIR, pepper_dirname, 'c', 'index.rst') 267 rst_index_c = GetRstName('c', channel)
229 GenerateDoxyfile(doxyfile_c_template, out_dirname_c, svn_dirname, 268 GenerateDoxyfile(doxyfile_c_template, out_dirname_c, svn_dirname,
230 doxyfile_c) 269 doxyfile_c)
231 RunDoxygen(out_dirname_c, doxyfile_c) 270 RunDoxygen(out_dirname_c, doxyfile_c)
232 RunDoxyCleanup(out_dirname_c) 271 RunDoxyCleanup(out_dirname_c)
233 RunRstIndex('c', channel, pepper_version, out_dirname_c, rst_index_c) 272 RunRstIndex('c', channel, pepper_version, out_dirname_c, rst_index_c)
234 273
235 # Generate C++ docs 274 # Generate C++ docs
236 out_dirname_cpp = os.path.join(out_dirname, 'cpp') 275 out_dirname_cpp = os.path.join(out_dirname, 'cpp')
237 doxyfile_cpp = os.path.join(doxyfile_dirname, 'Doxyfile.cpp.%s' % channel) 276 doxyfile_cpp = os.path.join(doxyfile_dirname, 'Doxyfile.cpp.%s' % channel)
238 doxyfile_cpp_template = os.path.join(SCRIPT_DIR, 'Doxyfile.cpp.template') 277 doxyfile_cpp_template = os.path.join(SCRIPT_DIR, 'Doxyfile.cpp.template')
239 rst_index_cpp = os.path.join(DOC_DIR, pepper_dirname, 'cpp', 'index.rst') 278 rst_index_cpp = GetRstName('cpp', channel)
240 GenerateDoxyfile(doxyfile_cpp_template, out_dirname_cpp, svn_dirname, 279 GenerateDoxyfile(doxyfile_cpp_template, out_dirname_cpp, svn_dirname,
241 doxyfile_cpp) 280 doxyfile_cpp)
242 RunDoxygen(out_dirname_cpp, doxyfile_cpp) 281 RunDoxygen(out_dirname_cpp, doxyfile_cpp)
243 RunDoxyCleanup(out_dirname_cpp) 282 RunDoxyCleanup(out_dirname_cpp)
244 RunRstIndex('cpp', channel, pepper_version, out_dirname_cpp, rst_index_cpp) 283 RunRstIndex('cpp', channel, pepper_version, out_dirname_cpp, rst_index_cpp)
245 finally: 284 finally:
246 # Cleanup 285 # Cleanup
247 RemoveDir(svn_dirname) 286 RemoveDir(svn_dirname)
248 RemoveDir(doxyfile_dirname) 287 RemoveDir(doxyfile_dirname)
249 288
(...skipping 17 matching lines...) Expand all
267 return 0 306 return 0
268 307
269 308
270 if __name__ == '__main__': 309 if __name__ == '__main__':
271 try: 310 try:
272 rtn = main(sys.argv[1:]) 311 rtn = main(sys.argv[1:])
273 except KeyboardInterrupt: 312 except KeyboardInterrupt:
274 sys.stderr.write('%s: interrupted\n' % os.path.basename(__file__)) 313 sys.stderr.write('%s: interrupted\n' % os.path.basename(__file__))
275 rtn = 1 314 rtn = 1
276 sys.exit(rtn) 315 sys.exit(rtn)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698