Implement OCSP stapling in Windows BoringSSL port.
[chromium-blink-merge.git] / native_client_sdk / src / doc / doxygen / rst_index.py
blob9706f97c4dbad8d5e59241ae6bde67f8a2c1d61b
1 #!/usr/bin/env python
2 # Copyright (c) 2014 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
6 import cStringIO
7 import fnmatch
8 import optparse
9 import os
10 import re
11 import sys
13 VALID_CHANNELS = ('stable', 'beta', 'dev')
15 ROOT_FILE_CONTENTS = """\
16 .. _pepper_%(channel)s_index:
19 :orphan:
21 .. DO NOT EDIT! This document is auto-generated by doxygen/rst_index.py.
23 ########################################
24 Pepper API Reference (%(channel_title)s)
25 ########################################
27 This page lists the API for Pepper %(version)s. Apps that use this API can
28 run in Chrome %(version)s or higher.
30 :ref:`Pepper C API Reference <pepper_%(channel)s_c_index>`
31 ===========================================================
33 :ref:`Pepper C++ API Reference <pepper_%(channel)s_cpp_index>`
34 ===============================================================
36 """
38 C_FILE_CONTENTS = """\
39 .. _pepper_%(channel)s_c_index:
40 .. _c-api%(channel_alt)s:
42 .. DO NOT EDIT! This document is auto-generated by doxygen/rst_index.py.
44 ##########################################
45 Pepper C API Reference (%(channel_title)s)
46 ##########################################
48 This page lists the C API for Pepper %(version)s. Apps that use this API can
49 run in Chrome %(version)s or higher.
51 `Interfaces <pepper_%(channel)s/c/group___interfaces.html>`__
52 =============================================================
53 %(interfaces)s
55 `Structures <pepper_%(channel)s/c/group___structs.html>`__
56 ==========================================================
57 %(structures)s
59 `Functions <pepper_%(channel)s/c/group___functions.html>`__
60 ===========================================================
62 `Enums <pepper_%(channel)s/c/group___enums.html>`__
63 ===================================================
65 `Typedefs <pepper_%(channel)s/c/group___typedefs.html>`__
66 =========================================================
68 `Macros <pepper_%(channel)s/c/globals_defs.html>`__
69 ===================================================
71 Files
72 =====
73 %(files)s
74 """
76 C_INTERFACE_WILDCARDS = ['struct_p_p_p__*', 'struct_p_p_b__*']
78 C_STRUCT_WILDCARDS = ['struct_p_p__*', 'union_p_p__*']
80 CPP_FILE_CONTENTS = """\
81 .. _pepper_%(channel)s_cpp_index:
82 .. _cpp-api%(channel_alt)s:
84 .. DO NOT EDIT! This document is auto-generated by doxygen/rst_index.py.
86 ############################################
87 Pepper C++ API Reference (%(channel_title)s)
88 ############################################
90 This page lists the C++ API for Pepper %(version)s. Apps that use this API can
91 run in Chrome %(version)s or higher.
93 `Classes <pepper_%(channel)s/cpp/inherits.html>`__
94 ==================================================
95 %(classes)s
97 Files
98 =====
99 %(files)s
102 CPP_CLASSES_WILDCARDS = ['classpp_1_1*.html']
103 CPP_CLASSES_EXCLUDES = ['*-members*']
105 FILE_WILDCARDS = ['*_8h.html']
108 def GetName(filename):
109 filename = os.path.splitext(filename)[0]
110 out = ''
111 if filename.startswith('struct_p_p_b__'):
112 mangle = filename[7:] # skip "struct_"
113 elif filename.startswith('struct_p_p_p__'):
114 mangle = filename[7:] # skip "struct_"
115 elif filename.startswith('struct_p_p__'):
116 mangle = filename[7:] # skip "struct_"
117 elif filename.startswith('union_p_p__'):
118 mangle = filename[6:] # skip "union_"
119 elif filename.startswith('classpp_1_1_'):
120 mangle = filename[12:]
121 elif filename.startswith('classpp_1_1ext_1_1_'):
122 out = 'Ext::' # maybe 'ext::' ?
123 mangle = filename[19:]
124 elif filename.startswith('classpp_1_1internal_1_1_'):
125 out = 'Internal::' # maybe 'internal::'
126 mangle = filename[24:]
127 elif filename.startswith('structpp_1_1internal_1_1_'):
128 out = 'Internal::'
129 mangle = filename[25:]
130 elif filename.endswith('_8h'):
131 return filename[:-3].replace('__', '_') + '.h'
132 else:
133 print 'No match: ' + filename
134 cap = True
135 for c in mangle:
136 if c == '_':
137 if cap:
138 # If cap is True, we've already read one underscore. The second means
139 # that we should insert a literal underscore.
140 cap = False
141 else:
142 cap = True
143 continue
144 if cap:
145 c = c.upper()
146 cap = False
147 out += c
149 # Strip trailing version number (e.g. PPB_Audio_1_1 -> PPB_Audio)
150 return re.sub(r'_\d_\d$', '', out)
153 def GetPath(filepath):
154 if os.path.exists(filepath):
155 return filepath
156 raise OSError('Couldn\'t find: ' + filepath)
159 def MakeReSTListFromFiles(prefix, path, matches, excludes=None):
160 dir_files = os.listdir(path)
161 good_files = []
162 for match in matches:
163 good_files.extend(fnmatch.filter(dir_files, match))
165 if excludes:
166 for exclude in excludes:
167 good_files = [filename for filename in good_files
168 if not fnmatch.fnmatch(filename, exclude)]
170 good_files.sort()
171 return '\n'.join(' * `%s <%s/%s>`__\n' % (GetName(f), prefix, f)
172 for f in good_files)
175 def MakeTitleCase(s):
176 return s[0].upper() + s[1:]
178 def MakeChannelAlt(channel):
179 if channel == 'stable':
180 return ''
181 else:
182 return '-' + channel
185 def GenerateRootIndex(channel, version, out_filename):
186 channel_title = MakeTitleCase(channel)
187 channel_alt = MakeChannelAlt(channel)
189 # Use StringIO so we don't write out a partial file on error.
190 output = cStringIO.StringIO()
191 output.write(ROOT_FILE_CONTENTS % vars())
193 with open(out_filename, 'w') as f:
194 f.write(output.getvalue())
197 def GenerateCIndex(root_dir, channel, version, out_filename):
198 prefix = 'pepper_%s/c' % channel
199 interfaces = MakeReSTListFromFiles(prefix, root_dir, C_INTERFACE_WILDCARDS)
200 structures = MakeReSTListFromFiles(prefix, root_dir, C_STRUCT_WILDCARDS)
201 files = MakeReSTListFromFiles(prefix, root_dir, FILE_WILDCARDS)
202 channel_title = MakeTitleCase(channel)
203 channel_alt = MakeChannelAlt(channel)
205 # Use StringIO so we don't write out a partial file on error.
206 output = cStringIO.StringIO()
207 output.write(C_FILE_CONTENTS % vars())
209 with open(out_filename, 'w') as f:
210 f.write(output.getvalue())
213 def GenerateCppIndex(root_dir, channel, version, out_filename):
214 prefix = 'pepper_%s/cpp' % channel
215 classes = MakeReSTListFromFiles(prefix, root_dir, CPP_CLASSES_WILDCARDS,
216 CPP_CLASSES_EXCLUDES)
217 files = MakeReSTListFromFiles(prefix, root_dir, FILE_WILDCARDS)
218 channel_title = MakeTitleCase(channel)
219 channel_alt = MakeChannelAlt(channel)
221 # Use StringIO so we don't write out a partial file on error.
222 output = cStringIO.StringIO()
223 output.write(CPP_FILE_CONTENTS % vars())
225 with open(out_filename, 'w') as f:
226 f.write(output.getvalue())
229 def main(argv):
230 usage = 'Usage: %prog [options] <--root|--c|--cpp> directory'
231 parser = optparse.OptionParser(usage=usage)
232 parser.add_option('--channel', help='pepper channel (stable, beta, dev)')
233 parser.add_option('--version', help='pepper version (e.g. 32, 33, 34, etc.)')
234 parser.add_option('--root', help='Generate root API index',
235 action='store_true', default=False)
236 parser.add_option('--c', help='Generate C API index', action='store_true',
237 default=False)
238 parser.add_option('--cpp', help='Generate C++ API index', action='store_true',
239 default=False)
240 parser.add_option('-o', '--output', help='output file.')
241 options, files = parser.parse_args(argv)
243 if len(files) != 1:
244 parser.error('Expected one directory')
246 if not options.output:
247 parser.error('Need output file')
249 if options.channel not in VALID_CHANNELS:
250 parser.error('Expected channel to be one of %s' % ', '.join(VALID_CHANNELS))
252 if sum((options.c, options.cpp, options.root)) != 1:
253 parser.error('Exactly one of --c/--cpp/--root flags is required.')
255 root_dir = files[0]
257 if options.c:
258 GenerateCIndex(root_dir, options.channel, options.version, options.output)
259 elif options.cpp:
260 GenerateCppIndex(root_dir, options.channel, options.version, options.output)
261 elif options.root:
262 GenerateRootIndex(options.channel, options.version, options.output)
263 else:
264 assert(False)
265 return 0
268 if __name__ == '__main__':
269 try:
270 rtn = main(sys.argv[1:])
271 except KeyboardInterrupt:
272 sys.stderr.write('%s: interrupted\n' % os.path.basename(__file__))
273 rtn = 1
274 sys.exit(rtn)