diff --git a/WinPort/WinCompat.h b/WinPort/WinCompat.h index ec4131645..6bc2fd5d7 100644 --- a/WinPort/WinCompat.h +++ b/WinPort/WinCompat.h @@ -1,4 +1,5 @@ #pragma once +#ifndef FAR_PYTHON_GEN #include #include #include @@ -11,6 +12,7 @@ // for PATH_MAX # include #endif +#endif /* FAR_PYTHON_GEN */ #define ELFMZ_WINPORT @@ -22,6 +24,7 @@ typedef unsigned __int64 uint64_t; #define FOPEN_WRITE "wb" #else +#ifndef FAR_PYTHON_GEN # include # include # ifdef __cplusplus @@ -29,6 +32,7 @@ typedef unsigned __int64 uint64_t; # else # define SHAREDSYMBOL __attribute__ ((visibility("default"))) # endif +#endif /* FAR_PYTHON_GEN */ # define FAR # define FARPROC @@ -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 #include #include @@ -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 diff --git a/WinPort/WinPort.h b/WinPort/WinPort.h index c52a794c3..8bdd8184d 100644 --- a/WinPort/WinPort.h +++ b/WinPort/WinPort.h @@ -1,4 +1,5 @@ #pragma once +#ifndef FAR_PYTHON_GEN //#ifdef _WIN32 #if 0 # include @@ -306,3 +307,4 @@ template #endif +#endif /* FAR_PYTHON_GEN */ diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt index 8690d83dd..1805d089a 100644 --- a/python/CMakeLists.txt +++ b/python/CMakeLists.txt @@ -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) @@ -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}" ) diff --git a/python/configs/plug/far2l/pluginmanager.py b/python/configs/plug/far2l/pluginmanager.py index 285ce3279..0d14a070a 100644 --- a/python/configs/plug/far2l/pluginmanager.py +++ b/python/configs/plug/far2l/pluginmanager.py @@ -5,7 +5,6 @@ import configparser import logging import logging.config -import cffi USERHOME = os.path.expanduser('~/.config/far2l/plugins/python') @@ -42,19 +41,7 @@ def handle_exception(exc_type, exc_value, exc_traceback): # py:load # py:unload - -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: diff --git a/python/src/farwin.h b/python/src/farwin.h deleted file mode 100644 index 7938f4727..000000000 --- a/python/src/farwin.h +++ /dev/null @@ -1,303 +0,0 @@ -typedef uint32_t ULONG; -typedef unsigned int UINT; -typedef unsigned short USHORT; -typedef int LONG; -typedef int INT, *PINT, *LPINT; -typedef short SHORT; -typedef long long LONGLONG; -typedef unsigned long long ULONGLONG; -typedef void VOID; - -typedef size_t SIZE_T; - -typedef char CCHAR; // winnt -typedef short CSHORT; -typedef ULONG CLONG; - -typedef CCHAR *PCCHAR; -typedef CSHORT *PCSHORT; -typedef CLONG *PCLONG; - -typedef ULONG DWORD; -typedef USHORT WORD; - -typedef unsigned long long DWORD64, *PDWORD64; -typedef int64_t INT64, *PINT64; -typedef uint64_t UINT64, *PUINT64; -typedef int64_t LONG64, *PLONG64; -typedef uint64_t ULONG64, *PULONG64; - -#if defined(__LP64__) || defined(_LP64) -typedef INT64 INT_PTR; -typedef UINT64 UINT_PTR; -typedef DWORD64 DWORD_PTR; -typedef LONG64 LONG_PTR; -typedef ULONG64 ULONG_PTR; -#else -typedef INT32 INT_PTR; -typedef UINT32 UINT_PTR; -typedef DWORD32 DWORD_PTR; -typedef LONG32 LONG_PTR; -typedef ULONG32 ULONG_PTR; -#endif - -typedef char *LPCSTR; -typedef char *LPSTR; -typedef char *PSTR; - -typedef wchar_t *LPCWSTR, * LPCTSTR; -typedef wchar_t *LPWSTR, *LPTSTR; -typedef wchar_t *PWSTR; - -typedef wchar_t WCHAR, TCHAR; -typedef char CHAR; -typedef unsigned char UCHAR; -typedef unsigned char BYTE; -typedef BYTE *PBYTE; -typedef BYTE *LPBYTE; - -typedef DWORD *LPDWORD; -typedef DWORD *PDWORD; -typedef ULONG *PULONG; -typedef LONG *PLONG; -typedef WORD *LPWORD; -typedef WORD *PWORD; -typedef USHORT *PUSHORT; -typedef SHORT *PSHORT; - -typedef LONGLONG *PLONGLONG; -typedef ULONGLONG *PULONGLONG; - -typedef int BOOL; -typedef UCHAR BOOLEAN; -typedef BOOL *LPBOOL, *PBOOL; - -typedef void *HANDLE; -typedef void *PVOID; -typedef void *LPVOID; -typedef void *LPCVOID; - -typedef ULONG LCID; // winnt -typedef PULONG PLCID; // winnt -typedef USHORT LANGID; // winnt - - -typedef HANDLE HKEY; -typedef struct _OVERLAPPED *LPOVERLAPPED; -typedef HKEY *PHKEY; - -typedef DWORD ACCESS_MASK; -typedef ACCESS_MASK *PACCESS_MASK; -typedef ACCESS_MASK REGSAM; - -typedef int HRESULT; - -typedef struct _GUID { - unsigned long Data1; - unsigned short Data2; - unsigned short Data3; - unsigned char Data4[ 8 ]; -} GUID, IID; - -typedef struct tagRECT { - LONG left; - LONG top; - LONG right; - LONG bottom; -} RECT; - - -#define DRIVE_UNKNOWN 0 -#define DRIVE_NO_ROOT_DIR 1 -#define DRIVE_REMOVABLE 2 -#define DRIVE_FIXED 3 -#define DRIVE_REMOTE 4 -#define DRIVE_CDROM 5 -#define DRIVE_RAMDISK 6 - - - -typedef struct _FILETIME { - DWORD dwLowDateTime; - DWORD dwHighDateTime; -} FILETIME, *PFILETIME, *LPFILETIME; - -typedef union _LARGE_INTEGER { - struct { - DWORD LowPart; - LONG HighPart; - } u; - struct { - DWORD LowPart; - LONG HighPart; - }; - LONGLONG QuadPart; -} LARGE_INTEGER; -typedef LARGE_INTEGER *PLARGE_INTEGER; - -typedef union _ULARGE_INTEGER { - struct { - DWORD LowPart; - DWORD HighPart; - } u; - struct { - DWORD LowPart; - DWORD HighPart; - }; - ULONGLONG QuadPart; -} ULARGE_INTEGER; -typedef ULARGE_INTEGER *PULARGE_INTEGER; - -typedef struct _COORD { - SHORT X; - SHORT Y; -} COORD, *PCOORD; - -typedef struct _CONSOLE_FONT_INFO { - DWORD nFont; - COORD dwFontSize; -} CONSOLE_FONT_INFO, *PCONSOLE_FONT_INFO; - -typedef struct _SMALL_RECT { - SHORT Left; - SHORT Top; - SHORT Right; - SHORT Bottom; -} SMALL_RECT, *PSMALL_RECT; - -typedef struct _CONSOLE_SCREEN_BUFFER_INFO { - COORD dwSize; - COORD dwCursorPosition; - WORD wAttributes; - SMALL_RECT srWindow; - COORD dwMaximumWindowSize; -} CONSOLE_SCREEN_BUFFER_INFO, *PCONSOLE_SCREEN_BUFFER_INFO; - -typedef struct _CONSOLE_CURSOR_INFO { - DWORD dwSize; - BOOL bVisible; -} CONSOLE_CURSOR_INFO, *PCONSOLE_CURSOR_INFO; - -typedef struct _CHAR_INFO { - union { - WCHAR UnicodeChar; - CHAR AsciiChar; - } Char; - WORD Attributes; -} CHAR_INFO, *PCHAR_INFO; - - -typedef struct _WINDOW_BUFFER_SIZE_RECORD { - COORD dwSize; -} WINDOW_BUFFER_SIZE_RECORD, *PWINDOW_BUFFER_SIZE_RECORD; - -typedef struct _MENU_EVENT_RECORD { - UINT dwCommandId; -} MENU_EVENT_RECORD, *PMENU_EVENT_RECORD; - -typedef struct _FOCUS_EVENT_RECORD { - BOOL bSetFocus; -} FOCUS_EVENT_RECORD, *PFOCUS_EVENT_RECORD; - -typedef struct _KEY_EVENT_RECORD { - BOOL bKeyDown; - WORD wRepeatCount; - WORD wVirtualKeyCode; - WORD wVirtualScanCode; - union { - WCHAR UnicodeChar; - CHAR AsciiChar; - } uChar; - DWORD dwControlKeyState; -} KEY_EVENT_RECORD, *PKEY_EVENT_RECORD; - -// -// ControlKeyState flags -// - -#define RIGHT_ALT_PRESSED 0x0001 // the right alt key is pressed. -#define LEFT_ALT_PRESSED 0x0002 // the left alt key is pressed. -#define RIGHT_CTRL_PRESSED 0x0004 // the right ctrl key is pressed. -#define LEFT_CTRL_PRESSED 0x0008 // the left ctrl key is pressed. -#define SHIFT_PRESSED 0x0010 // the shift key is pressed. -#define NUMLOCK_ON 0x0020 // the numlock light is on. -#define SCROLLLOCK_ON 0x0040 // the scrolllock light is on. -#define CAPSLOCK_ON 0x0080 // the capslock light is on. -#define ENHANCED_KEY 0x0100 // the key is enhanced. -#define NLS_DBCSCHAR 0x00010000 // DBCS for JPN: SBCS/DBCS mode. -#define NLS_ALPHANUMERIC 0x00000000 // DBCS for JPN: Alphanumeric mode. -#define NLS_KATAKANA 0x00020000 // DBCS for JPN: Katakana mode. -#define NLS_HIRAGANA 0x00040000 // DBCS for JPN: Hiragana mode. -#define NLS_ROMAN 0x00400000 // DBCS for JPN: Roman/Noroman mode. -#define NLS_IME_CONVERSION 0x00800000 // DBCS for JPN: IME conversion. -#define NLS_IME_DISABLE 0x20000000 // DBCS for JPN: IME enable/disable. - - -typedef struct _MOUSE_EVENT_RECORD { - COORD dwMousePosition; - DWORD dwButtonState; - DWORD dwControlKeyState; - DWORD dwEventFlags; -} MOUSE_EVENT_RECORD, *PMOUSE_EVENT_RECORD; -#define FROM_LEFT_1ST_BUTTON_PRESSED 0x0001 -#define RIGHTMOST_BUTTON_PRESSED 0x0002 -#define FROM_LEFT_2ND_BUTTON_PRESSED 0x0004 -#define FROM_LEFT_3RD_BUTTON_PRESSED 0x0008 -#define FROM_LEFT_4TH_BUTTON_PRESSED 0x0010 - -#define MOUSE_MOVED 0x0001 -#define DOUBLE_CLICK 0x0002 -#define MOUSE_WHEELED 0x0004 -#define MOUSE_HWHEELED 0x0008 - - -#define NOOP_EVENT 0x0000 -#define KEY_EVENT 0x0001 // Event contains key event record -#define MOUSE_EVENT 0x0002 // Event contains mouse event record -#define WINDOW_BUFFER_SIZE_EVENT 0x0004 // Event contains window change event record -#define MENU_EVENT 0x0008 // Event contains menu event record -#define FOCUS_EVENT 0x0010 // event contains focus change - - -typedef struct _INPUT_RECORD { - WORD EventType; - union { - KEY_EVENT_RECORD KeyEvent; - MOUSE_EVENT_RECORD MouseEvent; - WINDOW_BUFFER_SIZE_RECORD WindowBufferSizeEvent; - MENU_EVENT_RECORD MenuEvent; - FOCUS_EVENT_RECORD FocusEvent; - } Event; -} INPUT_RECORD, *PINPUT_RECORD; - - - -#define FOREGROUND_BLUE 0x0001 // text color contains blue. -#define FOREGROUND_GREEN 0x0002 // text color contains green. -#define FOREGROUND_RED 0x0004 // text color contains red. -#define FOREGROUND_INTENSITY 0x0008 // text color is intensified. -#define BACKGROUND_BLUE 0x0010 // background color contains blue. -#define BACKGROUND_GREEN 0x0020 // background color contains green. -#define BACKGROUND_RED 0x0040 // background color contains red. -#define BACKGROUND_INTENSITY 0x0080 // background color is intensified. -#define COMMON_LVB_LEADING_BYTE 0x0100 // Leading Byte of DBCS -#define COMMON_LVB_TRAILING_BYTE 0x0200 // Trailing Byte of DBCS -#define COMMON_LVB_GRID_HORIZONTAL 0x0400 // DBCS: Grid attribute: top horizontal. -#define COMMON_LVB_GRID_LVERTICAL 0x0800 // DBCS: Grid attribute: left vertical. -#define COMMON_LVB_GRID_RVERTICAL 0x1000 // DBCS: Grid attribute: right vertical. -#define COMMON_LVB_REVERSE_VIDEO 0x4000 // DBCS: Reverse fore/back ground attribute. -#define COMMON_LVB_UNDERSCORE 0x8000 // DBCS: Underscore. - -#define COMMON_LVB_SBCSDBCS 0x0300 // SBCS or DBCS flag. - - - - - - - - -typedef struct _INPUT_RECORD INPUT_RECORD; -typedef struct _CHAR_INFO CHAR_INFO; - -#define CP_AUTODETECT -1 diff --git a/python/src/prebuild.sh b/python/src/prebuild.sh index 993f6d752..23f407ca3 100755 --- a/python/src/prebuild.sh +++ b/python/src/prebuild.sh @@ -1,61 +1,18 @@ #!/bin/bash set -e +#echo "XBUILD=$*" SRC="$1" DST="$2" PYTHON="$3" -CC="$4 -E -DFAR_USE_INTERNALS -DWINAPI= -DWINAPIV= -D__cdecl=" -FAR2SDK="$SRC/far2l/far2sdk" -WINPORT="$SRC/WinPort" - -mkdir -p "$DST/staging" "$DST/incpy" - -echo '/** This file is autogenerated */' > "$DST/incpy/farwin.h" -echo '/** This file is autogenerated */' > "$DST/incpy/farcolor.h" -echo '/** This file is autogenerated */' > "$DST/incpy/farkeys.h" -echo '/** This file is autogenerated */' > "$DST/incpy/farplug-wide.h" - - -grep $'#[ \t]*define[ \t]*VK_\| KEYEVENTF_' "$WINPORT/WinCompat.h" >> "$DST/incpy/farwin.h" -grep $'#[ \t]*define[ \t]*' "$SRC/python/src/farwin.h" >> "$DST/incpy/farwin.h" - -grep $'#[ \t]*define[ \t]*.*_KEY_BASE' "$FAR2SDK/farkeys.h" >> "$DST/incpy/farkeys.h" -grep $'#[ \t]*define[ \t]*FARMANAGERVERSION_' "$FAR2SDK/farplug-wide.h" >> "$DST/incpy/farplug-wide.h" - -function preprocess_sdk_header -{ - grep -v '#[ \t]*include\|#[ \t]*pragma' "$1" | grep -v $'WINAPI _export' | $CC - |grep -v '^#' >> "$2" - sed -i 's/(\ \*FAR/(\*FAR/g' "$2" - for CODE in {33..38} {40,41} {43..45} {47..90} {94..126}; do - CHR=$(printf "\x$(printf %x $CODE)") - sed -i "s '$CHR' $CODE g" "$2" - done - sed -i "s/' ''/32/g" "$2" - sed -i "s/'\\\\''/39/g" "$2" - sed -i "s/'\\*'/42/g" "$2" - sed -i "s/'\\.'/46/g" "$2" - sed -i "s/'\\['/91/g" "$2" - sed -i "s/'\\\\\\\\'/92/g" "$2" - sed -i "s/'\\]'/93/g" "$2" - sed -i "s/'{'/123/g" "$2" - sed -i "s/'}'/125/g" "$2" -} - -preprocess_sdk_header "$FAR2SDK/farcolor.h" "$DST/incpy/farcolor.h" & -preprocess_sdk_header "$FAR2SDK/farkeys.h" "$DST/incpy/farkeys.h" & -preprocess_sdk_header "$FAR2SDK/farplug-wide.h" "$DST/incpy/farplug-wide.h" & -preprocess_sdk_header "$SRC/python/src/farwin.h" "$DST/incpy/farwin.h" & -wait - - -################### +mkdir -p "$DST/incpy" if [ ! -f "$DST/python/.prepared" ]; then echo "Preparing python virtual env at $DST/python using $PYTHON" mkdir -p "$DST/python" $PYTHON -m venv --system-site-packages "$DST/python" - "$DST/python/bin/python" -m pip install cffi debugpy + "$DST/python/bin/python" -m pip install cffi debugpy pcpp echo "1" > "$DST/python/.prepared" fi @@ -63,7 +20,6 @@ fi cp -f -R \ "$SRC/python/configs/plug/far2l/"* \ - "$DST/incpy/"* \ - "$DST/staging/" + "$DST/incpy/" -"$DST/python/bin/python" "$SRC/python/src/pythongen.py" "${DST}" +"$DST/python/bin/python" "$SRC/python/src/pythongen.py" "${SRC}" "${DST}/incpy" diff --git a/python/src/python.cpp b/python/src/python.cpp index 3bba454b4..08ce54a10 100644 --- a/python/src/python.cpp +++ b/python/src/python.cpp @@ -21,8 +21,6 @@ static struct PluginStartupInfo Info; static FARSTANDARDFUNCTIONS FSF; -PyMODINIT_FUNC PyInit__pyfar(void); - // #define PYPLUGIN_DEBUGLOG "/tmp/far2.py.log" // #define PYPLUGIN_DEBUGLOG "" /* to stderr */ @@ -100,8 +98,6 @@ class PythonHolder : Threaded syspath += "\nsys.path.insert(1, '" + pluginPath + "')"; PYTHON_LOG("syspath=%s\n", syspath.c_str()); - PyInit__pyfar(); - PyRun_SimpleString(syspath.c_str()); PyObject *pName; diff --git a/python/src/pythongen.py b/python/src/pythongen.py index 9c514aa26..6d360cfa9 100755 --- a/python/src/pythongen.py +++ b/python/src/pythongen.py @@ -1,48 +1,77 @@ #!/usr/bin/env vpython3 import sys import os +import pcpp +import io import cffi -source = os.path.join(sys.argv[1], "staging") -target = os.path.join(sys.argv[1], "staging", "_pyfar.cpp") +source = sys.argv[1] +target = os.path.join(sys.argv[2], "far2lcffi.py") -ffi = cffi.FFI() +cpp = pcpp.Preprocessor() +cpp.add_path(source) +cpp.add_path(os.path.join(source, "far2l", "far2sdk")) +cpp.define("FAR_USE_INTERNALS 1") +# cpp.define('WINPORT_DIRECT') +cpp.define("WINPORT_REGISTRY") +cpp.define("UNICODE") +cpp.define("PROCPLUGINMACROFUNC") +cpp.define("__GNUC__") +if True: + # 64 bit platform + cpp.define("__LP64__") +cpp.define("_FAR_NO_NAMELESS_UNIONS") +cpp.define("_FILE_OFFSET_BITS 64") +cpp.define("FAR_PYTHON_GEN 1") +data = """\ +#define PATH_MAX 1024 +#define NAME_MAX 255 +#define uid_t uint32_t +#define gid_t uint32_t +#include "farplug-wide.h" +#include "farcolor.h" +#include "farkeys.h" +""" +cpp.parse(data) +fp = io.StringIO() +cpp.write(fp) -xpre = """ -//#define FAR_DONT_USE_INTERNALS -#define FAR_USE_INTERNALS -#define PROCPLUGINMACROFUNC 1 +data = fp.getvalue() +data = data.replace("'['", "0x5B") +data = data.replace("']'", "0x5D") +data = data.replace("','", "0x2C") +data = data.replace("'\"'", "0x22") +data = data.replace("'.'", "0x2E") +data = data.replace("'/'", "0x2F") +data = data.replace("':'", "0x3A") +data = data.replace("';'", "0x3B") +data = data.replace("'\\\\'", "0x5C") +data = data.replace("#line", "//#line") +data = data.replace("#pragma", "//#pragma") -#define UNICODE -#define WINPORT_DIRECT -#define WINPORT_REGISTRY -//#define WXUSINGDLL -#define _FILE_OFFSET_BITS 64 -//#define __WXGTK__ +# if preprocessor fails then far2l.py is not generated +pydata = ( + '''\ +## This file is autogenerated +far2l = """ +''' + + data + + '''\ """ +import cffi -ffi.set_source("_pyfar", # name of the output C extension - #xpre + -""" -#include "farwin.h" -#include "farplug-wide.h" -#include "farcolor.h" -#include "farkeys.h" -""", - include_dirs=[ - os.path.join(source) - ], +ffi = cffi.FFI() +ffi.cdef(far2l, packed=True) +del far2l +''' ) -for fname in ("farwin.h", "farcolor.h", "farkeys.h", "farplug-wide.h"): - fqname = os.path.join(source, fname) - data = open(fqname, "rt", encoding="utf-8").read() - ffi.cdef(data, packed=True) +open(target, "wt").write(pydata) -if 0: - ffi.compile( - verbose=True, - call_c_compiler=False - ) -else: - ffi.emit_c_code(target) +# import generated file as real plugin does +try: + sys.path.insert(1, sys.argv[2]) + from far2lcffi import ffi, cffi +except: + os.unlink(target) + raise