-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild_dotnet.py
111 lines (97 loc) · 3.8 KB
/
build_dotnet.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
"""
Create / compile projects for .NET version of rhino3dm
"""
import os
import sys
import fileinput
import shutil
def system(cmd):
# copied from setup.py
rv = os.system(cmd)
rc = rv if os.name == 'nt' else os.WEXITSTATUS(rv)
if (rc != 0):
raise RuntimeError('The command "{}" exited with {}'.format(cmd, rc))
def methodgen(dotnetcore):
# set up args to pass to methodgen application
dir_cpp = os.getcwd() + '/librhino3dmio_native'
dir_cs = os.getcwd() + '/dotnet'
path_replace = '../lib/opennurbs'
args = ' "{0}" "{1}" "{2}"'.format(dir_cpp, dir_cs, path_replace)
if dotnetcore:
# staging and compilation occurs in the build directory
build_dir = "build/methodgen"
if not os.path.exists(build_dir):
if(not os.path.exists("build")):
os.mkdir("build")
os.mkdir(build_dir)
src_files = os.listdir('./methodgen')
for file_name in src_files:
if file_name.endswith('.cs'):
full_path = os.path.join('./methodgen', file_name)
if os.path.isfile(full_path):
shutil.copy(full_path, build_dir)
if file_name.endswith('.core'):
full_path = os.path.join('./methodgen', file_name)
if os.path.isfile(full_path):
shutil.copy(full_path, build_dir + '/methodgen.csproj')
# compile methodgen
system('dotnet build ' + './' + build_dir)
# execute methodgen
system('dotnet ./'+build_dir+'/bin/Debug/netcoreapp2.2/methodgen.dll '+ args)
else:
# compile methodgen
system('msbuild ./methodgen')
# execute methodgen for Rhino3dm
app = os.getcwd() + '/methodgen/bin/Debug/methodgen.exe'
if os.name == 'nt': # windows build
system(app + args)
else:
system('mono ' + app + args)
def create_cpp_project(bitness, compile):
# staging and compilation occurs in the build directory
build_dir = "build/librhino3dmio_native_{0}".format(bitness)
if not os.path.exists(build_dir):
if(not os.path.exists("build")):
os.mkdir("build")
os.mkdir(build_dir)
os.chdir(build_dir)
if os.name == 'nt': # windows build
arch = ""
if bitness == 64:
arch = " Win64"
args = '-G "Visual Studio 15 2017{0}"'.format(arch)
system('cmake ' + args + ' ../../librhino3dmio_native')
if bitness == 64:
for line in fileinput.input("librhino3dmio_native.vcxproj", inplace=1):
print(line.replace("WIN32;", "WIN64;"))
for line in fileinput.input("opennurbs_static.vcxproj", inplace=1):
print(line.replace("WIN32;", "WIN64;"))
if compile:
system("cmake --build . --config Release --target librhino3dmio_native")
else:
system("cmake ../../librhino3dmio_native")
if compile:
system("make")
os.chdir("../..")
def compilerhino3dm(dotnetcore):
if dotnetcore:
conf = '/p:Configuration=Release;OutDir="../build/dotnet"'
system('dotnet build ./dotnet/Rhino3dm.core.csproj {}'.format(conf))
else:
conf = '/p:Configuration=Release;OutDir="../build/dotnet"'
system('msbuild ./dotnet/Rhino3dm.csproj {}'.format(conf))
if __name__ == '__main__':
dotnetcore = False
if len(sys.argv)>1 and sys.argv[1]=='--core':
dotnetcore = True
if sys.platform.startswith('linux'):
dotnetcore = True
# always compile and run methodgen first to make sure the pinvoke
# definitions are in place
methodgen(dotnetcore)
# only create 32 bit compile on windows
if os.name == 'nt':
create_cpp_project(32, True)
create_cpp_project(64, True)
# compile Rhino3dm .NET project
compilerhino3dm(dotnetcore)