forked from xmlsec/python-xmlsec
-
Notifications
You must be signed in to change notification settings - Fork 0
/
xmlsec_setupinfo.py
258 lines (195 loc) · 6.65 KB
/
xmlsec_setupinfo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
from __future__ import print_function
import glob
import os
import pkg_resources
import sys
from distutils.errors import DistutilsOptionError
WIN32 = sys.platform.lower().startswith('win')
__MODULE_NAME = "xmlsec"
__MODULE_VERSION = None
__MODULE_DESCRIPTION = "Python bindings for the XML Security Library"
__MODULE_REQUIREMENTS = None
__XMLSEC_CONFIG = None
def name():
return __MODULE_NAME
def version():
global __MODULE_VERSION
if __MODULE_VERSION is None:
with open(os.path.join(get_base_dir(), 'version.txt')) as f:
__MODULE_VERSION = f.read().strip()
return __MODULE_VERSION
def description():
return __MODULE_DESCRIPTION
def sources():
return sorted(glob.glob(os.path.join(get_base_dir(), "src", "*.c")))
def define_macros():
macros = [
("MODULE_NAME", __MODULE_NAME),
("MODULE_VERSION", version()),
]
if OPTION_ENABLE_DEBUG:
macros.append(("PYXMLSEC_ENABLE_DEBUG", "1"))
macros.extend(xmlsec_config()['define_macros'])
return macros
def cflags():
options = []
if WIN32:
options.append("/Zi")
else:
options.append("-g")
options.append("-std=c99")
options.append("-fno-strict-aliasing")
options.append("-Wno-error=declaration-after-statement")
options.append("-Werror=implicit-function-declaration")
if OPTION_ENABLE_DEBUG:
options.append("-Wall")
options.append("-O0")
else:
options.append("-Os")
return options
def include_dirs():
import lxml
dirs = xmlsec_config()['include_dirs']
dirs.extend(lxml.get_include())
return dirs
def libraries():
return xmlsec_config()['libraries']
def library_dirs():
return xmlsec_config()['library_dirs']
def dev_status():
_version = version()
if 'a' in _version:
return 'Development Status :: 3 - Alpha'
elif 'b' in _version or 'c' in _version:
return 'Development Status :: 4 - Beta'
else:
return 'Development Status :: 5 - Production/Stable'
def requirements():
global __MODULE_REQUIREMENTS
if __MODULE_REQUIREMENTS is None:
with open(os.path.join(get_base_dir(), "requirements.txt")) as f:
__MODULE_REQUIREMENTS = [str(req) for req in pkg_resources.parse_requirements(f)]
return __MODULE_REQUIREMENTS
def xmlsec_config():
global __XMLSEC_CONFIG
if __XMLSEC_CONFIG is None:
__XMLSEC_CONFIG = load_xmlsec1_config()
return __XMLSEC_CONFIG
def load_xmlsec1_config():
config = None
if WIN32:
import xmlsec_extra
config = {
'define_macros': [
('XMLSEC_CRYPTO', '\\"openssl\\"'),
('__XMLSEC_FUNCTION__', '__FUNCTION__'),
('XMLSEC_NO_GOST', '1'),
('XMLSEC_NO_XKMS', '1'),
('XMLSEC_NO_CRYPTO_DYNAMIC_LOADING', '1'),
('XMLSEC_CRYPTO_OPENSSL', '1'),
('UNICODE', '1'),
('_UNICODE', '1'),
('LIBXML_ICONV_ENABLED', 1),
('LIBXML_STATIC', '1'),
('LIBXSLT_STATIC', '1'),
('XMLSEC_STATIC', '1'),
('inline', '__inline'),
],
'libraries': [
'libxmlsec_a',
'libxmlsec-openssl_a',
'libeay32',
'iconv_a',
'libxslt_a',
'libexslt_a',
'libxml2_a',
'zlib',
'WS2_32',
'Advapi32',
'User32',
'Gdi32',
'Crypt32',
],
'include_dirs': [],
'library_dirs': [],
}
xmlsec_extra.get_prebuilt_libs(
OPTION_DOWNLOAD_DIR, config['include_dirs'], config['library_dirs']
)
else:
import pkgconfig
try:
config = pkgconfig.parse('xmlsec1')
except EnvironmentError:
pass
if config is None or not config.get('libraries'):
fatal_xmlsec1_error()
# make sure that all options are list
for x in ('libraries', 'include_dirs', 'library_dirs'):
config[x] = list(config.get(x) or [])
# fix macros, ensure that macros is list
macros = list(config.get('define_macros', []))
for i, v in enumerate(macros):
if v[0] == 'XMLSEC_CRYPTO' and not (v[1].startswith('"') and v[1].endswith('"')):
macros[i] = ('XMLSEC_CRYPTO', '"{0}"'.format(v[1]))
break
config['define_macros'] = macros
return config
def fatal_xmlsec1_error():
print('*********************************************************************************')
print('Could not find xmlsec1 config. Are libxmlsec1-dev and pkg-config installed?')
if sys.platform in ('darwin',):
print('Perhaps try: xcode-select --install')
print('*********************************************************************************')
sys.exit(1)
def get_base_dir():
return os.path.abspath(os.path.dirname(sys.argv[0]))
if sys.version_info[0] >= 3:
_system_encoding = sys.getdefaultencoding()
if _system_encoding is None:
_system_encoding = "iso-8859-1"
def decode_input(data):
if isinstance(data, str):
return data
return data.decode(_system_encoding)
else:
def decode_input(data):
return data
def env_var(n):
value = os.getenv(n)
if value:
value = decode_input(value)
if sys.platform == 'win32' and ';' in value:
return value.split(';')
else:
return value.split()
else:
return []
def env_var_name(n):
return "PYXMLSEC_" + n.upper().replace('-', '_')
# Option handling:
def has_option(n):
try:
sys.argv.remove('--%s' % n)
return True
except ValueError:
pass
# allow passing all cmd line options also as environment variables
env_val = os.getenv(env_var_name(n), 'false').lower()
return env_val in ("true", "1")
def option_value(n, default=None):
for index, option in enumerate(sys.argv):
if option == '--' + n:
if index+1 >= len(sys.argv):
raise DistutilsOptionError(
'The option %s requires a value' % option)
value = sys.argv[index+1]
sys.argv[index:index+2] = []
return value
if option.startswith('--' + n + '='):
value = option[len(n)+3:]
sys.argv[index:index+1] = []
return value
return os.getenv(env_var_name(n), default)
OPTION_ENABLE_DEBUG = has_option('enable-debug')
OPTION_DOWNLOAD_DIR = option_value('download-dir', 'build/extra')