This repository has been archived by the owner on Nov 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCSHelper.hx
268 lines (218 loc) · 5.6 KB
/
CSHelper.hx
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
package lime.tools;
import hxp.*;
import lime.tools.Architecture;
import lime.tools.HXProject;
import sys.io.File;
import sys.FileSystem;
using StringTools;
class CSHelper
{
public static var ndllSourceFiles:Array<String> = [
"cs.ndll.NDLLFunction", "cs.ndll.CFFICSLoader", "cs.ndll.CSAbstract", "cs.ndll.CSHandleContainer", "cs.ndll.CSHandleScope", "cs.ndll.CSPersistent",
"cs.ndll.DelegateConverter", "cs.ndll.HandleUtils", "cs.ndll.NativeMethods", "cs.ndll.NDLLFunction",
];
private static function getAndroidABIName(arch:Architecture):String
{
var name = switch (arch)
{
case ARMV5:
"armeabi";
case ARMV7:
"armeabi-v7a";
case ARM64:
"arm64-v8a";
case X86:
"x86";
case X64:
"x86_64";
case _:
null;
}
if (name == null)
{
throw "Unsupported architecture:" + arch;
}
return name;
}
public static function getAndroidABINames(architectures:Array<Architecture>):String
{
var result = "";
var first = true;
for (arch in architectures)
{
if (first)
{
first = false;
}
else
{
result += ",";
}
var archName = getAndroidABIName(arch);
result += archName;
}
return result;
}
public static function getAndroidNativeLibraryPaths(libPath:String, libraries:Array<NDLL>, architectures:Array<Architecture>):Array<String>
{
var paths = [];
for (arch in architectures)
{
var archName = getAndroidABIName(arch);
for (lib in libraries)
{
paths.push(FileSystem.absolutePath(libPath + "/" + archName + "/" + "lib" + lib.name + ".so").replace("/", "\\"));
}
}
return paths;
}
public static function copySourceFiles(templatePaths:Array<String>, targetPath:String)
{
System.recursiveCopyTemplate(templatePaths, "cs/src", targetPath);
}
public static function addSourceFiles(txtPath:String, sourceFiles:Array<String>)
{
if (sourceFiles.length == 0)
{
return;
}
var file = File.append(txtPath, false);
file.writeString('\nbegin modules\n');
for (fileName in sourceFiles)
{
file.writeString('M $fileName\nC $fileName\n');
}
file.writeString('end modules\n');
file.close();
}
public static function addAndroidResources(txtPath:String, resources:Array<String>)
{
if (resources.length == 0)
{
return;
}
var file = File.append(txtPath, false);
file.writeString('\nbegin android_resources\n');
for (resource in resources)
{
file.writeString('$resource\n');
}
file.writeString('end android_resources\n');
file.close();
}
public static function addAssemblies(txtPath:String, assemblies:Array<String>)
{
if (assemblies.length == 0)
{
return;
}
var file = File.append(txtPath, false);
file.writeString('\nbegin libs\n');
for (assembly in assemblies)
{
file.writeString(assembly.replace("/", "\\") + '\n');
}
file.writeString('end libs\n');
file.close();
}
public static function addNativeLibraries(txtPath:String, libPath:String, libraries:Array<NDLL>, architectures:Array<Architecture>)
{
if (libraries.length == 0)
{
return;
}
var file = File.append(txtPath, false);
file.writeString('\nbegin native_libs\n');
for (arch in architectures)
{
var archName = getAndroidABIName(arch);
for (lib in libraries)
{
file.writeString(FileSystem.absolutePath(libPath + "/" + archName + "/" + "lib" + lib.name + ".so").replace("/", "\\") + '\n');
}
}
file.writeString('end native_libs\n');
file.close();
}
public static function addAndroidABIs(txtPath:String, architectures:Array<Architecture>)
{
if (architectures.length == 0)
{
return;
}
var file = File.append(txtPath, false);
file.writeString('\nbegin android_abis\n');
for (arch in architectures)
{
var archName = getAndroidABIName(arch);
file.writeString(archName + '\n');
}
file.writeString('end android_abis\n');
file.close();
}
public static function addAssets(txtPath:String, assets:Array<String>)
{
if (assets.length == 0)
{
return;
}
var file = File.append(txtPath, false);
file.writeString('\nbegin android_assets\n');
for (asset in assets)
{
file.writeString(FileSystem.absolutePath(asset).replace("/", "\\") + '\n');
}
file.writeString('end android_assets\n');
file.close();
}
public static function addGUID(txtPath:String, guid:String)
{
var file = File.append(txtPath, false);
file.writeString('\nbegin guid\n');
file.writeString('$guid\n');
file.writeString('end guid\n');
file.close();
}
public static function compile(project:HXProject, path:String, outPath:String, arch:String, platform:String, buildFile:String = "hxcs_build.txt",
noCompile:Bool = false)
{
var args = [
"run",
project.config.getString("cs.buildLibrary", "hxcs"),
buildFile,
"--arch",
arch,
"--platform",
platform,
"--out",
outPath,
"--unsafe"
];
if (noCompile) args.push("--no-compile");
var code = Haxelib.runCommand(path, args);
if (code != 0)
{
Sys.exit(code);
}
}
public static function buildGradleProj(path:String)
{
var gradlePath = FileSystem.absolutePath(path + "/" + "gradlew");
System.runCommand(path, gradlePath, ["build", "assembleRelease"]);
}
inline public static function buildSln(path:String, slnPath:String, task:String = null)
{
buildCSProj(path, slnPath, task);
}
public static function buildCSProj(path:String, csprojPath:String, task:String = null)
{
var msBuildPath = "C:/Program Files (x86)/MSBuild/14.0/Bin/MSBuild.exe";
var absCSProjPath = FileSystem.absolutePath(csprojPath);
var args = [absCSProjPath, "/p:Configuration=Release"];
if (task != null)
{
args.push("/t:" + task);
}
System.runCommand(path, msBuildPath, args);
}
}