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

Update for swig/python #4093

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
49 changes: 38 additions & 11 deletions pjsip-apps/src/swig/importsym.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from pycparser import c_generator
import sys
import os
from modules.win32fix import *

def which(program):
import os
Expand Down Expand Up @@ -52,18 +53,40 @@ def is_exe(fpath):
print 'Error: need to have cpp in PATH'
sys.exit(1)

# Hardcoded!
# Note for win32:
# - temporarily comment "#include <pj/compat/socket.h>" in pj/sock.h (line ~29)
if sys.platform == 'win32':
PYCPARSER_DIR="D:/work/tool/pycparser-master"
# If OS is Linux, find local OS path for Unix .local installation of python, and assume user has installed pycparser via pip.
if sys.platform == "linux2":
script_path_list = os.path.normpath(os.path.abspath(__file__)).split(os.sep)
home_linux = os.path.join("/", script_path_list[1], script_path_list[2])
# if OS is Windows, find the path to current python environment, and assume user has installed pycparser via pip.
elif sys.platform == "win32":
# Current Environment Path. it will take the currently active python interpreter path, which means if you are using a virtual environment,
# it will take the path of the virtual environment.
home_win = sys.prefix
if home_win == "C:/msys64/mingw64":
home_win = "C:/msys64/mingw64/lib/python2.7"
else:
pass

# disable the include of pj/compat/socket.h in pj/sock.h, fixes having to go in and manually comment out the include.
disable_include()
print("continuing with code")

# Checks if its mingw64, if it is, it will use the path to the python interpreter in the mingw64 folder.
if sys.platform == 'win32' and home_win == "C:/msys64/mingw64/lib/python2.7":
PYCPARSER_DIR = home_win + "/site-packages/pycparser"
# else it will use the path to the python interpreter in the default location.
elif sys.platform == "win32" and not home_win == "C:/msys64/mingw64/lib/python2.7":
PYCPARSER_DIR = home_win + "/Lib/site-packages/pycparser"
elif sys.platform == "linux2":
PYCPARSER_DIR="/home/bennylp/Desktop/opt/src/pycparser-master"
PYCPARSER_DIR = home_linux + "/.local/lib/python2.7/site-packages/pycparser"
else:
PYCPARSER_DIR="/Library/Python/2.7/site-packages/pycparser"
print("Couldnt find your python location with pycparser.")
PYCPARSER_DIR = raw_input("Enter the path to your pycparser installation: ")

pycparser_Fakelibc = os.path.dirname(PYCPARSER_DIR) + '/pycparser_fake_libc'

if not os.path.exists(PYCPARSER_DIR + '/utils/fake_libc_include'):
print "Error: couldn't find pycparser utils in '%s'" % PYCPARSER_DIR
if not os.path.exists(pycparser_Fakelibc):
print "Error: couldn't find pycparser_fake_libc in '%s'" % os.path.dirname(PYCPARSER_DIR)
sys.exit(1)

# Heading, to be placed before the source files
Expand All @@ -75,7 +98,7 @@ def is_exe(fpath):

# CPP (C preprocessor) settings
CPP_CFLAGS = [
'-I' + PYCPARSER_DIR + '/utils/fake_libc_include',
'-I' + pycparser_Fakelibc,
"-I" + PJ_ROOT_PATH + "pjlib/include",
"-I" + PJ_ROOT_PATH + "pjlib-util/include",
"-I" + PJ_ROOT_PATH + "pjnath/include",
Expand Down Expand Up @@ -190,5 +213,9 @@ def process(self, listfile, outfile):
os.remove("yacctab.py")
except OSError:
pass

finally:
if sys.platform == "win32":
re_enable_include()
print("re-enabled pj/compat/socket.h!")
sys.exit(0)

Empty file.
84 changes: 84 additions & 0 deletions pjsip-apps/src/swig/modules/win32fix.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# functions to disable and re-enable the include of pj/compat/socket.h in pj/sock.h
def disable_include():
import os.path as path
import re

current_dir = path.dirname(path.abspath(__file__))
main_project = path.abspath(path.join(current_dir, '../../../../'))
file_path = path.abspath(path.join(main_project, 'pjlib/include/pj/sock.h'))
print("File to edit: %s" % file_path)

global use_new_path

yes_no = raw_input("is the path correct? (y/n): ")
if yes_no == 'y':
is_path_valid = True
elif yes_no == 'n':
is_path_valid = False

if is_path_valid == True:

use_new_path = False
with open(file_path, 'r') as file:
content = file.read()

# Regular expression to match the line with #include <pj/compat/socket.h>
pattern = re.compile(r'#include <pj/compat/socket.h>')

# Replace the matched pattern
new_content = pattern.sub(r'/* #include <pj/compat/socket.h> */', content)

with open(file_path, 'w') as file:
file.write(new_content)

print("pj/compat/socket.h has been disabled in pj/sock.h!")

elif is_path_valid == False:


use_new_path = True
print("Current location is %s" % main_project)
print("Use ../ at the start of the path to go back a directory...")
new_path = raw_input("Enter the correct path: ")
global new_file_path
new_file_path = path.abspath(path.join(main_project, new_path))

with open(new_file_path, 'r') as file:
content = file.read()

# Regular expression to match the line with #include <pj/compat/socket.h>
pattern = re.compile(r'#include <pj/compat/socket.h>')

# Replace the matched pattern
new_content = pattern.sub(r'/* #include <pj/compat/socket.h> */', content)

with open(new_file_path, 'w') as file:
file.write(new_content)

print("pj/compat/socket.h has been disabled in pj/sock.h!")

def re_enable_include():

import os.path as path
import re

current_dir = path.dirname(path.abspath(__file__))
main_project = path.abspath(path.join(current_dir, '../../../'))
file_path = path.abspath(path.join(main_project, 'pjlib/include/pj/sock.h'))

if use_new_path == True:
file_path = new_file_path

with open(file_path, 'r') as file:
content = file.read()

# Regular expression to match the line with #include <pj/compat/socket.h>
pattern = re.compile(r'/* #include <pj/compat/socket.h> */')

# Replace the matched pattern
new_content = pattern.sub(r'#include <pj/compat/socket.h>', content)

with open(file_path, 'w') as file:
file.write(new_content)

print("pj/compat/socket.h has been re-enabled in pj/sock.h!")
6 changes: 6 additions & 0 deletions pjsip-apps/src/swig/python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@
import os
import sys
import platform
import transform_docs

try:
transform_docs.transform()
except Exception as e:
print(f"Error transforming docs: {e}")

# find pjsip version
pj_version=""
Expand Down
16 changes: 16 additions & 0 deletions pjsip-apps/src/swig/python/transform_docs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import re

def transform():
file_path = 'pjsua2.py'

with open(file_path, 'r') as file:
content = file.read()

# Regular expression to match the property with doc=...
pattern = re.compile(r'(\w+\s*=\s*property\([^,]+,[^,]+),\s*doc=r?\"\"\"(.*?)\"\"\"\)', re.DOTALL)

# Replace the matched pattern
new_content = pattern.sub(r'\1)\n """\2"""', content)

with open(file_path, 'w') as file:
file.write(new_content)
Loading