OLD | NEW |
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 Loading... |
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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 'script_dirname': SCRIPT_DIR}) | 198 'script_dirname': SCRIPT_DIR}) |
168 | 199 |
169 | 200 |
170 def RunDoxygen(out_dirname, doxyfile): | 201 def RunDoxygen(out_dirname, doxyfile): |
171 Trace('Removing old output directory %s' % out_dirname) | 202 Trace('Removing old output directory %s' % out_dirname) |
172 RemoveDir(out_dirname) | 203 RemoveDir(out_dirname) |
173 | 204 |
174 Trace('Making new output directory %s' % out_dirname) | 205 Trace('Making new output directory %s' % out_dirname) |
175 os.makedirs(out_dirname) | 206 os.makedirs(out_dirname) |
176 | 207 |
177 cmd = ['doxygen', doxyfile] | 208 doxygen = os.environ.get('DOXYGEN', 'doxygen') |
| 209 cmd = [doxygen, doxyfile] |
178 Trace('Running Doxygen:\n %s' % ' '.join(cmd)) | 210 Trace('Running Doxygen:\n %s' % ' '.join(cmd)) |
179 subprocess.check_call(cmd) | 211 subprocess.check_call(cmd) |
180 | 212 |
181 | 213 |
182 def RunDoxyCleanup(out_dirname): | 214 def RunDoxyCleanup(out_dirname): |
183 script = os.path.join(SCRIPT_DIR, 'doxy_cleanup.py') | 215 script = os.path.join(SCRIPT_DIR, 'doxy_cleanup.py') |
184 cmd = [sys.executable, script, out_dirname] | 216 cmd = [sys.executable, script, out_dirname] |
185 if Trace.verbose: | 217 if Trace.verbose: |
186 cmd.append('-v') | 218 cmd.append('-v') |
187 Trace('Running doxy_cleanup:\n %s' % ' '.join(cmd)) | 219 Trace('Running doxy_cleanup:\n %s' % ' '.join(cmd)) |
188 subprocess.check_call(cmd) | 220 subprocess.check_call(cmd) |
189 | 221 |
190 | 222 |
191 def RunRstIndex(kind, channel, pepper_version, out_dirname, out_rst_filename): | 223 def RunRstIndex(kind, channel, pepper_version, out_dirname, out_rst_filename): |
192 assert kind in ('root', 'c', 'cpp') | 224 assert kind in ('root', 'c', 'cpp') |
193 script = os.path.join(SCRIPT_DIR, 'rst_index.py') | 225 script = os.path.join(SCRIPT_DIR, 'rst_index.py') |
194 cmd = [sys.executable, script, | 226 cmd = [sys.executable, script, |
195 '--' + kind, | 227 '--' + kind, |
196 '--channel', channel, | 228 '--channel', channel, |
197 '--version', pepper_version, | 229 '--version', pepper_version, |
198 out_dirname, | 230 out_dirname, |
199 '-o', out_rst_filename] | 231 '-o', out_rst_filename] |
200 Trace('Running rst_index:\n %s' % ' '.join(cmd)) | 232 Trace('Running rst_index:\n %s' % ' '.join(cmd)) |
201 subprocess.check_call(cmd) | 233 subprocess.check_call(cmd) |
202 | 234 |
203 | 235 |
| 236 def GetRstName(kind, channel): |
| 237 if channel == 'stable': |
| 238 filename = '%s-api.rst' % kind |
| 239 else: |
| 240 filename = '%s-api-%s.rst' % (kind, channel) |
| 241 return os.path.join(DOC_DIR, filename) |
| 242 |
| 243 |
204 def GenerateDocs(root_dirname, channel, pepper_version, branch): | 244 def GenerateDocs(root_dirname, channel, pepper_version, branch): |
205 Trace('Generating docs for %s (branch %s)' % (channel, branch)) | 245 Trace('Generating docs for %s (branch %s)' % (channel, branch)) |
206 pepper_dirname = 'pepper_%s' % channel | 246 pepper_dirname = 'pepper_%s' % channel |
207 out_dirname = os.path.join(root_dirname, pepper_dirname) | 247 out_dirname = os.path.join(root_dirname, pepper_dirname) |
208 | 248 |
209 try: | 249 try: |
210 svn_dirname = tempfile.mkdtemp(prefix=pepper_dirname) | 250 svn_dirname = tempfile.mkdtemp(prefix=pepper_dirname) |
211 doxyfile_dirname = tempfile.mkdtemp(prefix='%s_doxyfiles' % pepper_dirname) | 251 doxyfile_dirname = tempfile.mkdtemp(prefix='%s_doxyfiles' % pepper_dirname) |
212 | 252 |
213 CheckoutPepperDocs(branch, svn_dirname) | 253 CheckoutPepperDocs(branch, svn_dirname) |
214 FixPepperDocLinks(svn_dirname) | 254 FixPepperDocLinks(svn_dirname) |
215 GenerateCHeaders(pepper_version, svn_dirname) | 255 GenerateCHeaders(pepper_version, svn_dirname) |
216 | 256 |
217 doxyfile_c = '' | 257 doxyfile_c = '' |
218 doxyfile_cpp = '' | 258 doxyfile_cpp = '' |
219 | 259 |
220 # Generate Root index | 260 # Generate Root index |
221 rst_index_root = os.path.join(DOC_DIR, pepper_dirname, 'index.rst') | 261 rst_index_root = os.path.join(DOC_DIR, pepper_dirname, 'index.rst') |
222 RunRstIndex('root', channel, pepper_version, out_dirname, rst_index_root) | 262 RunRstIndex('root', channel, pepper_version, out_dirname, rst_index_root) |
223 | 263 |
224 # Generate C docs | 264 # Generate C docs |
225 out_dirname_c = os.path.join(out_dirname, 'c') | 265 out_dirname_c = os.path.join(out_dirname, 'c') |
226 doxyfile_c = os.path.join(doxyfile_dirname, 'Doxyfile.c.%s' % channel) | 266 doxyfile_c = os.path.join(doxyfile_dirname, 'Doxyfile.c.%s' % channel) |
227 doxyfile_c_template = os.path.join(SCRIPT_DIR, 'Doxyfile.c.template') | 267 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') | 268 rst_index_c = GetRstName('c', channel) |
229 GenerateDoxyfile(doxyfile_c_template, out_dirname_c, svn_dirname, | 269 GenerateDoxyfile(doxyfile_c_template, out_dirname_c, svn_dirname, |
230 doxyfile_c) | 270 doxyfile_c) |
231 RunDoxygen(out_dirname_c, doxyfile_c) | 271 RunDoxygen(out_dirname_c, doxyfile_c) |
232 RunDoxyCleanup(out_dirname_c) | 272 RunDoxyCleanup(out_dirname_c) |
233 RunRstIndex('c', channel, pepper_version, out_dirname_c, rst_index_c) | 273 RunRstIndex('c', channel, pepper_version, out_dirname_c, rst_index_c) |
234 | 274 |
235 # Generate C++ docs | 275 # Generate C++ docs |
236 out_dirname_cpp = os.path.join(out_dirname, 'cpp') | 276 out_dirname_cpp = os.path.join(out_dirname, 'cpp') |
237 doxyfile_cpp = os.path.join(doxyfile_dirname, 'Doxyfile.cpp.%s' % channel) | 277 doxyfile_cpp = os.path.join(doxyfile_dirname, 'Doxyfile.cpp.%s' % channel) |
238 doxyfile_cpp_template = os.path.join(SCRIPT_DIR, 'Doxyfile.cpp.template') | 278 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') | 279 rst_index_cpp = GetRstName('cpp', channel) |
240 GenerateDoxyfile(doxyfile_cpp_template, out_dirname_cpp, svn_dirname, | 280 GenerateDoxyfile(doxyfile_cpp_template, out_dirname_cpp, svn_dirname, |
241 doxyfile_cpp) | 281 doxyfile_cpp) |
242 RunDoxygen(out_dirname_cpp, doxyfile_cpp) | 282 RunDoxygen(out_dirname_cpp, doxyfile_cpp) |
243 RunDoxyCleanup(out_dirname_cpp) | 283 RunDoxyCleanup(out_dirname_cpp) |
244 RunRstIndex('cpp', channel, pepper_version, out_dirname_cpp, rst_index_cpp) | 284 RunRstIndex('cpp', channel, pepper_version, out_dirname_cpp, rst_index_cpp) |
245 finally: | 285 finally: |
246 # Cleanup | 286 # Cleanup |
247 RemoveDir(svn_dirname) | 287 RemoveDir(svn_dirname) |
248 RemoveDir(doxyfile_dirname) | 288 RemoveDir(doxyfile_dirname) |
249 | 289 |
(...skipping 17 matching lines...) Expand all Loading... |
267 return 0 | 307 return 0 |
268 | 308 |
269 | 309 |
270 if __name__ == '__main__': | 310 if __name__ == '__main__': |
271 try: | 311 try: |
272 rtn = main(sys.argv[1:]) | 312 rtn = main(sys.argv[1:]) |
273 except KeyboardInterrupt: | 313 except KeyboardInterrupt: |
274 sys.stderr.write('%s: interrupted\n' % os.path.basename(__file__)) | 314 sys.stderr.write('%s: interrupted\n' % os.path.basename(__file__)) |
275 rtn = 1 | 315 rtn = 1 |
276 sys.exit(rtn) | 316 sys.exit(rtn) |
OLD | NEW |