Skip to content

Commit 32a7f4e

Browse files
committed
Build: add builder for Oddie module.
1 parent 56fd085 commit 32a7f4e

File tree

2 files changed

+44
-40
lines changed

2 files changed

+44
-40
lines changed

dss_build.py

Lines changed: 40 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ def process_header(src, extern_py=False, implement_py=False, prefix=''):
99

1010
src = src.replace('dss_long_bool', 'int32_t')
1111

12-
src = re.sub('^.*namespace dss.*$', '', src, flags=re.MULTILINE)
12+
src = re.sub('^.*namespace .*$', '', src, flags=re.MULTILINE)
1313
if not implement_py:
1414
src = re.sub('^extern .*', '', src, flags=re.MULTILINE)
1515
src = re.sub('^.*extern .*$', '', src, flags=re.MULTILINE)
1616
src = re.sub('^#.*', '', src, flags=re.MULTILINE)
17-
src = re.sub('DSS_CAPI_.*DLL', '', src)
17+
src = re.sub('(DSS_CAPI_.*DLL)|(ALTDSS_.*_DLL)', '', src)
1818
src = re.sub(
1919
r'DSS_MODEL_CALLBACK\(([^,]+), ([^\)]+)\)',
2020
r'\1 ({call_convention}*\2)'.format(call_convention=call_convention),
@@ -75,51 +75,53 @@ def process_header(src, extern_py=False, implement_py=False, prefix=''):
7575

7676
src_path = os.environ.get('SRC_DIR', '')
7777
DSS_CAPI_PATH = os.environ.get('DSS_CAPI_PATH', os.path.join(src_path, '..', 'dss_capi'))
78-
79-
for version in ('', 'd'):
78+
79+
for version in ('dss_capi', 'dss_capid', 'altdss_oddie_capi'):
8080
ffi_builder_dss = FFI()
8181
debug = 'd' if version.endswith('d') else ''
8282

83-
main_header_fn = os.path.join(DSS_CAPI_PATH, 'include', 'dss_capi.h')
84-
dss_capi_ctx_path = os.path.join(DSS_CAPI_PATH, 'include', 'dss_capi_ctx.h')
85-
headers = [main_header_fn, dss_capi_ctx_path]
86-
# Temporary fixes for DSS C-API headers
87-
for fn in headers:
88-
with open(fn, 'r') as f:
89-
patched = (f.read().
90-
replace(' ctx_Fuses_Reset(void* ctx, int32_t Value)', ' ctx_Fuses_Reset(void* ctx)').
91-
replace(' Fuses_Reset(int32_t Value)', ' Fuses_Reset(void)')
92-
)
93-
with open(fn, 'w') as f:
94-
f.write(patched)
83+
if 'oddie' not in version:
84+
main_header_fn = os.path.join(DSS_CAPI_PATH, 'include', 'dss_capi.h')
85+
dss_capi_ctx_path = os.path.join(DSS_CAPI_PATH, 'include', 'dss_capi_ctx.h')
86+
# headers = [main_header_fn, dss_capi_ctx_path]
87+
else:
88+
main_header_fn = os.path.join(DSS_CAPI_PATH, 'include', 'altdss', 'altdss_oddie.h')
89+
dss_capi_ctx_path = None
90+
# headers = [main_header_fn]
9591

9692
with open(main_header_fn, 'r') as f:
9793
cffi_header_dss = process_header(f.read())
98-
99-
if os.path.exists(dss_capi_ctx_path):
100-
with open(dss_capi_ctx_path, 'r') as f:
101-
cffi_header_dss += process_header(f.read())
102-
103-
with open('cffi/dss_capi_custom.h', 'r') as f:
104-
extra_header_dss = f.read()
105-
106-
cffi_header_dss += extra_header_dss
107-
108-
with open('cffi/dss_capi_custom.c', 'r') as f:
94+
95+
if 'oddie' not in version:
10996
if os.path.exists(dss_capi_ctx_path):
110-
extra_source_dss = '#include <dss_capi_ctx.h>\n'
111-
extra_source_dss += f.read()
112-
else:
113-
extra_source_dss = f.read()
114-
97+
with open(dss_capi_ctx_path, 'r') as f:
98+
cffi_header_dss += process_header(f.read())
99+
100+
with open('cffi/dss_capi_custom.h', 'r') as f:
101+
extra_header_dss = f.read()
102+
103+
cffi_header_dss += extra_header_dss
104+
105+
with open('cffi/dss_capi_custom.c', 'r') as f:
106+
if os.path.exists(dss_capi_ctx_path):
107+
extra_source_dss = '#include <dss_capi_ctx.h>\n'
108+
extra_source_dss += f.read()
109+
else:
110+
extra_source_dss = f.read()
111+
else:
112+
extra_source_dss = '#include <altdss_oddie.h>\n'
113+
115114
ffi_builder_dss.cdef(cffi_header_dss)
116115

117-
ffi_builder_dss.set_source("_dss_capi{}".format(debug), extra_source_dss,
118-
libraries=["dss_capi{}".format(debug)],
116+
ffi_builder_dss.set_source(f"_{version}", extra_source_dss,
117+
libraries=[version],
119118
library_dirs=[
120119
os.path.join(DSS_CAPI_PATH, 'lib/{}'.format(PLATFORM_FOLDER))
121120
],
122-
include_dirs=[os.path.join(DSS_CAPI_PATH, 'include')],
121+
include_dirs=[
122+
os.path.join(DSS_CAPI_PATH, 'include'),
123+
os.path.join(DSS_CAPI_PATH, 'include/altdss'),
124+
],
123125
source_extension='.c',
124126
**extra
125127
)
@@ -165,8 +167,9 @@ def process_header(src, extern_py=False, implement_py=False, prefix=''):
165167

166168
# Is there a better way to do this? Unfortunately setup(cffi_modules=...)
167169
# needs a list of strings and cannot handle objects directly
168-
ffi_builder_ = ffi_builders['']
169-
ffi_builder_d = ffi_builders['d']
170+
ffi_builder_ = ffi_builders['dss_capi']
171+
ffi_builder_d = ffi_builders['dss_capid']
172+
ffi_builder_odd = ffi_builders['altdss_oddie_capi']
170173
ffi_builder_GenUserModel = ffi_builders['GenUserModel']
171174
#ffi_builder_PVSystemUserModel = ffi_builders['PVSystemUserModel']
172175
#ffi_builder_StoreDynaModel = ffi_builders['StoreDynaModel']

setup.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,9 @@
5555
shutil.copy(fn, dll_path_out)
5656

5757
# Copy libs (easier to build custom extensions with a default DSS Python installation)
58-
for fn in glob.glob(os.path.join(base_dll_path_in, '*.lib')) + glob.glob(os.path.join(base_dll_path_in, '*.a')):
59-
shutil.copy(fn, dll_path_out)
58+
for pattern in ('*.lib', '*.a', '*.pdb'):
59+
for fn in glob.glob(os.path.join(base_dll_path_in, pattern)):
60+
shutil.copy(fn, dll_path_out)
6061

6162
# Copy headers
6263
if os.path.exists(include_path_out):
@@ -94,7 +95,7 @@
9495
license="BSD",
9596
packages=['dss_python_backend'],
9697
setup_requires=["cffi>=1.11.2"],
97-
cffi_modules=["dss_build.py:ffi_builder_{}".format(version) for version in ('', 'd')] +
98+
cffi_modules=["dss_build.py:ffi_builder_{}".format(version) for version in ('', 'd', 'odd')] +
9899
[
99100
'dss_build.py:ffi_builder_GenUserModel',
100101
#'dss_build.py:ffi_builder_PVSystemUserModel',

0 commit comments

Comments
 (0)