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

Side by Side Diff: third_party/grpc/tools/buildgen/plugins/list_api.py

Issue 1932353002: Initial checkin of gRPC to third_party/ Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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/env python 1 #!/usr/bin/env python2.7
2 # Copyright (C) 2013 Google Inc. All rights reserved. 2
3 # Copyright 2016, Google Inc.
4 # All rights reserved.
3 # 5 #
4 # Redistribution and use in source and binary forms, with or without 6 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions are 7 # modification, are permitted provided that the following conditions are
6 # met: 8 # met:
7 # 9 #
8 # * Redistributions of source code must retain the above copyright 10 # * Redistributions of source code must retain the above copyright
9 # notice, this list of conditions and the following disclaimer. 11 # notice, this list of conditions and the following disclaimer.
10 # * Redistributions in binary form must reproduce the above 12 # * Redistributions in binary form must reproduce the above
11 # copyright notice, this list of conditions and the following disclaimer 13 # copyright notice, this list of conditions and the following disclaimer
12 # in the documentation and/or other materials provided with the 14 # in the documentation and/or other materials provided with the
13 # distribution. 15 # distribution.
14 # * Neither the name of Google Inc. nor the names of its 16 # * Neither the name of Google Inc. nor the names of its
15 # contributors may be used to endorse or promote products derived from 17 # contributors may be used to endorse or promote products derived from
16 # this software without specific prior written permission. 18 # this software without specific prior written permission.
17 # 19 #
18 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 31
30 import os.path 32 import collections
33 import fnmatch
34 import os
35 import re
31 import sys 36 import sys
32 37 import yaml
33 import in_generator
34 import make_runtime_features
35 import name_utilities
36 import template_expander
37 38
38 39
39 # We want exactly the same parsing as RuntimeFeatureWriter 40 _RE_API = r'(?:GPRAPI|GRPCAPI|CENSUSAPI)([^;]*);'
40 # but generate different files.
41 class InternalRuntimeFlagsWriter(make_runtime_features.RuntimeFeatureWriter):
42 class_name = 'InternalRuntimeFlags'
43 41
44 def __init__(self, in_file_path):
45 super(InternalRuntimeFlagsWriter, self).__init__(in_file_path)
46 self._outputs = {(self.class_name + '.idl'): self.generate_idl,
47 (self.class_name + '.h'): self.generate_header,
48 }
49 42
50 @template_expander.use_jinja(class_name + '.idl.tmpl') 43 def list_c_apis(filenames):
51 def generate_idl(self): 44 for filename in filenames:
52 return { 45 with open(filename, 'r') as f:
53 'features': self._features, 46 text = f.read()
54 'standard_features': self._standard_features, 47 for m in re.finditer(_RE_API, text):
55 } 48 api_declaration = re.sub('[ \r\n\t]+', ' ', m.group(1))
49 type_and_name, args_and_close = api_declaration.split('(', 1)
50 args = args_and_close[:args_and_close.rfind(')')].strip()
51 last_space = type_and_name.rfind(' ')
52 last_star = type_and_name.rfind('*')
53 type_end = max(last_space, last_star)
54 return_type = type_and_name[0:type_end+1].strip()
55 name = type_and_name[type_end+1:].strip()
56 yield {'return_type': return_type, 'name': name, 'arguments': args, 'heade r': filename}
56 57
57 @template_expander.use_jinja(class_name + '.h.tmpl') 58
58 def generate_header(self): 59 def headers_under(directory):
59 return { 60 for root, dirnames, filenames in os.walk(directory):
60 'features': self._features, 61 for filename in fnmatch.filter(filenames, '*.h'):
61 'feature_sets': self._feature_sets(), 62 yield os.path.join(root, filename)
62 'standard_features': self._standard_features, 63
63 } 64
65 def mako_plugin(dictionary):
66 apis = []
67
68 # for lib in dictionary['libs']:
69 # if lib['name'] == 'grpc':
70 # apis.extend(list_c_apis(lib['public_headers']))
71 apis.extend(list_c_apis(sorted(headers_under('include/grpc'))))
72
73 dictionary['c_apis'] = apis
64 74
65 75
66 if __name__ == '__main__': 76 if __name__ == '__main__':
67 in_generator.Maker(InternalRuntimeFlagsWriter).main(sys.argv) 77 print yaml.dump([api for api in list_c_apis(headers_under('include/grpc'))])
78
OLDNEW
« no previous file with comments | « third_party/grpc/tools/buildgen/plugins/generate_vsprojects.py ('k') | third_party/grpc/tools/buildgen/plugins/list_protos.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698