annotate OrthancFramework/Resources/CheckOrthancFrameworkSymbols.py @ 4277:c5ca798b158a

CheckOrthancFrameworkSymbols.py
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 03 Nov 2020 18:45:32 +0100
parents
children ab4d015af660
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4277
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 #!/usr/bin/env python
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 # Orthanc - A Lightweight, RESTful DICOM Store
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 # Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5 # Department, University Hospital of Liege, Belgium
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 # Copyright (C) 2017-2020 Osimis S.A., Belgium
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 #
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 # This program is free software: you can redistribute it and/or
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 # modify it under the terms of the GNU Lesser General Public License
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 # as published by the Free Software Foundation, either version 3 of
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 # the License, or (at your option) any later version.
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 #
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 # This program is distributed in the hope that it will be useful, but
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 # Lesser General Public License for more details.
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 #
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 # You should have received a copy of the GNU Lesser General Public
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 # License along with this program. If not, see
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 # <http://www.gnu.org/licenses/>.
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 ##
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 ## This maintenance script detects all the public methods in the
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 ## Orthanc framework that come with an inlined implementation in the
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 ## header file. Such methods can break the ABI of the shared library,
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 ## as the actual implementation might change over versions.
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 ##
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 # Ubuntu 20.04:
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32 # sudo apt-get install python-clang-6.0
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 # ./ParseWebAssemblyExports.py --libclang=libclang-6.0.so.1 ./Test.cpp
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 # Ubuntu 18.04:
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 # sudo apt-get install python-clang-4.0
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 # ./ParseWebAssemblyExports.py --libclang=libclang-4.0.so.1 ./Test.cpp
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 # Ubuntu 14.04:
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 # ./ParseWebAssemblyExports.py --libclang=libclang-3.6.so.1 ./Test.cpp
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 import os
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 import sys
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 import clang.cindex
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 import argparse
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 ##
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 ## Parse the command-line arguments
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 ##
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 parser = argparse.ArgumentParser(description = 'Parse WebAssembly C++ source file, and create a basic JavaScript wrapper.')
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 parser.add_argument('--libclang',
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 default = '',
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 help = 'manually provides the path to the libclang shared library')
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 args = parser.parse_args()
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 if len(args.libclang) != 0:
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 clang.cindex.Config.set_library_file(args.libclang)
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 index = clang.cindex.Index.create()
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 ROOT = os.path.abspath(os.path.dirname(sys.argv[0]))
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 SOURCES = []
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 for root, dirs, files in os.walk(os.path.join(ROOT, '..', 'Sources')):
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 for name in files:
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 if os.path.splitext(name)[1] == '.h':
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 SOURCES.append(os.path.join(root, name))
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 AMALGAMATION = '/tmp/CheckOrthancFrameworkSymbols.cpp'
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 with open(AMALGAMATION, 'w') as f:
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 f.write('#include "%s"\n' % os.path.join(ROOT, '..', 'Sources', 'OrthancFramework.h'))
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 for source in SOURCES:
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 f.write('#include "%s"\n' % source)
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 tu = index.parse(AMALGAMATION,
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 [ '-DORTHANC_BUILDING_FRAMEWORK_LIBRARY=1' ])
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 def ExploreNamespace(node, namespace):
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 for child in node.get_children():
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 fqn = namespace + [ child.spelling ]
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 if child.kind == clang.cindex.CursorKind.NAMESPACE:
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 ExploreNamespace(child, fqn)
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 elif (child.kind == clang.cindex.CursorKind.CLASS_DECL or
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 child.kind == clang.cindex.CursorKind.STRUCT_DECL):
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 visible = False
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 for i in child.get_children():
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 if (i.kind == clang.cindex.CursorKind.VISIBILITY_ATTR and
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 i.spelling == 'default'):
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 visible = True
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 if visible:
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 isPublic = (child.kind == clang.cindex.CursorKind.STRUCT_DECL)
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 for i in child.get_children():
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 if i.kind == clang.cindex.CursorKind.CXX_ACCESS_SPEC_DECL:
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 isPublic = (i.access_specifier == clang.cindex.AccessSpecifier.PUBLIC)
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 elif (i.kind == clang.cindex.CursorKind.CXX_METHOD or
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 i.kind == clang.cindex.CursorKind.CONSTRUCTOR):
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 if isPublic:
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 hasImplementation = False
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 for j in i.get_children():
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 if j.kind == clang.cindex.CursorKind.COMPOUND_STMT:
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 hasImplementation = True
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118 if hasImplementation:
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119 print('Exported public method with an implementation: %s::%s()' %
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 ('::'.join(fqn), i.spelling))
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 for node in tu.cursor.get_children():
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 if (node.kind == clang.cindex.CursorKind.NAMESPACE and
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 node.spelling == 'Orthanc'):
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126 ExploreNamespace(node, [ 'Orthanc' ])