forked from FunkinDroidTeam/lime
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProjectHelper.hx
205 lines (173 loc) · 5.32 KB
/
ProjectHelper.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
package lime.tools;
import hxp.*;
import sys.io.File;
import sys.FileSystem;
#if neko
import neko.Lib;
#elseif cpp
import cpp.Lib;
#end
class ProjectHelper
{
// private static var doubleVarMatch = new EReg ("\\$\\${(.*?)}", "");
private static var varMatch = new EReg("{{(.*?)}}", "");
public static function copyLibrary(project:HXProject, ndll:NDLL, directoryName:String, namePrefix:String, nameSuffix:String, targetDirectory:String,
allowDebug:Bool = false, targetSuffix:String = null)
{
var path = NDLL.getLibraryPath(ndll, directoryName, namePrefix, nameSuffix, allowDebug);
if (FileSystem.exists(path))
{
var targetPath = Path.combine(targetDirectory, namePrefix + ndll.name);
if (targetSuffix != null)
{
targetPath += targetSuffix;
}
else
{
targetPath += nameSuffix;
}
if (project.config.getBool("tools.copy-ndlls"))
{
Log.info("", " - \x1b[1mCopying library file:\x1b[0m " + path + " \x1b[3;37m->\x1b[0m " + targetPath);
System.mkdir(targetDirectory);
try
{
File.copy(path, targetPath);
}
catch (e:Dynamic)
{
Log.error("Cannot copy to \"" + targetPath + "\", is the file in use?");
}
}
else
{
Log.info("", " - \x1b[1mSkipping library file:\x1b[0m " + path + " \x1b[3;37m->\x1b[0m " + targetPath);
}
}
else
{
Log.error("Source path \"" + path + "\" does not exist");
}
}
public static function getCurrentCommand():String
{
var args = Sys.args();
args.remove("-watch");
if (Haxelib.pathOverrides.exists("lime-tools"))
{
var tools = Haxelib.pathOverrides.get("lime-tools");
return "neko " + tools + "/tools.n " + args.join(" ");
}
else
{
args.pop();
return "lime " + args.join(" ");
}
}
public static function recursiveSmartCopyTemplate(project:HXProject, source:String, destination:String, context:Dynamic = null, process:Bool = true,
warnIfNotFound:Bool = true)
{
var destinations = [];
var paths = System.findTemplateRecursive(project.templatePaths, source, warnIfNotFound, destinations);
if (paths != null)
{
System.mkdir(destination);
var itemDestination;
for (i in 0...paths.length)
{
itemDestination = Path.combine(destination, ProjectHelper.substitutePath(project, destinations[i]));
System.copyFile(paths[i], itemDestination, context, process);
}
}
}
public static function replaceVariable(project:HXProject, string:String):String
{
if (string.substr(0, 8) == "haxelib:")
{
var path = Haxelib.getPath(new Haxelib(string.substr(8)), true);
return Path.standardize(path);
}
else if (project.defines.exists(string))
{
return project.defines.get(string);
}
else if (project.environment != null && project.environment.exists(string))
{
return project.environment.get(string);
}
// TODO: Should we start phasing this out?
else if (string == "projectDirectory")
{
Log.info("", "Consider using ${project.workingDirectory} instead of ${projectDirectory}.");
return project.workingDirectory;
}
else
{
var substring = StringTools.replace(string, " ", "");
var index, value;
if (substring.indexOf("==") > -1)
{
index = substring.indexOf("==");
value = ProjectHelper.replaceVariable(project, substring.substr(0, index));
return Std.string(value == substring.substr(index + 2));
}
else if (substring.indexOf("!=") > -1)
{
index = substring.indexOf("!=");
value = ProjectHelper.replaceVariable(project, substring.substr(0, index));
return Std.string(value != substring.substr(index + 2));
}
else if (substring.indexOf("<=") > -1)
{
index = substring.indexOf("<=");
value = ProjectHelper.replaceVariable(project, substring.substr(0, index));
return Std.string(value <= substring.substr(index + 2));
}
else if (substring.indexOf("<") > -1)
{
index = substring.indexOf("<");
value = ProjectHelper.replaceVariable(project, substring.substr(0, index));
return Std.string(value < substring.substr(index + 1));
}
else if (substring.indexOf(">=") > -1)
{
index = substring.indexOf(">=");
value = ProjectHelper.replaceVariable(project, substring.substr(0, index));
return Std.string(value >= substring.substr(index + 2));
}
else if (substring.indexOf(">") > -1)
{
index = substring.indexOf(">");
value = ProjectHelper.replaceVariable(project, substring.substr(0, index));
return Std.string(value > substring.substr(index + 1));
}
else if (substring.indexOf(".") > -1)
{
var fields = substring.split(".");
if (fields[0] == "project") fields.shift();
var object:Dynamic = project;
while (object != null && fields.length > 0)
{
object = Reflect.getProperty(object, fields.shift());
}
if (object != null && object != project)
{
return Std.string(object);
}
}
}
return string;
}
public static function substitutePath(project:HXProject, path:String):String
{
var newString = path;
// while (doubleVarMatch.match (newString)) {
// newString = doubleVarMatch.matchedLeft () + "${" + ProjectHelper.replaceVariable (this, doubleVarMatch.matched (1)) + "}" + doubleVarMatch.matchedRight ();
// }
while (varMatch.match(newString))
{
newString = varMatch.matchedLeft() + ProjectHelper.replaceVariable(project, varMatch.matched(1)) + varMatch.matchedRight();
}
return newString;
}
}