-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.hxp
352 lines (288 loc) · 10.3 KB
/
build.hxp
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
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
import hxp.*;
import haxe.Timer;
class Build extends Script {
public function new() {
super();
switch command {
case 'build':
command_build();
Log.info('Task completed.');
case 'buildall':
command_buildAll();
Log.info('Task completed.');
case 'test':
command_test();
case 'run':
command_run();
default:
Log.info('Cuttlefish Build Tool - Help
Commands:
build [list of target flags] - Builds Cuttlefish for all targets listed
buildall - Builds Cuttlefish for all targets. Shortcut for `build` followed by all target flags
run <target> - Runs the most recent build available of Cuttlefish for the provided target
test <target> - Builds and then runs Cuttlefish for the provided target. Shortcut for `build -<target>` then `run <target>`');
}
}
function getProjectVersion():String {
return System.readText('./version.txt');
}
function command_build() {
if (flags.get('all')) {
Log.warn('Consider using the `buildall` command instead of the `-all` target flag to build for all targets.');
command_buildAll();
return;
}
var hasAny = false;
if (flags.get('cpp') || flags.get('c++') || flags.get('cplusplus')) {
build_cpp();
hasAny = true;
}
if (flags.get('cs') || flags.get('csharp')) {
build_csharp();
hasAny = true;
}
if (flags.get('hl') || flags.get('hashlink')) {
build_hashlink();
hasAny = true;
}
if (flags.get('java')) {
build_java();
hasAny = true;
}
if (flags.get('node') || flags.get('js') || flags.get('nodejs')) {
build_nodejs();
hasAny = true;
}
if (flags.get('jvm')) {
build_jvm();
hasAny = true;
}
if (flags.get('neko')) {
build_neko();
hasAny = true;
}
if (flags.get('py') || flags.get('python')) {
build_python();
hasAny = true;
}
if (!hasAny) {
Log.error('No targets specified.');
}
}
function command_buildAll() {
Log.info('Building all targets');
build_cpp();
build_csharp();
build_hashlink();
build_java();
//build_nodejs(); // hxnodejs doesnt support threads
build_jvm();
build_neko();
build_python();
}
function createBaseHXML():HXML {
var hxml = new HXML({cp: ['src'], main: 'Main', libs: ['uuid']});
if (flags.get('debug')) hxml.debug = true;
return hxml;
}
function getExecutableName(target:String, arch:HostArchitecture, windows:Bool=false, debug:Bool=false) {
var name = 'Cuttlefish';
if (debug) name += '.dev';
name += '-${getProjectVersion()}';
name += switch target {
case 'cpp': '.cpp';
case 'csharp': '.cs';
case 'hashlink': '.hl';
case 'java': '.jar';
case 'nodejs': 'js';
case 'jvm': '.jvm.jar';
case 'neko': '.n';
case 'python': '.py';
default: throw 'unknown target';
}
if (['cpp', 'csharp'].contains(target)) {
name += switch arch {
case ARMV6: '.armv6';
case ARMV7: '.armv7';
case X86: '.x86';
case X64: '.x64';
};
if (windows) name += '.exe';
}
return name;
}
function build_cpp() {
Log.info('Building C++');
var hxml = createBaseHXML();
hxml.cpp = './build/cpp/';
hxml.build();
var executablePath = './build/cpp/Main';
if (flags.get('debug')) executablePath += '-debug';
if (System.hostPlatform == WINDOWS) executablePath += '.exe';
var targetName = getExecutableName('cpp', System.hostArchitecture, System.hostPlatform == WINDOWS, flags.get('debug'));
//System.copyFile('./build/cpp/$executablePath', './out/$targetName');
System.copyFile(executablePath, './out/$targetName');
System.runCommand('./out/', 'chmod', ['a+x', targetName]);
}
function build_csharp() {
Log.info('Building C#');
var hxml = createBaseHXML();
hxml.cs = './build/csharp/';
try {
hxml.build();
} catch (e:haxe.Exception) {
trace(e.stack);
Log.error('Failed to build C#');
return;
}
var executablePath = './build/csharp/bin/Main';
if (flags.get('debug')) executablePath += '-Debug';
//if (System.hostPlatform == WINDOWS) executablePath += '.exe';
executablePath += '.exe';
//var targetName = getExecutableName('csharp', System.hostArchitecture, System.hostPlatform == WINDOWS, flags.get('debug'));
var targetName = getExecutableName('csharp', System.hostArchitecture, true, flags.get('debug'));
System.copyFile(executablePath, './out/$targetName');
if (hxml.debug) System.copyFile('$executablePath.mdb', './out/$targetName.mdb');
}
function build_hashlink() {
Log.info('Building Hashlink');
var hxml = createBaseHXML();
hxml.hl = './build/hashlink/Cuttlefish.hl';
hxml.build();
var targetName = getExecutableName('hashlink', System.hostArchitecture, System.hostPlatform == WINDOWS, flags.get('debug'));
System.copyFile('./build/hashlink/Cuttlefish.hl', './out/$targetName');
}
function build_jvm() {
Log.info('Building JVM Bytecode');
var hxml = createBaseHXML();
hxml.java = './build/jvm/';
hxml.define('jvm', true);
hxml.build();
var targetName = getExecutableName('jvm', System.hostArchitecture, System.hostPlatform == WINDOWS, flags.get('debug'));
System.copyFile('./build/jvm/${flags.get('debug') ? 'Main-Debug' : 'Main'}.jar', './out/$targetName');
}
function build_nodejs() {
throw 'NodeJS is currently not supported! hxnodejs doesnt support threads!';
}
function build_java() {
Log.info('Building Java');
var hxml = createBaseHXML();
hxml.java = './build/java/';
hxml.build();
var targetName = getExecutableName('java', System.hostArchitecture, System.hostPlatform == WINDOWS, flags.get('debug'));
System.copyFile('./build/java/${flags.get('debug') ? 'Main-Debug.jar' : 'Main.jar'}', './out/$targetName');
}
function build_neko() {
Log.info('Building Neko');
var hxml = createBaseHXML();
hxml.neko = './build/neko/Cuttlefish.n';
hxml.build();
var targetName = getExecutableName('neko', System.hostArchitecture, System.hostPlatform == WINDOWS, flags.get('debug'));
System.copyFile('./build/neko/Cuttlefish.n', './out/$targetName');
}
function build_python() {
Log.info('Building Python');
var hxml = createBaseHXML();
hxml.python = './build/python/Cuttlefish.py';
hxml.build();
var targetName = getExecutableName('python', System.hostArchitecture, System.hostPlatform == WINDOWS, flags.get('debug'));
System.copyFile('./build/python/Cuttlefish.py', './out/$targetName');
}
function command_test() {
switch commandArgs[0] {
case 'cpp': test_cpp();
case 'cplusplus': test_cpp();
case 'c++': test_cpp();
case 'cs': test_csharp();
case 'csharp': test_csharp();
case 'c#': test_csharp();
case 'hl': test_hashlink();
case 'hashlink': test_hashlink();
case 'java': test_java();
case 'nodejs': test_nodejs();
case 'node': test_nodejs();
case 'js': test_nodejs();
case 'jvm': test_jvm();
case 'neko': test_neko();
case 'python': test_python();
case 'py': test_python();
}
}
function test_cpp() {
build_cpp();
run_cpp();
}
function test_csharp() {
build_csharp();
run_csharp();
}
function test_hashlink() {
build_hashlink();
run_hashlink();
}
function test_java() {
build_java();
run_java();
}
function test_nodejs() {
build_nodejs();
run_nodejs();
}
function test_jvm() {
build_jvm();
run_jvm();
}
function test_neko() {
build_neko();
run_neko();
}
function test_python() {
build_python();
run_python();
}
function command_run() {
switch commandArgs[0] {
case 'cpp': run_cpp();
case 'cplusplus': run_cpp();
case 'c++': run_cpp();
case 'cs': run_csharp();
case 'csharp': run_csharp();
case 'c#': run_csharp();
case 'hl': run_hashlink();
case 'hashlink': run_hashlink();
case 'java': run_java();
case 'nodejs': run_nodejs();
case 'node': run_nodejs();
case 'js': run_nodejs();
case 'jvm': run_jvm();
case 'neko': run_neko();
case 'python': run_python();
case 'py': run_python();
}
}
function run_cpp() {
System.runCommand('./out/', './' + getExecutableName('cpp', System.hostArchitecture, System.hostPlatform == WINDOWS, flags.get('debug')));
}
function run_csharp() {
if (System.hostPlatform == WINDOWS) System.runCommand('./out/', getExecutableName('csharp', System.hostArchitecture, true, flags.get('debug')));
else System.runCommand('./out/', 'wine', [getExecutableName('csharp', System.hostArchitecture, true, flags.get('debug'))]);
}
function run_hashlink() {
System.runCommand('./out/', 'hl', [getExecutableName('hashlink', System.hostArchitecture, System.hostPlatform == WINDOWS, flags.get('debug'))]);
}
function run_java() {
System.runCommand('./out/', 'java', ['-jar', getExecutableName('java', System.hostArchitecture, System.hostPlatform == WINDOWS, flags.get('debug'))]);
}
function run_nodejs() {
// idk lol!
}
function run_jvm() {
System.runCommand('./out/', 'java', ['-jar', getExecutableName('jvm', System.hostArchitecture, System.hostPlatform == WINDOWS, flags.get('debug'))]);
}
function run_neko() {
System.runCommand('./out/', 'neko', [getExecutableName('neko', System.hostArchitecture, System.hostPlatform == WINDOWS, flags.get('debug'))]);
}
function run_python() {
System.runCommand('./out/', 'python3', [getExecutableName('python', System.hostArchitecture, System.hostPlatform == WINDOWS, flags.get('debug'))]);
}
}