-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathset_path.py
111 lines (92 loc) · 4.6 KB
/
set_path.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
import argparse,sys,os,json
import sysconfig,glob,json,shutil
parser = argparse.ArgumentParser()
parser.add_argument("--entry_point", help=\
"sets the module where main_loop function exists if the entrypoint file does not exists it is created "+\
"with the functions main_loop and kill")
parser.add_argument("--entry_path", help="a path where the entry_point exists")
parser.add_argument("--project_path", help="path to unreal engine project path")
parser.add_argument("--packed_game_path", help="path to a packed game path")
parser.add_argument("--packed_game_name", help="path to a packed game path")
parser.add_argument("--uepath", help="path to the unreal engine")
args = parser.parse_args()
pathdata={}
cwd=os.path.abspath('.')
pathdata['bridge_path']=os.path.abspath(os.path.dirname(__file__))+'/src'
project_mode= args.project_path is not None
stand_alone_game= args.packed_game_path is not None
if project_mode:
pathdata['UE']=os.path.abspath(args.uepath)
pathdata['project_path']=os.path.abspath(args.project_path)
uepath=pathdata['UE']
if args.entry_path is not None:
pathdata['entry_path']=os.path.abspath(args.entry_path)
libdir=sysconfig.get_config_var('LIBPL')
libfile=sysconfig.get_config_var('LDLIBRARY')
include_path=sysconfig.get_path('include')
file_dir=os.path.abspath(os.path.dirname(__file__))
pylibsearch=\
"import sysconfig;from os import path;"+\
"so=sysconfig.get_config_var('LDLIBRARY');"+\
"p1=sysconfig.get_config_var('LIBPL')+'/'+so;"+\
"p2=sysconfig.get_config_var('LIBDIR')+'/'+so;"+\
"print(p1 if path.isfile(p1) else p2 if path.isfile(p2) else 'NULL')"
if project_mode:
pfile=glob.glob(pathdata['project_path']+'/*.uproject')[0]
pdata=json.load(open(pfile))
if 'Modules' in pdata:
pname=pdata['Modules'][0]['Name']
else: #take the path as the project name
print("error no mosuls created please create an empty c++ file in the project to make it c++ project")
sys.exit(-1)
prj_src_path=pathdata['project_path']+'/Source/'+pname
#print(prj_src_path)
dest_src_dir=prj_src_path+'/PyServer'
if os.path.isdir(dest_src_dir):
shutil.rmtree(dest_src_dir)
os.mkdir(dest_src_dir)
src_files=glob.glob(pathdata['bridge_path']+'/cpp/*.cpp')+glob.glob(pathdata['bridge_path']+'/cpp/*.h')
for fl in src_files:
#open(dest_src_dir+'/'+os.path.basename(fl),'wb').write(open(fl).read().replace('PyServerPrivatePCH.h',pname+'.h').encode())
open(dest_src_dir+'/'+os.path.basename(fl),'wb').write(open(fl).read().encode())
fd=open(prj_src_path+'/PyServer/PyConfig.h','w')
print('//this is autogenerated file by build.py Dont Edit!!!',file=fd)
print('#pragma once',file=fd)
assert(os.path.isfile(include_path+'/Python.h'))
print('#include "'+include_path+'/Python.h"',file=fd)
fd.close()
fd=open(pathdata['project_path']+'/run.sh','w')
print('#!/bin/bash',file=fd)
print('#This is auto generated script Don\'t Edit!!!',file=fd)
print('cd '+uepath,file=fd)
print('export UEEDITOR_SO='+pathdata['project_path']+'/Binaries/Linux/libUnrealEditor-'+pname+'.so',file=fd)
print('export BRIDGE_ENTRY_NAME='+args.entry_point,file=fd)
print('export BRIDGE_ENTRY_PATH='+pathdata['entry_path'],file=fd)
print("""export PYTHON_LIB=`python3 -c"%s"`"""%pylibsearch,file=fd)
print("export SYSPATH="+file_dir+"/src",file=fd)
print('Engine/Binaries/Linux/UnrealEditor "'+pfile+'" -nocore -project='+pfile,file=fd)
fd.close()
assert(os.system('chmod +x '+pathdata['project_path']+'/run.sh')==0)
#
fd=open(pathdata['project_path']+'/build.sh','w')
cmd="mono "+uepath+'/Engine/Binaries/DotNET/UnrealBuildTool.exe '+pname+' Development Linux -project="'+pfile+\
'" -editorrecompile -progress -noubtmakefiles -NoHotReloadFromIDE'
print('#!/bin/bash',file=fd)
print(cmd,file=fd)
fd.close()
assert(os.system('chmod +x '+pathdata['project_path']+'/build.sh')==0)
if stand_alone_game:
fd=open(args.packed_game_path+'/run.sh','w')
print('#!/bin/bash',file=fd)
print('#This is auto generated script Don\'t Edit!!!',file=fd)
print('export BRIDGE_ENTRY_NAME='+args.entry_point,file=fd)
print('export BRIDGE_ENTRY_PATH='+pathdata['entry_path'],file=fd)
print("""export PYTHON_LIB=`python3 -c"%s"`"""%pylibsearch,file=fd)
print("export SYSPATH="+file_dir+"/src",file=fd)
pname=args.packed_game_name
prunfile=pname+'/Binaries/Linux/'+pname
print('chmod +x '+prunfile,file=fd)
print(prunfile+' $@',file=fd)
fd.close()
assert(os.system('chmod +x '+args.packed_game_path+'/run.sh')==0)