Repository navigation
Expand file tree
/
Copy pathRunScript.hx
More file actions
211 lines (172 loc) · 5.27 KB
/
Copy pathRunScript.hx
File metadata and controls
211 lines (172 loc) · 5.27 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
package;
import hxp.Haxelib;
import hxp.Log;
import hxp.Path;
import hxp.System;
import sys.FileSystem;
import sys.io.File;
class RunScript
{
private static function rebuildTools(limeDirectory:String, toolsDirectory:String):Void
{
System.runCommand(limeDirectory, "haxe", ["run.hxml"]);
System.runCommand(toolsDirectory, "haxe", ["tools.hxml"]);
}
private static function rebuildAlias(limeDirectory:String, aliasDirectory:String):Void
{
var aliasTargetDirectory:String = Path.combine(limeDirectory, "templates/bin/alias/");
System.makeDirectory(aliasTargetDirectory);
function rebuildAliasExecutable(directoryName:String, architectureDefine:String, ?executableExtension:String):Void
{
var aliasTargetOutputDirectory:String = Path.combine(aliasTargetDirectory, directoryName);
System.makeDirectory(aliasTargetOutputDirectory);
var aliasTargetOutputFile:String = Path.combine(aliasTargetOutputDirectory, haxe.io.Path.withExtension('lime', executableExtension));
// Always clean rebuild it!
System.removeDirectory(Path.combine(aliasDirectory, 'obj'));
// -Dno-compilation so its doesnt print the command itself, stupid haxe
System.runCommand(aliasDirectory, "haxe", ["alias.hxml", "-D", architectureDefine, '-D', 'no-compilation']);
// We need to run this manually now!
System.runCommand(Path.combine(aliasDirectory, 'obj'), 'haxelib', ['run', 'hxcpp', 'Build.xml', '-options', 'Options.txt']);
var aliasOutput:String = Path.combine(aliasDirectory, haxe.io.Path.withExtension("obj/Alias", executableExtension));
if (FileSystem.exists(aliasOutput))
{
System.copyFile(Path.combine(aliasDirectory, haxe.io.Path.withExtension("obj/Alias", executableExtension)), aliasTargetOutputFile);
}
}
switch (System.hostPlatform)
{
case WINDOWS:
if (System.hostArchitecture == X64)
{
rebuildAliasExecutable('Windows64', 'HXCPP_M64', 'exe');
}
else if (System.hostArchitecture == X86)
{
rebuildAliasExecutable('Windows', 'HXCPP_M32', 'exe');
}
case MAC:
if (System.hostArchitecture == X64)
{
rebuildAliasExecutable('Mac64', 'HXCPP_M64');
}
else if (System.hostArchitecture == ARM64)
{
rebuildAliasExecutable('MacArm64', 'HXCPP_ARM64');
}
case LINUX:
if (System.hostArchitecture == ARMV7)
{
rebuildAliasExecutable('LinuxArm', 'HXCPP_ARMV7');
}
else if (System.hostArchitecture == ARM64)
{
rebuildAliasExecutable('LinuxArm64', 'HXCPP_ARM64');
}
else if (System.hostArchitecture == X64)
{
rebuildAliasExecutable('Linux64', 'HXCPP_M64');
}
}
}
public static function runCommand(path:String, command:String, args:Array<String>, throwErrors:Bool = true):Int
{
var oldPath:String = "";
if (path != null && path != "")
{
oldPath = Sys.getCwd();
try
{
Sys.setCwd(path);
}
catch (e:Dynamic)
{
Log.error("Cannot set current working directory to \"" + path + "\"");
}
}
final result:Int = Sys.command(command, args);
if (oldPath != "")
{
Sys.setCwd(oldPath);
}
if (throwErrors && result != 0)
{
Sys.exit(1);
}
return result;
}
public static function main()
{
final args:Array<String> = Sys.args();
if (args.length > 0)
{
var lastArgument:String = new Path(args[args.length - 1]).toString();
if (((StringTools.endsWith(lastArgument, "/") && lastArgument != "/") || StringTools.endsWith(lastArgument, "\\"))
&& !StringTools.endsWith(lastArgument, ":\\"))
{
lastArgument = lastArgument.substr(0, lastArgument.length - 1);
}
if (FileSystem.exists(lastArgument) && FileSystem.isDirectory(lastArgument))
{
Haxelib.workingDirectory = lastArgument;
}
}
var limeDirectory:String = Haxelib.getPath(new Haxelib("lime"), true);
var toolsDirectory:String = Path.combine(limeDirectory, "tools");
if (!FileSystem.exists(toolsDirectory))
{
limeDirectory = Path.combine(limeDirectory, "..");
toolsDirectory = Path.combine(limeDirectory, "tools");
}
if (args.length > 2 && args[0] == "rebuild" && (args[1] == "tools" || args[1] == "alias"))
{
final cacheDirectory:String = Sys.getCwd();
Sys.setCwd(Haxelib.workingDirectory);
for (arg in args)
{
final equals:Int = arg.indexOf("=");
if (equals > -1 && StringTools.startsWith(arg, "--"))
{
final argValue:String = arg.substr(equals + 1);
final field:String = arg.substr(2, equals - 2);
if (StringTools.startsWith(field, "haxelib-"))
{
Haxelib.pathOverrides.set(field.substr(8), Path.tryFullPath(argValue));
}
}
else if (StringTools.startsWith(arg, "-"))
{
switch (arg)
{
case "-v", "-verbose":
Log.verbose = true;
case "-nocolor":
Log.enableColor = false;
default:
}
}
}
if (args[1] == "alias")
{
rebuildAlias(limeDirectory, Path.combine(toolsDirectory, 'alias'));
}
else
{
rebuildTools(limeDirectory, toolsDirectory);
}
if (args.indexOf("-openfl") > -1)
{
Sys.setCwd(cacheDirectory);
}
else
{
Sys.exit(0);
}
}
final tools_n:String = Path.combine(toolsDirectory, "tools.n");
if (!FileSystem.exists(tools_n) || args.indexOf("-rebuild") > -1)
{
rebuildTools(limeDirectory, toolsDirectory);
}
Sys.exit(runCommand("", "neko", [tools_n].concat(args)));
}
}