-
Notifications
You must be signed in to change notification settings - Fork 10
/
script.hx
213 lines (180 loc) · 4.11 KB
/
script.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
package;
import hxp.*;
import sys.FileSystem;
class Script extends hxp.Script
{
private var samples:Array<String>;
public function new()
{
super();
initHXCPPCache();
samples = [];
findSamples("", samples);
samples.sort(function(a, b)
{
a = a.toLowerCase();
b = b.toLowerCase();
if (a < b) return -1;
if (a > b) return 1;
return 0;
});
switch (command)
{
case "list":
listSamples();
case "build", "run", "test", "update", "clean", "display":
execSamples();
default:
Log.error("Unkown command \"" + command + "\"");
}
}
private function initHXCPPCache():Void
{
if (!FileSystem.exists(".hxcpp_cache"))
{
System.mkdir(".hxcpp_cache");
}
if (!flags.exists("nocache"))
{
Sys.putEnv("HXCPP_COMPILE_CACHE", Path.tryFullPath(".hxcpp_cache"));
}
}
private function execSamples():Void
{
var paths = [];
if (commandArgs.length > 0)
{
var sampleName = commandArgs.shift();
for (sample in samples)
{
if (sample.split("/").pop() == sampleName)
{
paths.push(sample);
}
}
if (paths.length == 0 && sampleName == "all")
{
paths = samples.copy();
}
if (paths.length == 0)
{
for (sample in samples)
{
if (StringTools.startsWith(sample, sampleName))
{
paths.push(sample);
}
}
}
if (paths.length == 0)
{
for (sample in samples)
{
if (StringTools.startsWith(sample, Path.combine("haxelib", sampleName)))
{
paths.push(sample);
}
}
}
if (paths.length == 0)
{
Log.error("Could not find sample name \"" + sampleName + "\"");
}
}
else
{
paths = paths.concat(samples);
}
var targets = null;
if (commandArgs.length > 0)
{
targets = commandArgs;
}
else
{
var hostPlatform = switch (System.hostPlatform)
{
case WINDOWS: "windows";
case MAC: "mac";
case LINUX: "linux";
default: "";
}
targets = [];
if (!flags.exists("noneko")) targets.push("neko");
if (!flags.exists("noneko") && !flags.exists("nocairo")) targets.push("neko -Dcairo");
if (!flags.exists("noelectron")) targets.push("electron");
if (!flags.exists("noelectron") && !flags.exists("nocanvas")) targets.push("electron -Dcanvas");
if (!flags.exists("noelectron") && !flags.exists("nodom")) targets.push("electron -Ddom");
if (!flags.exists("nocpp")) targets.push(hostPlatform);
if (!flags.exists("noflash")) targets.push("flash");
}
for (path in paths)
{
var sampleName = path.split("/").pop();
for (target in targets)
{
var script = "lime";
var args = [command];
if (FileSystem.exists(Path.combine(path, "script.hx")))
{
script = "hxp";
args.push(Path.combine(path, "script.hx"));
if (target.split(" ")[0] == "electron") continue; // TODO, MinimalApplication
}
else
{
args.push(path);
}
Log.info(Log.accentColor + script + " " + command + " " + sampleName + " " + target + Log.resetColor);
args = args.concat(target.split(" "));
for (flag in flags.keys())
{
args.push("-" + flag);
}
for (define in defines.keys())
{
args.push("-D");
if (defines.get(define) != "")
{
args.push(define + "=" + defines.get(define));
}
else
{
args.push(define);
}
}
if (target == "flash" && targets.length > 1)
{
args.push("-notrace");
}
System.runCommand("", script, args);
}
}
}
private function findSamples(path:String, list:Array<String>):Void
{
for (fileName in FileSystem.readDirectory(path != "" ? path : Sys.getCwd()))
{
var filePath = Path.combine(path, fileName);
if (FileSystem.isDirectory(filePath))
{
if (FileSystem.exists(Path.combine(filePath, "project.xml")) || FileSystem.exists(Path.combine(filePath, "script.hx")))
{
list.push(Path.standardize(filePath));
}
else
{
findSamples(filePath, list);
}
}
}
}
private function listSamples():Void
{
for (sample in samples)
{
var sampleName = sample.split("/").pop();
Log.println(Log.accentColor + sampleName + Log.resetColor + " (" + sample + ")");
}
}
}