Skip to content

Commit

Permalink
Merge pull request #1172 from m32/master
Browse files Browse the repository at this point in the history
#1164 - automagic generation of far2lcffi.py file
  • Loading branch information
elfmz authored Jan 4, 2022
2 parents c675af3 + c4bf4d2 commit eab8777
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 414 deletions.
7 changes: 7 additions & 0 deletions WinPort/WinCompat.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#pragma once
#ifndef FAR_PYTHON_GEN
#include <stddef.h>
#include <stdint.h>
#include <stdlib.h>
Expand All @@ -11,6 +12,7 @@
// for PATH_MAX
# include <linux/limits.h>
#endif
#endif /* FAR_PYTHON_GEN */

#define ELFMZ_WINPORT

Expand All @@ -22,13 +24,15 @@ typedef unsigned __int64 uint64_t;
#define FOPEN_WRITE "wb"

#else
#ifndef FAR_PYTHON_GEN
# include <unistd.h>
# include <wchar.h>
# ifdef __cplusplus
# define SHAREDSYMBOL extern "C" __attribute__ ((visibility("default")))
# else
# define SHAREDSYMBOL __attribute__ ((visibility("default")))
# endif
#endif /* FAR_PYTHON_GEN */

# define FAR
# define FARPROC
Expand Down Expand Up @@ -72,6 +76,8 @@ typedef unsigned __int64 uint64_t;
# define st_ctim st_ctimespec
# define st_atim st_atimespec
#endif

#ifndef FAR_PYTHON_GEN
#include <limits.h>
#include <sys/types.h>
#include <sys/stat.h>
Expand Down Expand Up @@ -185,6 +191,7 @@ static char iswalnum(wchar_t c) {return iswalpha(c) || (c>='0' && c<='9'); }
static wchar_t towupper(wchar_t c) {return c; }
static wchar_t towlower(wchar_t c) {return c; }*/

#endif /* FAR_PYTHON_GEN */
#endif


Expand Down
2 changes: 2 additions & 0 deletions WinPort/WinPort.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#pragma once
#ifndef FAR_PYTHON_GEN
//#ifdef _WIN32
#if 0
# include <Windows.h>
Expand Down Expand Up @@ -306,3 +307,4 @@ template <class CHAR_T>


#endif
#endif /* FAR_PYTHON_GEN */
20 changes: 11 additions & 9 deletions python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ project(python)

set(SOURCES
src/python.cpp
${CMAKE_CURRENT_BINARY_DIR}/staging/_pyfar.cpp
${CMAKE_CURRENT_BINARY_DIR}/incpy/far2lcffi.py
)

find_package(PythonLibs 3.0)
Expand All @@ -25,19 +25,21 @@ set_target_properties(python PROPERTIES
SUFFIX ".far-plug-wide"
)

find_program (SED NAMES sed)
if(NOT SED)
message(FATAL_ERROR "${ColorRed}sed not found - please install it${ColorNormal}")
endif ()

add_custom_command(TARGET python POST_BUILD
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/configs
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/staging/_pyfar.cpp
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/incpy/far2lcffi.py
COMMAND ${CMAKE_COMMAND} -E copy_directory "${CMAKE_CURRENT_SOURCE_DIR}/configs" "${INSTALL_DIR}/Plugins/python"
COMMAND ${CMAKE_COMMAND} -E copy_directory "${CMAKE_CURRENT_BINARY_DIR}/python" "${INSTALL_DIR}/Plugins/python/plug/python"
COMMAND ${CMAKE_COMMAND} -E copy_directory "${CMAKE_CURRENT_BINARY_DIR}/incpy" "${INSTALL_DIR}/Plugins/python/plug/far2l"
)

add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/staging/_pyfar.cpp
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/src/prebuild.sh "${CMAKE_SOURCE_DIR}" "${CMAKE_CURRENT_BINARY_DIR}" "${PYTHON3}" "${CMAKE_C_COMPILER}"
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/incpy/far2lcffi.py
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/src/pythongen.py
DEPENDS ../far2l/far2sdk/farplug-wide.h
DEPENDS ../far2l/far2sdk/farcolor.h
DEPENDS ../far2l/far2sdk/farkeys.h
DEPENDS ../WinPort/windows.h
DEPENDS ../WinPort/WinCompat.h
DEPENDS ../WinPort/WinPort.h
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/src/prebuild.sh "${CMAKE_SOURCE_DIR}" "${CMAKE_CURRENT_BINARY_DIR}" "${PYTHON3}"
)
15 changes: 1 addition & 14 deletions python/configs/plug/far2l/pluginmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import configparser
import logging
import logging.config
import cffi

USERHOME = os.path.expanduser('~/.config/far2l/plugins/python')

Expand Down Expand Up @@ -42,19 +41,7 @@ def handle_exception(exc_type, exc_value, exc_traceback):
# py:load <python modulename>
# py:unload <registered python module name>


def installffi(ffi):
dname = "/".join(__file__.split("/")[:-1])
for fname in ("farwin.h", "farcolor.hpp", "farkeys.hpp", "plugin.hpp"):
fqname = os.path.join(dname, fname)
log.debug("installffi({0})".format(fqname))
data = open(fqname, "rt", encoding="utf-8").read()
ffi.cdef(data, packed=True)


ffi = cffi.FFI()
installffi(ffi)
# ffi.cdef(open(__file__+'.h', 'rt').read(), packed=True)
from .far2lcffi import cffi, ffi
ffic = ffi.dlopen("c" if sys.platform != "darwin" else "libSystem.dylib")

class PluginManager:
Expand Down
Loading

0 comments on commit eab8777

Please sign in to comment.