Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove config.pxi and use compile_time_env instead #484

Merged
merged 3 commits into from
Jul 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ script:
fi
- pip3 install .
- urh --version
- urh autoclose
#- urh autoclose

after_success:
- |
Expand Down
15 changes: 4 additions & 11 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def get_package_data():
for plugin in PLUGINS:
package_data["urh.plugins." + plugin] = ['*.ui', "*.txt"]

package_data["urh.dev.native.lib"] = ["*.pyx", "*.pxd", "*.pxi"]
package_data["urh.dev.native.lib"] = ["*.pyx", "*.pxd"]

if IS_RELEASE and sys.platform == "win32":
package_data["urh.dev.native.lib.shared"] = ["*.dll", "*.txt"]
Expand All @@ -94,21 +94,14 @@ def get_extensions():
language="c++") for f in filenames]

ExtensionHelper.USE_RELATIVE_PATHS = True
extensions += ExtensionHelper.get_device_extensions()
device_extensions, device_extras = ExtensionHelper.get_device_extensions_and_extras()
extensions += device_extensions

if NO_NUMPY_WARNINGS_FLAG:
for extension in extensions:
extension.extra_compile_args.append(NO_NUMPY_WARNINGS_FLAG)

try:
extensions = cythonize(extensions, compiler_directives=COMPILER_DIRECTIVES, quiet=True)
except:
# Copy config.pxi in current directory so cython distutils can find it
# error occurs only sometimes, see https://github.com/jopohl/urh/issues/481
shutil.copy(ExtensionHelper.CONFIG_PXI_PATH, os.path.realpath(os.path.dirname(__file__)))
extensions = cythonize(extensions, compiler_directives=COMPILER_DIRECTIVES, quiet=True)
os.remove(os.path.realpath(os.path.join(os.path.dirname(__file__), "config.pxi")))

extensions = cythonize(extensions, compiler_directives=COMPILER_DIRECTIVES, quiet=True, compile_time_env=device_extras)
return extensions


Expand Down
2 changes: 1 addition & 1 deletion src/urh/controller/dialogs/OptionsDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ def on_gnuradio_install_dir_edited(self):
def on_btn_rebuild_native_clicked(self):
library_dirs = None if not self.ui.lineEditLibDirs.text() \
else list(map(str.strip, self.ui.lineEditLibDirs.text().split(",")))
extensions = ExtensionHelper.get_device_extensions(library_dirs=library_dirs)
extensions, _ = ExtensionHelper.get_device_extensions_and_extras(library_dirs=library_dirs)

self.ui.labelRebuildNativeStatus.setText(self.tr("Rebuilding device extensions..."))
QApplication.instance().processEvents()
Expand Down
41 changes: 16 additions & 25 deletions src/urh/dev/native/ExtensionHelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

from setuptools import Extension

CONFIG_PXI_PATH = os.path.join(os.path.dirname(__file__), "lib", "config.pxi")
USE_RELATIVE_PATHS = False

