-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathsetup.py
More file actions
245 lines (210 loc) · 8.66 KB
/
setup.py
File metadata and controls
245 lines (210 loc) · 8.66 KB
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
import os
import sys
import subprocess
from setuptools import setup, Extension
from packaging.version import Version
script_path = os.path.dirname(os.path.abspath(__file__))
# dependencies
EFL_MIN_VER = '1.28.0'
# === pkg-config helper ===
def cmd_output(cmd):
p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
retcode = p.wait()
if retcode != 0:
print(f'WARNING: An error occurred while running "{cmd}" (code {retcode})')
stderr_content = p.stderr.read().decode('utf-8').strip() if p.stderr else None
if stderr_content:
print(stderr_content)
return ''
return p.stdout.read().decode('utf-8').strip() if p.stdout else ''
def pkg_config(name, require, min_vers=None):
ver = None
try:
print(f'Checking for {name}: ', end='')
ver = cmd_output(f'pkg-config --modversion {require}')
if not ver:
raise SystemExit(f'Cannot find {name} with pkg-config.')
if min_vers is not None:
assert Version(ver) >= Version(min_vers)
print(f'OK, found {ver}')
cflags = cmd_output(f'pkg-config --cflags {require}').split()
libs = cmd_output(f'pkg-config --libs {require}').split()
return cflags, libs
except (OSError, subprocess.CalledProcessError):
raise SystemExit(f'Did not find {name} with pkg-config.')
except AssertionError:
raise SystemExit(f'{name} version mismatch. Found: {ver} Needed {min_vers}')
# use cython (git) or pre-generated C files (dist tarballs)
USE_CYTHON = os.path.exists(os.path.join(script_path, 'src/efl/eo.pyx'))
MODULES_EXT = 'pyx' if USE_CYTHON else 'c'
ext_modules = []
py_modules = []
packages = ['efl']
common_cflags = [
'-fno-var-tracking-assignments', # seems to lower the mem used during build
'-Wno-misleading-indentation', # not needed (we don't indent the C code)
'-Wno-deprecated-declarations', # we bind deprecated functions
'-Wno-unused-variable', # eo_instance_from_object() is unused
'-Wno-format-security', # some cc don't like the way cython use EINA_LOG macros
# '-Werror', '-Wfatal-errors' # use this to stop build on first warnings
]
# remove clang unknown flags
if os.getenv('CC') == 'clang':
common_cflags.remove('-fno-var-tracking-assignments')
# force default visibility. See phab T504
if os.getenv('CFLAGS') is not None and '-fvisibility=' in os.environ['CFLAGS']:
os.environ['CFLAGS'] += ' -fvisibility=default'
if {'build', 'build_ext', 'install', 'bdist', 'bdist_wheel', 'sdist'} & set(sys.argv):
# configure cython
if USE_CYTHON:
try:
import Cython
import Cython.Compiler.Options
except ImportError:
raise SystemExit('Cython not found!')
print(f'Using Cython {Cython.__version__}')
# Stop compilation on first error
Cython.Compiler.Options.fast_fail = True
# Generates HTML files with annotated source
Cython.Compiler.Options.annotate = False
# Set to False to disable docstrings
Cython.Compiler.Options.docstrings = True
else:
print('Cython not needed, using pre-generated C files\n')
# === Eina ===
eina_cflags, eina_libs = pkg_config('Eina', 'eina', EFL_MIN_VER)
# === Eo ===
eo_cflags, eo_libs = pkg_config('Eo', 'eo', EFL_MIN_VER)
ext_modules.append(Extension(
'efl.eo', ['src/efl/eo.' + MODULES_EXT],
extra_compile_args=eo_cflags + common_cflags,
extra_link_args=eo_libs
))
# === Utilities ===
ext_modules.append(Extension(
'efl.utils.deprecated', ['src/efl/utils/deprecated.' + MODULES_EXT],
extra_compile_args=eina_cflags + common_cflags,
extra_link_args=eina_libs
))
ext_modules.append(Extension(
'efl.utils.conversions', ['src/efl/utils/conversions.' + MODULES_EXT],
extra_compile_args=eo_cflags + common_cflags,
extra_link_args=eo_libs + eina_libs
))
ext_modules.append(Extension(
'efl.utils.logger', ['src/efl/utils/logger.' + MODULES_EXT],
extra_compile_args=eina_cflags + common_cflags,
extra_link_args=eina_libs
))
py_modules.append('efl.utils.setup')
packages.append('efl.utils')
# === Evas ===
evas_cflags, evas_libs = pkg_config('Evas', 'evas', EFL_MIN_VER)
ext_modules.append(Extension(
'efl.evas', ['src/efl/evas.' + MODULES_EXT],
extra_compile_args=evas_cflags + common_cflags,
extra_link_args=evas_libs
))
# === Ecore + EcoreFile ===
ecore_cflags, ecore_libs = pkg_config('Ecore', 'ecore', EFL_MIN_VER)
ecore_file_cflags, ecore_file_libs = pkg_config('EcoreFile', 'ecore-file', EFL_MIN_VER)
ext_modules.append(Extension(
'efl.ecore', ['src/efl/ecore.' + MODULES_EXT],
extra_compile_args=list(set(ecore_cflags + ecore_file_cflags + common_cflags)),
extra_link_args=ecore_libs + ecore_file_libs
))
# === Ecore Input ===
ecore_input_cflags, ecore_input_libs = pkg_config('EcoreInput', 'ecore-input', EFL_MIN_VER)
ext_modules.append(Extension(
'efl.ecore_input', ['src/efl/ecore_input.' + MODULES_EXT],
extra_compile_args=ecore_input_cflags + common_cflags,
extra_link_args=ecore_input_libs
))
# === Ecore Con ===
ecore_con_cflags, ecore_con_libs = pkg_config('EcoreCon', 'ecore-con', EFL_MIN_VER)
ext_modules.append(Extension(
'efl.ecore_con', ['src/efl/ecore_con.' + MODULES_EXT],
extra_compile_args=ecore_con_cflags + ecore_file_cflags + common_cflags,
extra_link_args=ecore_con_libs
))
# === Ecore X ===
try:
ecore_x_cflags, ecore_x_libs = pkg_config('EcoreX', 'ecore-x', EFL_MIN_VER)
except SystemExit:
print('Not found, will not be built')
else:
ext_modules.append(Extension(
'efl.ecore_x', ['src/efl/ecore_x.' + MODULES_EXT],
extra_compile_args=ecore_x_cflags + common_cflags,
extra_link_args=ecore_x_libs
))
# === Ethumb ===
ethumb_cflags, ethumb_libs = pkg_config('Ethumb', 'ethumb', EFL_MIN_VER)
ext_modules.append(Extension(
'efl.ethumb', ['src/efl/ethumb.' + MODULES_EXT],
extra_compile_args=ethumb_cflags + common_cflags,
extra_link_args=ethumb_libs
))
# === Ethumb Client ===
ethumb_cl_cflags, ethumb_cl_libs = pkg_config('Ethumb_Client', 'ethumb_client', EFL_MIN_VER)
ext_modules.append(Extension(
'efl.ethumb_client', ['src/efl/ethumb_client.' + MODULES_EXT],
extra_compile_args=ethumb_cl_cflags + common_cflags,
extra_link_args=ethumb_cl_libs
))
# === Edje ===
edje_cflags, edje_libs = pkg_config('Edje', 'edje', EFL_MIN_VER)
ext_modules.append(Extension(
'efl.edje', ['src/efl/edje.' + MODULES_EXT],
extra_compile_args=edje_cflags + common_cflags,
extra_link_args=edje_libs
))
# === Edje_Edit ===
ext_modules.append(Extension(
'efl.edje_edit', ['src/efl/edje_edit.' + MODULES_EXT],
define_macros=[('EDJE_EDIT_IS_UNSTABLE_AND_I_KNOW_ABOUT_IT', None)],
extra_compile_args=edje_cflags + common_cflags,
extra_link_args=edje_libs
))
# === Emotion ===
emotion_cflags, emotion_libs = pkg_config('Emotion', 'emotion', EFL_MIN_VER)
ext_modules.append(Extension(
'efl.emotion', ['src/efl/emotion.' + MODULES_EXT],
extra_compile_args=emotion_cflags + common_cflags,
extra_link_args=emotion_libs
))
# === dbus mainloop integration ===
dbus_cflags, dbus_libs = pkg_config('DBus', 'dbus-python', '0.83.0')
ext_modules.append(Extension(
'efl.dbus_mainloop',
sources=['src/efl/dbus_mainloop.' + MODULES_EXT, 'src/efl/e_dbus.c'],
depends=['src/efl/e_dbus.h'],
extra_compile_args=dbus_cflags + ecore_cflags + common_cflags,
extra_link_args=dbus_libs + ecore_libs
))
# === Elementary ===
elm_cflags, elm_libs = pkg_config('Elementary', 'elementary', EFL_MIN_VER)
ext_modules.append(Extension(
'efl.elementary.__init__', ['src/efl/elementary/__init__.' + MODULES_EXT],
extra_compile_args=elm_cflags + common_cflags,
extra_link_args=elm_libs
))
packages.append('efl.elementary')
# Cythonize all ext_modules
if USE_CYTHON:
from Cython.Build import cythonize
ext_modules = cythonize(
ext_modules,
include_path=['src/include'],
compiler_directives={
# 'c_string_type': 'unicode',
# 'c_string_encoding': 'utf-8',
'embedsignature': True,
'binding': True,
}
)
dist = setup(
packages=packages,
ext_modules=ext_modules,
py_modules=py_modules,
)