forked from openfl/lime
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathPlatformTarget.hx
More file actions
256 lines (204 loc) · 5.9 KB
/
PlatformTarget.hx
File metadata and controls
256 lines (204 loc) · 5.9 KB
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
package lime.tools;
import haxe.rtti.Meta;
import hxp.*;
import lime.tools.AssetHelper;
import lime.tools.CommandHelper;
import sys.FileSystem;
import sys.io.File;
class PlatformTarget
{
public var additionalArguments:Array<String>;
public var buildType:String;
public var command:String;
public var noOutput:Bool;
public var project:HXProject;
public var targetDirectory:String;
public var targetFlags:Map<String, String>;
public var traceEnabled = true;
public function new(command:String = null, project:HXProject = null, targetFlags:Map<String, String> = null)
{
this.command = command;
this.project = project;
this.targetFlags = targetFlags;
buildType = "release";
if (project != null)
{
if (project.debug)
{
buildType = "debug";
}
else if (project.targetFlags.exists("final"))
{
buildType = "final";
}
}
for (haxeflag in project.haxeflags)
{
if (haxeflag == "--no-output")
{
noOutput = true;
}
}
}
public function execute(additionalArguments:Array<String>):Void
{
// Log.info ("", Log.accentColor + "Using target platform: " + Std.string (project.target).toUpperCase () + Log.resetColor);
this.additionalArguments = additionalArguments;
var metaFields = Meta.getFields(Type.getClass(this));
// known issue: this may not log in `-eval` mode on Linux
inline function logCommand(command:String):Void
{
if (!Reflect.hasField(metaFields, command)
|| !Reflect.hasField(Reflect.field(metaFields, command), "ignore"))
{
Log.info("", "\n" + Log.accentColor + "Running command: " + command.toUpperCase() + Log.resetColor);
}
}
if (project.targetFlags.exists("watch"))
{
Log.info("", "\n" + Log.accentColor + "Running command: WATCH" + Log.resetColor);
watch();
return;
}
if (command == "display")
{
display();
}
// if (command == "clean" || project.targetFlags.exists ("clean")) {
if (command == "clean"
|| (project.targetFlags.exists("clean") && (command == "update" || command == "build" || command == "test")))
{
logCommand("CLEAN");
clean();
}
if (command == "rebuild" || project.targetFlags.exists("rebuild"))
{
logCommand("REBUILD");
// hack for now, need to move away from project.rebuild.path, probably
if (project.targetFlags.exists("rebuild"))
{
project.config.set("project.rebuild.path", null);
}
rebuild();
}
if (command == "update" || command == "build" || command == "test")
{
logCommand("update");
_touchedFiles = [];
update();
deleteStaleFiles(_touchedFiles);
_touchedFiles = null;
}
if (command == "build" || command == "test")
{
CommandHelper.executeCommands(project.preBuildCallbacks);
logCommand("build");
build();
CommandHelper.executeCommands(project.postBuildCallbacks);
}
if (command == "deploy")
{
logCommand("deploy");
deploy();
}
if (command == "install" || command == "run" || command == "test")
{
logCommand("install");
install();
}
if (command == "run" || command == "rerun" || command == "test")
{
logCommand("run");
run();
}
if ((command == "test" || command == "trace" || command == "run" || command == "rerun")
&& (traceEnabled || command == "trace"))
{
logCommand("trace");
this.trace();
}
if (command == "uninstall")
{
logCommand("UNINSTALL");
uninstall();
}
}
@ignore public function build():Void {}
@ignore public function clean():Void {}
@ignore public function deploy():Void {}
@ignore public function display():Void {}
@ignore public function install():Void {}
@ignore public function rebuild():Void {}
@ignore public function run():Void {}
@ignore public function trace():Void {}
@ignore public function uninstall():Void {}
@ignore public function update():Void {}
@ignore public function watch():Void {}
// Functions to track and delete stale files
/**
Files that were copied into the output directory due to something in
project.xml, but which might not be included next time.
`PlatformTarget` will handle assets and templates, but subclasses are
responsible for adding any other files they copy (e.g., dependencies).
**/
private var _touchedFiles:Array<String> = null;
/**
Calls `System.copyIfNewer()` with the given arguments, then records the
file in `_touchedFiles`. See `_touchedFiles` for information about what
needs to be recorded.
**/
private function copyIfNewer(source:String, destination:String):Void
{
System.copyIfNewer(source, destination);
if (_touchedFiles != null)
{
_touchedFiles.push(destination);
}
}
private function deleteStaleFiles(touchedFiles:Array<String>):Void
{
if (project.defines.exists("lime-ignore-stale-files")) return;
for (asset in project.assets)
{
touchedFiles.push(targetDirectory + "/bin/" + asset.targetPath);
}
var record:String = targetDirectory + "/.files";
if (FileSystem.exists(record))
{
for (oldFile in File.getContent(record).split("\n"))
{
if (oldFile.length > 0 && touchedFiles.indexOf(oldFile) < 0)
{
System.deleteFile(oldFile);
}
}
}
File.saveContent(record, touchedFiles.join("\n"));
}
/**
Calls `System.recursiveCopy()` with the given arguments, then records
the files in `_touchedFiles`. See `_touchedFiles` for information about
what needs to be recorded.
**/
private function recursiveCopy(source:String, destination:String, context:Dynamic = null, process:Bool = true):Void
{
System.recursiveCopy(source, destination, context, process);
if (_touchedFiles == null || !FileSystem.exists(source)) return;
function recurse(source:String, destination:String):Void
{
for (file in FileSystem.readDirectory(source))
{
if (file.charAt(0) == ".") continue;
if (FileSystem.isDirectory(source + "/" + file))
{
recurse(source + "/" + file, destination + "/" + file);
}
else
{
_touchedFiles.push(destination + "/" + file);
}
}
}
recurse(source, destination);
}
}