DEVICES = {
Expand Down Expand Up @@ -53,20 +52,13 @@ def compiler_has_function(compiler, function_name, libraries, library_dirs, incl
devnull.close()
shutil.rmtree(tmp_dir)


def generate_config_pxi(device_extras: list):
with open(CONFIG_PXI_PATH, "w") as f:
for extra, enabled in sorted(device_extras):
f.write("DEF {} = {}\n".format(extra, int(enabled)))


def get_device_extensions(library_dirs=None):
def get_device_extensions_and_extras(library_dirs=None):
library_dirs = [] if library_dirs is None else library_dirs

cur_dir = os.path.dirname(os.path.realpath(__file__))
include_dirs = []

device_extras = []
device_extras = dict()

if os.path.isdir(os.path.join(cur_dir, "lib/shared")):
# Device libs are packaged, so we are in release mode
Expand All @@ -75,11 +67,10 @@ def get_device_extensions(library_dirs=None):
lib_dir = os.path.realpath(os.path.join(cur_dir, "lib/shared"))
for dev_name, params in DEVICES.items():
# Since drivers are bundled we can enforce the extras
device_extras.extend([(extra, 1) for extra in params.get("extras", dict())])
device_extras.update({extra: 1 for extra in params.get("extras", dict())})
result.append(get_device_extension(dev_name, [params["lib"]], [lib_dir], include_dirs))

generate_config_pxi(device_extras)
return result
return result, device_extras

if sys.platform == "darwin":
# On Mac OS X clang is by default not smart enough to search in the lib dir
Expand Down Expand Up @@ -116,37 +107,36 @@ def get_device_extensions(library_dirs=None):
continue
if build_device_extensions[dev_name] == 1:
print("Enforcing native {0} support".format(dev_name))
device_extras.extend(__get_device_extras(compiler, dev_name, [params["lib"]], library_dirs, include_dirs))
device_extras.update(get_device_extras(compiler, dev_name, [params["lib"]], library_dirs, include_dirs))
extension = get_device_extension(dev_name, [params["lib"]], library_dirs, include_dirs)
result.append(extension)
continue

if compiler_has_function(compiler, params["test_function"], (params["lib"],), library_dirs, include_dirs):
print("Found {0} lib. Will compile with native {1} support".format(params["lib"], dev_name))
device_extras.extend(__get_device_extras(compiler, dev_name, [params["lib"]], library_dirs, include_dirs))
device_extras.update(get_device_extras(compiler, dev_name, [params["lib"]], library_dirs, include_dirs))
extension = get_device_extension(dev_name, [params["lib"]], library_dirs, include_dirs)
result.append(extension)
else:
print("Skipping native support for {1}".format(params["lib"], dev_name))

generate_config_pxi(device_extras)
return result
return result, device_extras


def __get_device_extras(compiler, dev_name, libraries, library_dirs, include_dirs):
def get_device_extras(compiler, dev_name, libraries, library_dirs, include_dirs):
try:
extras = DEVICES[dev_name]["extras"]
except KeyError:
extras = dict()

result = []
result = dict()

for extra, func_name in extras.items():
if compiler_has_function(compiler, func_name, libraries, library_dirs, include_dirs):
result.append((extra, 1))
result[extra] = 1
else:
print("Skipping {} as installed driver does not support it".format(extra))
result.append((extra, 0))
result[extra] = 0

return result

Expand Down Expand Up @@ -186,12 +176,12 @@ def perform_health_check() -> str:
from setuptools import setup

if "-L" in sys.argv:
library_dirs = sys.argv[sys.argv.index("-L") + 1].split(":")
library_directories = sys.argv[sys.argv.index("-L") + 1].split(":")
else:
library_dirs = None
library_directories = None

cur_dir = os.path.dirname(os.path.realpath(__file__))
os.chdir("..")
os.chdir(os.path.join(cur_dir, "..", "..", ".."))

try:
from Cython.Build import cythonize
Expand All @@ -201,7 +191,8 @@ def perform_health_check() -> str:
file=sys.stderr)
sys.exit(1)

dev_extensions, dev_extras = get_device_extensions_and_extras(library_dirs=library_directories)
setup(
name="urh",
ext_modules=cythonize(get_device_extensions(library_dirs=library_dirs), force=True),
ext_modules=cythonize(dev_extensions, force=True, compile_time_env=dev_extras),
)
2 changes: 0 additions & 2 deletions src/urh/dev/native/lib/chackrf.pxd
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
include "config.pxi"

cdef extern from "libhackrf/hackrf.h":
enum hackrf_error:
HACKRF_SUCCESS = 0
Expand Down
2 changes: 0 additions & 2 deletions src/urh/dev/native/lib/config.pxi

This file was deleted.

2 changes: 0 additions & 2 deletions src/urh/dev/native/lib/crtlsdr.pxd
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
include "config.pxi"

cdef extern from "rtl-sdr.h":
ctypedef struct rtlsdr_dev_t:
pass
Expand Down
2 changes: 0 additions & 2 deletions src/urh/dev/native/lib/hackrf.pyx
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
include "config.pxi"

cimport urh.dev.native.lib.chackrf as chackrf
from libc.stdlib cimport malloc
import time
Expand Down
3 changes: 0 additions & 3 deletions src/urh/dev/native/lib/rtlsdr.pyx
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# cython wrapper for RTL-SDR (https://github.com/pinkavaj/rtl-sdr)
include "config.pxi"

cimport urh.dev.native.lib.crtlsdr as crtlsdr
from libc.stdlib cimport malloc, free

Expand Down