annotate OrthancFramework/Resources/CheckOrthancFrameworkSymbols.py @ 4778:50fd70169f6e

news
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 30 Aug 2021 11:41:27 +0200
parents 1de2fc0363cb
children 7053502fbf97
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
4437
d9473bd5ed43 upgrade to year 2021
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4349
diff changeset
6 # Copyright (C) 2017-2021 Osimis S.A., Belgium
4277
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')
4520
f5cb0c0ffbed added unit test OrthancFramework.SizeOf to dump sizeof all the public classes in the Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
56 parser.add_argument('--target-cpp-size',
f5cb0c0ffbed added unit test OrthancFramework.SizeOf to dump sizeof all the public classes in the Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
57 default = '',
f5cb0c0ffbed added unit test OrthancFramework.SizeOf to dump sizeof all the public classes in the Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
58 help = 'where to store C++ source to display the size of each public class')
4277
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 args = parser.parse_args()
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61
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 if len(args.libclang) != 0:
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 clang.cindex.Config.set_library_file(args.libclang)
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 index = clang.cindex.Index.create()
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67
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 ROOT = os.path.abspath(os.path.dirname(sys.argv[0]))
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 SOURCES = []
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 for root, dirs, files in os.walk(os.path.join(ROOT, '..', 'Sources')):
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 for name in files:
4305
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4304
diff changeset
74 if (os.path.splitext(name)[1] == '.h' and
4537
1de2fc0363cb sanity checks in CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4520
diff changeset
75 not name.endswith('.impl.h')):
4277
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 SOURCES.append(os.path.join(root, name))
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 AMALGAMATION = '/tmp/CheckOrthancFrameworkSymbols.cpp'
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 with open(AMALGAMATION, 'w') as f:
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 f.write('#include "%s"\n' % os.path.join(ROOT, '..', 'Sources', 'OrthancFramework.h'))
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 for source in SOURCES:
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 f.write('#include "%s"\n' % source)
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
4303
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
86 tu = index.parse(AMALGAMATION, [
4537
1de2fc0363cb sanity checks in CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4520
diff changeset
87 '--std=c++11',
4303
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
88 '-DORTHANC_BUILDING_FRAMEWORK_LIBRARY=1',
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
89 '-DORTHANC_BUILD_UNIT_TESTS=0',
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
90 '-DORTHANC_ENABLE_BASE64=1',
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
91 '-DORTHANC_ENABLE_CIVETWEB=1',
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
92 '-DORTHANC_ENABLE_CURL=1',
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
93 '-DORTHANC_ENABLE_DCMTK=1',
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
94 '-DORTHANC_ENABLE_DCMTK_JPEG=1',
4537
1de2fc0363cb sanity checks in CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4520
diff changeset
95 '-DORTHANC_ENABLE_DCMTK_JPEG_LOSSLESS=1',
4303
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
96 '-DORTHANC_ENABLE_DCMTK_NETWORKING=1',
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
97 '-DORTHANC_ENABLE_DCMTK_TRANSCODING=1',
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
98 '-DORTHANC_ENABLE_JPEG=1',
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
99 '-DORTHANC_ENABLE_LOCALE=1',
4305
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4304
diff changeset
100 '-DORTHANC_ENABLE_LOGGING=1',
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4304
diff changeset
101 '-DORTHANC_ENABLE_LOGGING_STDIO=0',
4303
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
102 '-DORTHANC_ENABLE_LUA=1',
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
103 '-DORTHANC_ENABLE_MD5=1',
4537
1de2fc0363cb sanity checks in CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4520
diff changeset
104 '-DORTHANC_ENABLE_MONGOOSE=1',
4303
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
105 '-DORTHANC_ENABLE_PKCS11=1',
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
106 '-DORTHANC_ENABLE_PNG=1',
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
107 '-DORTHANC_ENABLE_PUGIXML=1',
4537
1de2fc0363cb sanity checks in CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4520
diff changeset
108 '-DORTHANC_ENABLE_SQLITE=1',
4303
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
109 '-DORTHANC_ENABLE_SSL=1',
4537
1de2fc0363cb sanity checks in CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4520
diff changeset
110 '-DORTHANC_ENABLE_ZLIB=1',
4305
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4304
diff changeset
111 '-DORTHANC_SANDBOXED=0',
4303
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
112 '-DORTHANC_SQLITE_STANDALONE=0',
4537
1de2fc0363cb sanity checks in CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4520
diff changeset
113 '-DORTHANC_SQLITE_VERSION=3027001',
1de2fc0363cb sanity checks in CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4520
diff changeset
114 '-I/usr/include/jsoncpp', # On Ubuntu 18.04
1de2fc0363cb sanity checks in CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4520
diff changeset
115 '-I/usr/include/lua5.3', # On Ubuntu 18.04
4303
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
116 ])
4277
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
4537
1de2fc0363cb sanity checks in CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4520
diff changeset
119 if len(tu.diagnostics) != 0:
1de2fc0363cb sanity checks in CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4520
diff changeset
120 for d in tu.diagnostics:
1de2fc0363cb sanity checks in CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4520
diff changeset
121 print(' ** %s' % d)
1de2fc0363cb sanity checks in CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4520
diff changeset
122 print('')
1de2fc0363cb sanity checks in CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4520
diff changeset
123 raise Exception('Error')
1de2fc0363cb sanity checks in CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4520
diff changeset
124
1de2fc0363cb sanity checks in CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4520
diff changeset
125
1de2fc0363cb sanity checks in CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4520
diff changeset
126
4279
ab4d015af660 moving inline methods to source files for ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4277
diff changeset
127 FILES = []
ab4d015af660 moving inline methods to source files for ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4277
diff changeset
128 COUNT = 0
4520
f5cb0c0ffbed added unit test OrthancFramework.SizeOf to dump sizeof all the public classes in the Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
129 ALL_TYPES = []
4277
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130
4303
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
131 def ReportProblem(message, fqn, cursor):
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
132 global FILES, COUNT
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
133 FILES.append(os.path.normpath(str(cursor.location.file)))
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
134 COUNT += 1
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
135
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
136 print('%s: %s::%s()' % (message, '::'.join(fqn), cursor.spelling))
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
137
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
138
4300
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4279
diff changeset
139 def ExploreClass(child, fqn):
4303
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
140 # Safety check
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
141 if (child.kind != clang.cindex.CursorKind.CLASS_DECL and
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
142 child.kind != clang.cindex.CursorKind.STRUCT_DECL):
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
143 raise Exception()
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
144
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
145 # Ignore forward declaration of classes
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
146 if not child.is_definition():
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
147 return
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
148
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
149
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
150 ##
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
151 ## Verify that the class is publicly exported (its visibility must
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
152 ## be "default")
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
153 ##
4300
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4279
diff changeset
154 visible = False
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4279
diff changeset
155
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4279
diff changeset
156 for i in child.get_children():
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4279
diff changeset
157 if (i.kind == clang.cindex.CursorKind.VISIBILITY_ATTR and
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4279
diff changeset
158 i.spelling == 'default'):
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4279
diff changeset
159 visible = True
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4279
diff changeset
160
4303
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
161 if not visible:
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
162 return
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
163
4520
f5cb0c0ffbed added unit test OrthancFramework.SizeOf to dump sizeof all the public classes in the Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
164 global ALL_TYPES
f5cb0c0ffbed added unit test OrthancFramework.SizeOf to dump sizeof all the public classes in the Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
165 ALL_TYPES.append('::'.join(fqn))
f5cb0c0ffbed added unit test OrthancFramework.SizeOf to dump sizeof all the public classes in the Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
166
4303
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
167
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
168 ##
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
169 ## Ignore pure abstract interfaces, by checking the following
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
170 ## criteria:
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
171 ## - It must be a C++ class (not a struct)
4310
2ae905070221 renaming pure interface JobOperationValue as IJobOperationValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4305
diff changeset
172 ## - It must start with "I"
4303
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
173 ## - All its methods must be pure virtual (abstract) and public
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
174 ## - Its destructor must be public, virtual, and must do nothing
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
175 ##
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
176
4310
2ae905070221 renaming pure interface JobOperationValue as IJobOperationValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4305
diff changeset
177 if (child.kind == clang.cindex.CursorKind.CLASS_DECL and
2ae905070221 renaming pure interface JobOperationValue as IJobOperationValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4305
diff changeset
178 child.spelling[0] == 'I' and
2ae905070221 renaming pure interface JobOperationValue as IJobOperationValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4305
diff changeset
179 child.spelling[1].isupper()):
4303
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
180 abstract = True
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
181 isPublic = False
4300
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4279
diff changeset
182
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4279
diff changeset
183 for i in child.get_children():
4303
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
184 if i.kind == clang.cindex.CursorKind.VISIBILITY_ATTR: # "default"
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
185 pass
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
186 elif i.kind == clang.cindex.CursorKind.CXX_ACCESS_SPEC_DECL:
4300
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4279
diff changeset
187 isPublic = (i.access_specifier == clang.cindex.AccessSpecifier.PUBLIC)
4303
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
188 elif i.kind == clang.cindex.CursorKind.CXX_BASE_SPECIFIER:
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
189 if i.spelling != 'boost::noncopyable':
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
190 abstract = False
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
191 elif isPublic:
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
192 if i.kind == clang.cindex.CursorKind.CXX_METHOD:
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
193 if i.is_pure_virtual_method():
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
194 pass # pure virtual is ok
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
195 elif i.is_static_method():
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
196 # static method without an inline implementation is ok
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
197 for j in i.get_children():
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
198 if j.kind == clang.cindex.CursorKind.COMPOUND_STMT:
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
199 abstract = False
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
200 else:
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
201 abstract = False
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
202 elif (i.kind == clang.cindex.CursorKind.DESTRUCTOR and
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
203 i.is_virtual_method()):
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
204 # The destructor must be virtual, and must do nothing
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
205 c = list(i.get_children())
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
206 if (len(c) != 1 or
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
207 c[0].kind != clang.cindex.CursorKind.COMPOUND_STMT or
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
208 len(list(c[0].get_children())) != 0):
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
209 abstract = False
4310
2ae905070221 renaming pure interface JobOperationValue as IJobOperationValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4305
diff changeset
210 elif i.kind == clang.cindex.CursorKind.CLASS_DECL:
4303
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
211 ExploreClass(i, fqn + [ i.spelling ])
4304
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4303
diff changeset
212 elif (i.kind == clang.cindex.CursorKind.TYPEDEF_DECL or # Allow "typedef"
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4303
diff changeset
213 i.kind == clang.cindex.CursorKind.ENUM_DECL): # Allow enums
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4303
diff changeset
214 pass
4303
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
215 else:
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
216 abstract = False
4300
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4279
diff changeset
217
4303
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
218 if abstract:
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
219 print('Detected a pure interface (this is fine): %s' % ('::'.join(fqn)))
4310
2ae905070221 renaming pure interface JobOperationValue as IJobOperationValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4305
diff changeset
220 else:
2ae905070221 renaming pure interface JobOperationValue as IJobOperationValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4305
diff changeset
221 ReportProblem('Not a pure interface', fqn, child)
4303
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
222
4310
2ae905070221 renaming pure interface JobOperationValue as IJobOperationValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4305
diff changeset
223 return
2ae905070221 renaming pure interface JobOperationValue as IJobOperationValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4305
diff changeset
224
4303
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
225
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
226 ##
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
227 ## We are facing a standard C++ class or struct
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
228 ##
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
229
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
230 isPublic = (child.kind == clang.cindex.CursorKind.STRUCT_DECL)
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
231
4520
f5cb0c0ffbed added unit test OrthancFramework.SizeOf to dump sizeof all the public classes in the Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
232 membersCount = 0
f5cb0c0ffbed added unit test OrthancFramework.SizeOf to dump sizeof all the public classes in the Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
233 membersSize = 0
f5cb0c0ffbed added unit test OrthancFramework.SizeOf to dump sizeof all the public classes in the Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
234
4303
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
235 for i in child.get_children():
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
236 if (i.kind == clang.cindex.CursorKind.VISIBILITY_ATTR or # "default"
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
237 i.kind == clang.cindex.CursorKind.CXX_BASE_SPECIFIER): # base class
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
238 pass
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
239
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
240 elif i.kind == clang.cindex.CursorKind.CXX_ACCESS_SPEC_DECL:
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
241 isPublic = (i.access_specifier == clang.cindex.AccessSpecifier.PUBLIC)
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
242
4310
2ae905070221 renaming pure interface JobOperationValue as IJobOperationValue
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4305
diff changeset
243 elif i.kind == clang.cindex.CursorKind.CLASS_DECL:
4303
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
244 # This is a subclass
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
245 if isPublic:
4300
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4279
diff changeset
246 ExploreClass(i, fqn + [ i.spelling ])
4303
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
247
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
248 elif (i.kind == clang.cindex.CursorKind.CXX_METHOD or
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
249 i.kind == clang.cindex.CursorKind.CONSTRUCTOR or
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
250 i.kind == clang.cindex.CursorKind.DESTRUCTOR):
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
251 if isPublic:
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
252 hasImplementation = False
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
253 for j in i.get_children():
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
254 if j.kind == clang.cindex.CursorKind.COMPOUND_STMT:
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
255 hasImplementation = True
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
256
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
257 if hasImplementation:
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
258 ReportProblem('Exported public method with an implementation', fqn, i)
4300
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4279
diff changeset
259
4303
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
260 elif i.kind == clang.cindex.CursorKind.VAR_DECL:
4520
f5cb0c0ffbed added unit test OrthancFramework.SizeOf to dump sizeof all the public classes in the Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
261 raise Exception('Unsupported: %s, %s' % (i.kind, i.location))
4303
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
262
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
263 elif i.kind == clang.cindex.CursorKind.FUNCTION_TEMPLATE:
4313
91554aecff9a removed a friend method for better abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4310
diff changeset
264 # An inline function template is OK, as it is not added to
91554aecff9a removed a friend method for better abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4310
diff changeset
265 # a shared library, but compiled by the client of the library
4303
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
266 if isPublic:
4313
91554aecff9a removed a friend method for better abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4310
diff changeset
267 print('Detected a template function (this is fine, but avoid it as much as possible): %s' % ('::'.join(fqn + [ i.spelling ])))
91554aecff9a removed a friend method for better abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4310
diff changeset
268 hasImplementation = False
91554aecff9a removed a friend method for better abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4310
diff changeset
269 for j in i.get_children():
91554aecff9a removed a friend method for better abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4310
diff changeset
270 if j.kind == clang.cindex.CursorKind.COMPOUND_STMT:
91554aecff9a removed a friend method for better abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4310
diff changeset
271 hasImplementation = True
4300
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4279
diff changeset
272
4313
91554aecff9a removed a friend method for better abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4310
diff changeset
273 if not hasImplementation:
91554aecff9a removed a friend method for better abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4310
diff changeset
274 ReportProblem('Exported template function without an inline implementation', fqn, i)
91554aecff9a removed a friend method for better abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4310
diff changeset
275
4303
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
276 elif (i.kind == clang.cindex.CursorKind.TYPEDEF_DECL or # Allow "typedef"
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
277 i.kind == clang.cindex.CursorKind.ENUM_DECL): # Allow enums
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
278 pass
4349
85237ae3a076 relax CheckOrthancFrameworkSymbols.py about one friend stream function
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4313
diff changeset
279
85237ae3a076 relax CheckOrthancFrameworkSymbols.py about one friend stream function
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4313
diff changeset
280 elif i.kind == clang.cindex.CursorKind.FRIEND_DECL:
85237ae3a076 relax CheckOrthancFrameworkSymbols.py about one friend stream function
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4313
diff changeset
281 children = list(i.get_children())
85237ae3a076 relax CheckOrthancFrameworkSymbols.py about one friend stream function
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4313
diff changeset
282 if (isPublic and
85237ae3a076 relax CheckOrthancFrameworkSymbols.py about one friend stream function
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4313
diff changeset
283 (len(children) != 1 or
85237ae3a076 relax CheckOrthancFrameworkSymbols.py about one friend stream function
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4313
diff changeset
284 not children[0].displayname in [
85237ae3a076 relax CheckOrthancFrameworkSymbols.py about one friend stream function
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4313
diff changeset
285 # This is supported for ABI compatibility with Orthanc <= 1.8.0
85237ae3a076 relax CheckOrthancFrameworkSymbols.py about one friend stream function
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4313
diff changeset
286 'operator<<(std::ostream &, const Orthanc::DicomTag &)',
85237ae3a076 relax CheckOrthancFrameworkSymbols.py about one friend stream function
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4313
diff changeset
287 ])):
85237ae3a076 relax CheckOrthancFrameworkSymbols.py about one friend stream function
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4313
diff changeset
288 raise Exception('Unsupported: %s, %s' % (i.kind, i.location))
4520
f5cb0c0ffbed added unit test OrthancFramework.SizeOf to dump sizeof all the public classes in the Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
289
f5cb0c0ffbed added unit test OrthancFramework.SizeOf to dump sizeof all the public classes in the Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
290 elif i.kind == clang.cindex.CursorKind.FIELD_DECL:
f5cb0c0ffbed added unit test OrthancFramework.SizeOf to dump sizeof all the public classes in the Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
291 # TODO
f5cb0c0ffbed added unit test OrthancFramework.SizeOf to dump sizeof all the public classes in the Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
292 if i.type.get_size() > 0:
f5cb0c0ffbed added unit test OrthancFramework.SizeOf to dump sizeof all the public classes in the Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
293 membersSize += i.type.get_size()
f5cb0c0ffbed added unit test OrthancFramework.SizeOf to dump sizeof all the public classes in the Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
294 membersCount += 1
4303
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
295
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
296 else:
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
297 if isPublic:
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
298 raise Exception('Unsupported: %s, %s' % (i.kind, i.location))
4300
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4279
diff changeset
299
4520
f5cb0c0ffbed added unit test OrthancFramework.SizeOf to dump sizeof all the public classes in the Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
300 #print('Size of %s => (%d,%d)' % ('::'.join(fqn), membersCount, membersSize))
f5cb0c0ffbed added unit test OrthancFramework.SizeOf to dump sizeof all the public classes in the Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
301
4300
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4279
diff changeset
302
4277
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
303 def ExploreNamespace(node, namespace):
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
304 for child in node.get_children():
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
305 fqn = namespace + [ child.spelling ]
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
306
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
307 if child.kind == clang.cindex.CursorKind.NAMESPACE:
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
308 ExploreNamespace(child, fqn)
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
309
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
310 elif (child.kind == clang.cindex.CursorKind.CLASS_DECL or
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
311 child.kind == clang.cindex.CursorKind.STRUCT_DECL):
4300
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4279
diff changeset
312 ExploreClass(child, fqn)
4277
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
313
4305
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4304
diff changeset
314 elif child.kind == clang.cindex.CursorKind.FUNCTION_DECL:
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4304
diff changeset
315 visible = False
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4304
diff changeset
316 hasImplementation = False
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4304
diff changeset
317 for i in child.get_children():
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4304
diff changeset
318 if (i.kind == clang.cindex.CursorKind.VISIBILITY_ATTR and
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4304
diff changeset
319 i.spelling == 'default'):
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4304
diff changeset
320 visible = True
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4304
diff changeset
321 elif i.kind == clang.cindex.CursorKind.COMPOUND_STMT:
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4304
diff changeset
322 hasImplementation = True
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4304
diff changeset
323
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4304
diff changeset
324 if visible and hasImplementation:
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4304
diff changeset
325 ReportProblem('Exported public function with an implementation', fqn, i)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4304
diff changeset
326
4303
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
327
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
328
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
329 print('')
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
330
4277
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
331 for node in tu.cursor.get_children():
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
332 if (node.kind == clang.cindex.CursorKind.NAMESPACE and
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
333 node.spelling == 'Orthanc'):
c5ca798b158a CheckOrthancFrameworkSymbols.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
334 ExploreNamespace(node, [ 'Orthanc' ])
4279
ab4d015af660 moving inline methods to source files for ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4277
diff changeset
335
ab4d015af660 moving inline methods to source files for ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4277
diff changeset
336
4520
f5cb0c0ffbed added unit test OrthancFramework.SizeOf to dump sizeof all the public classes in the Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
337 if args.target_cpp_size != '':
f5cb0c0ffbed added unit test OrthancFramework.SizeOf to dump sizeof all the public classes in the Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
338 with open(args.target_cpp_size, 'w') as f:
f5cb0c0ffbed added unit test OrthancFramework.SizeOf to dump sizeof all the public classes in the Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
339 for t in sorted(ALL_TYPES):
f5cb0c0ffbed added unit test OrthancFramework.SizeOf to dump sizeof all the public classes in the Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
340 f.write(' printf("sizeof(::%s) == %%d\\n", static_cast<int>(sizeof(::%s)));\n' % (t, t))
f5cb0c0ffbed added unit test OrthancFramework.SizeOf to dump sizeof all the public classes in the Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
341
f5cb0c0ffbed added unit test OrthancFramework.SizeOf to dump sizeof all the public classes in the Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
342
4279
ab4d015af660 moving inline methods to source files for ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4277
diff changeset
343 print('\nTotal of possibly problematic methods: %d' % COUNT)
ab4d015af660 moving inline methods to source files for ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4277
diff changeset
344
4303
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
345 print('\nProblematic files:\n')
4279
ab4d015af660 moving inline methods to source files for ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4277
diff changeset
346 for i in sorted(list(set(FILES))):
ab4d015af660 moving inline methods to source files for ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4277
diff changeset
347 print(i)
4303
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
348
44b53a2c0a13 improving detection of ABI compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4300
diff changeset
349 print('')