Python: Flags cleanup
Jeffrey Pfau jeffrey@endrift.com
Fri, 28 Oct 2016 15:39:43 -0700
4 files changed,
40 insertions(+),
40 deletions(-)
M
src/platform/python/CMakeLists.txt
→
src/platform/python/CMakeLists.txt
@@ -1,30 +1,11 @@
find_program(PYTHON python) -set(PY_INCLUDE_DIRS -I${CMAKE_SOURCE_DIR}/src) -get_property(INCLUDE_DIRECTORIES DIRECTORY ${CMAKE_SOURCE_DIR} PROPERTY INCLUDE_DIRECTORIES) -get_property(COMPILE_DEFINITIONS DIRECTORY ${CMAKE_SOURCE_DIR} PROPERTY COMPILE_DEFINITIONS) -foreach(INCLUDE_DIR IN LISTS INCLUDE_DIRECTORIES) - list(APPEND PY_INCLUDE_DIRS -I${INCLUDE_DIR}) -endforeach() -foreach(COMPILE_DEF IN LISTS COMPILE_DEFINITIONS FEATURE_DEFINES) - list(APPEND PY_COMPILE_DEFS -D${COMPILE_DEF}) -endforeach() - configure_file(${CMAKE_CURRENT_SOURCE_DIR}/setup.py.in ${CMAKE_CURRENT_BINARY_DIR}/setup.py) -add_custom_command(OUTPUT _builder.h - COMMAND ${CMAKE_C_COMPILER} ${PY_COMPILE_DEFS} ${PY_INCLUDE_DIRS} -fno-inline -E -P -c ${CMAKE_CURRENT_SOURCE_DIR}/_builder.h -o _builder.h - DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/_builder.h) -add_custom_target(_builder.h ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/_builder.h) - -add_custom_target(${BINARY_NAME}-pylib COMMAND ${PYTHON} ${CMAKE_CURRENT_SOURCE_DIR}/_builder.py ${PY_COMPILE_DEFS} ${PY_INCLUDE_DIRS} - DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/_builder.py - DEPENDS _builder.h) - -add_custom_command(OUTPUT ${BINARY_NAME}/__init__.py - COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/${BINARY_NAME} ${CMAKE_CURRENT_BINARY_DIR}/${BINARY_NAME} - COMMAND ${PYTHON} ${CMAKE_CURRENT_BINARY_DIR}/setup.py build +add_custom_command(OUTPUT build/lib/${BINARY_NAME}/__init__.py + COMMAND BINDIR=${CMAKE_CURRENT_BINARY_DIR}/.. ${PYTHON} ${CMAKE_CURRENT_BINARY_DIR}/setup.py build --build-base ${CMAKE_CURRENT_BINARY_DIR} + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/setup.py - DEPENDS ${BINARY_NAME}-pylib) + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/_builder.py) -add_custom_target(${BINARY_NAME}-py ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${BINARY_NAME}/__init__.py) +add_custom_target(${BINARY_NAME}-py ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/build/lib/${BINARY_NAME}/__init__.py)
M
src/platform/python/_builder.h
→
src/platform/python/_builder.h
@@ -20,6 +20,9 @@
void free(void*); #include <limits.h> +#undef const + +#include "flags.h" #include "core/core.h" #include "core/tile-cache.h"
M
src/platform/python/_builder.py
→
src/platform/python/_builder.py
@@ -1,12 +1,22 @@
import cffi -import os.path +import os, os.path +import shlex import subprocess import sys ffi = cffi.FFI() -src = os.path.join(os.path.dirname(__file__), "..", "..") +pydir = os.path.dirname(os.path.abspath(__file__)) +srcdir = os.path.join(pydir, "..", "..") +bindir = os.environ.get("BINDIR", os.path.join(os.getcwd(), "..")) + +cpp = shlex.split(os.environ.get("CPP", "cc -E")) +cppflags = shlex.split(os.environ.get("CPPFLAGS", "")) +if __name__ == "__main__": + cppflags.extend(sys.argv[1:]) +cppflags.extend(["-I" + srcdir, "-I" + bindir]) ffi.set_source("mgba._pylib", """ +#include "flags.h" #include "util/common.h" #include "core/core.h" #include "core/log.h"@@ -34,19 +44,21 @@ struct mLoggerPy {
struct mLogger d; void* pyobj; }; -""", include_dirs=[src], - extra_compile_args=sys.argv[1:], +""", include_dirs=[srcdir], + extra_compile_args=cppflags, libraries=["mgba"], - library_dirs=[os.path.join(os.getcwd(), "..")], - sources=[os.path.join(os.path.dirname(__file__), path) for path in ["vfs-py.c", "log.c"]]) + library_dirs=[bindir], + sources=[os.path.join(pydir, path) for path in ["vfs-py.c", "log.c"]]) -with open(os.path.join(os.getcwd(), "_builder.h")) as core: - lines = [] - for line in core: - line = line.strip() - if line.startswith('#'): - continue - lines.append(line) - ffi.cdef('\n'.join(lines)) +preprocessed = subprocess.check_output(cpp + ["-fno-inline", "-P"] + cppflags + [os.path.join(pydir, "_builder.h")], universal_newlines=True) + +lines = [] +for line in preprocessed.splitlines(): + line = line.strip() + if line.startswith('#'): + continue + lines.append(line) +ffi.cdef('\n'.join(lines)) -ffi.compile() +if __name__ == "__main__": + ffi.compile()
M
src/platform/python/setup.py.in
→
src/platform/python/setup.py.in
@@ -2,9 +2,12 @@ from setuptools import setup
import re classifiers = [ + "Programming Language :: C", "Programming Language :: Python :: 2", "Programming Language :: Python :: 3", - "License :: OSI Approved :: Mozilla Public License 2.0 (MPL 2.0)" + "License :: OSI Approved :: Mozilla Public License 2.0 (MPL 2.0)", + "Topic :: Games/Entertainment", + "Topic :: System :: Emulators" ] setup(name="${BINARY_NAME}",@@ -15,6 +18,7 @@ url="http://github.com/mgba-emu/mgba/",
packages=["mgba"], setup_requires=['cffi>=1.6'], install_requires=['cffi>=1.6', 'cached-property'], + cffi_modules=["_builder.py:ffi"], license="MPL 2.0", classifiers=classifiers )