Merge branch 'main' into translations-system
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
package;
|
||||
|
||||
using StringTools;
|
||||
|
||||
class Utils {
|
||||
// trace(evaluateArgsCondition("hello && (world || world)", ["hello", "world"])); // true
|
||||
// trace(evaluateArgsCondition("hello && (!world || world)", ["hello"])); // true
|
||||
// trace(evaluateArgsCondition("hello && (!world && world)", ["hello", "world"])); // false
|
||||
public static function evaluateArgsCondition(condition:String, args:Array<String>):Bool {
|
||||
function evaluateToken(token:String):Bool {
|
||||
if (token.charAt(0) == '!') {
|
||||
return !args.contains(token.substr(1));
|
||||
} else {
|
||||
return args.contains(token);
|
||||
}
|
||||
}
|
||||
|
||||
condition = condition.replace('&&', '&').replace('||', '|').replace(" ", "");
|
||||
|
||||
var stack:Array<Dynamic> = [];
|
||||
var i = 0;
|
||||
|
||||
while (i < condition.length) {
|
||||
var char = condition.charAt(i);
|
||||
|
||||
switch (char) {
|
||||
case '(':
|
||||
var j = i;
|
||||
var balance = 1;
|
||||
while (balance != 0) {
|
||||
j++;
|
||||
if (condition.charAt(j) == '(') balance++;
|
||||
if (condition.charAt(j) == ')') balance--;
|
||||
}
|
||||
var subExpr = condition.substr(i + 1, j - i - 1);
|
||||
stack.push(evaluateArgsCondition(subExpr, args));
|
||||
i = j;
|
||||
case '&', '|':
|
||||
stack.push(char);
|
||||
default:
|
||||
var token = "";
|
||||
while (i < condition.length && condition.charAt(i) != '&' && condition.charAt(i) != '|' && condition.charAt(i) != '(' && condition.charAt(i) != ')') {
|
||||
token += condition.charAt(i);
|
||||
i++;
|
||||
}
|
||||
stack.push(evaluateToken(token));
|
||||
i--;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
return evaluate(stack);
|
||||
}
|
||||
|
||||
public static function evaluate(stack:Array<Dynamic>):Bool {
|
||||
var result = stack.shift();
|
||||
while (stack.length > 0) {
|
||||
var op = stack.shift();
|
||||
var next = stack.shift();
|
||||
switch(op) {
|
||||
case '&':
|
||||
result = result && next;
|
||||
case '|':
|
||||
result = result || next;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -15,21 +15,19 @@ class Compiler {
|
||||
}
|
||||
|
||||
private static function __build(args:Array<String>, arg:Array<String>) {
|
||||
arg.insert(0, "lime");
|
||||
arg.insert(0, "run");
|
||||
for(a in args)
|
||||
arg.push(a);
|
||||
Sys.command("lime", arg);
|
||||
Sys.command("haxelib", arg);
|
||||
}
|
||||
|
||||
public static function getBuildTarget() {
|
||||
return switch(Sys.systemName()) {
|
||||
case "Windows":
|
||||
"windows";
|
||||
case "Mac":
|
||||
"macos";
|
||||
case "Linux":
|
||||
"linux";
|
||||
case def:
|
||||
def.toLowerCase();
|
||||
case "Windows": "windows";
|
||||
case "Mac": "macos";
|
||||
case "Linux": "linux";
|
||||
case def: def.toLowerCase();
|
||||
}
|
||||
}
|
||||
}
|
||||
+177
-34
@@ -8,11 +8,9 @@ import sys.FileSystem;
|
||||
|
||||
class Update {
|
||||
public static function main(args:Array<String>) {
|
||||
prettyPrint("Preparing installation...");
|
||||
|
||||
var args = ArgParser.parse(args, ["S" => "silent-progress", "silent" => "silent-progress"]);
|
||||
var CHECK_VSTUDIO = !args.existsOption("no-vscheck");
|
||||
var REINSTALL_ALL = args.existsOption("all");
|
||||
var REINSTALL_ALL = args.existsOption("reinstall");
|
||||
var SILENT = args.existsOption("silent-progress");
|
||||
|
||||
// to prevent messing with currently installed libs
|
||||
@@ -24,46 +22,170 @@ class Update {
|
||||
FileSystem.createDirectory('.haxelib');
|
||||
}
|
||||
|
||||
var libs:Array<Library> = [];
|
||||
var libsXML:Access = new Access(Xml.parse(File.getContent('./libs.xml')).firstElement());
|
||||
var libFile = "./libs.xml";
|
||||
if(args.existsOption("lib")) {
|
||||
libFile = args.getOption("lib");
|
||||
if(libFile == null) {
|
||||
Sys.println('Please specify a file with the --lib option as --lib=path/to/libs.xml');
|
||||
return;
|
||||
}
|
||||
}
|
||||
if(!FileSystem.exists(libFile)) {
|
||||
Sys.println('File $libFile does not exist.');
|
||||
return;
|
||||
}
|
||||
|
||||
var events:Array<Event> = [];
|
||||
var libsXML:Access = new Access(Xml.parse(File.getContent(libFile)).firstElement());
|
||||
|
||||
function handleLib(libNode:Access) {
|
||||
switch(libNode.name) {
|
||||
case "lib" | "git":
|
||||
var lib:Library = {
|
||||
name: libNode.att.name,
|
||||
type: libNode.name
|
||||
};
|
||||
if (libNode.has.global) lib.global = libNode.att.global;
|
||||
switch (lib.type) {
|
||||
case "lib":
|
||||
if (libNode.has.version) lib.version = libNode.att.version;
|
||||
case "git":
|
||||
if (libNode.has.url) lib.url = libNode.att.url;
|
||||
if (libNode.has.ref) lib.ref = libNode.att.ref;
|
||||
}
|
||||
events.push({
|
||||
type: INSTALL,
|
||||
data: lib
|
||||
});
|
||||
case "cmd":
|
||||
|
||||
events.push({
|
||||
type: CMD,
|
||||
data: {
|
||||
inLib: libNode.has.inLib ? libNode.att.inLib : null,
|
||||
lines: {
|
||||
if(Lambda.count(libNode.nodes.line) > 0)
|
||||
[
|
||||
for(line in libNode.nodes.line)
|
||||
line.innerData
|
||||
];
|
||||
else
|
||||
[
|
||||
libNode.has.cmd ? libNode.att.cmd : "echo 'No command specified'"
|
||||
];
|
||||
}
|
||||
}
|
||||
});
|
||||
case "print":
|
||||
events.push({
|
||||
type: PRINT,
|
||||
data: {
|
||||
text: libNode.innerData,
|
||||
pretty: libNode.has.pretty && libNode.att.pretty == "true"
|
||||
}
|
||||
});
|
||||
default:
|
||||
Sys.println('Unknown library type ${libNode.name}');
|
||||
}
|
||||
}
|
||||
|
||||
var platform = switch(Sys.systemName()) {
|
||||
case "Windows": "windows";
|
||||
case "Mac": "mac";
|
||||
case "Linux": "linux";
|
||||
case def: def.toLowerCase();
|
||||
}
|
||||
|
||||
var defines = args.args.copy();
|
||||
defines.push(platform);
|
||||
if(args.args.length == 0) defines.push("all");
|
||||
|
||||
function parse(libNode:Access) {
|
||||
if(libNode.name == "if") {
|
||||
var cond = libNode.att.cond;
|
||||
if(!Utils.evaluateArgsCondition(cond, defines)) {
|
||||
return;
|
||||
}
|
||||
|
||||
for(child in libNode.elements) {
|
||||
parse(child);
|
||||
}
|
||||
} else {
|
||||
handleLib(libNode);
|
||||
}
|
||||
}
|
||||
|
||||
for (libNode in libsXML.elements) {
|
||||
var lib:Library = {
|
||||
name: libNode.att.name,
|
||||
type: libNode.name
|
||||
};
|
||||
if (libNode.has.global) lib.global = libNode.att.global;
|
||||
switch (lib.type) {
|
||||
case "lib":
|
||||
if (libNode.has.version) lib.version = libNode.att.version;
|
||||
case "git":
|
||||
if (libNode.has.url) lib.url = libNode.att.url;
|
||||
if (libNode.has.ref) lib.ref = libNode.att.ref;
|
||||
}
|
||||
libs.push(lib);
|
||||
parse(libNode);
|
||||
}
|
||||
|
||||
var commandSuffix = " --always";
|
||||
if (SILENT) commandSuffix += " --silent";
|
||||
|
||||
for(lib in libs) {
|
||||
var globalism:Null<String> = lib.global == "true" ? "--global" : null;
|
||||
var globalSuffix = globalism != null ? ' $globalism' : '';
|
||||
switch(lib.type) {
|
||||
case "lib":
|
||||
prettyPrint((lib.global == "true" ? "Globally installing" : "Locally installing") + ' "${lib.name}"...');
|
||||
Sys.command('haxelib install ${lib.name} ${lib.version != null ? " " + lib.version : " "}$globalSuffix$commandSuffix');
|
||||
case "git":
|
||||
prettyPrint((lib.global == "true" ? "Globally installing" : "Locally installing") + ' "${lib.name}" from git url "${lib.url}"');
|
||||
Sys.command('haxelib git ${lib.name} ${lib.url}${lib.ref != null ? ' ${lib.ref}' : ''}$globalSuffix$commandSuffix');
|
||||
case "custom":
|
||||
Sys.command('haxelib dev ${lib.name} "./libraries/${lib.name}"');
|
||||
default:
|
||||
prettyPrint('Cannot resolve library of type "${lib.type}"');
|
||||
for(event in events) {
|
||||
switch(event.type) {
|
||||
case INSTALL:
|
||||
var lib:Library = event.data;
|
||||
var globalism:Null<String> = lib.global == "true" ? "--global" : null;
|
||||
var globalSuffix = globalism != null ? ' $globalism' : '';
|
||||
switch(lib.type) {
|
||||
case "lib":
|
||||
prettyPrint((lib.global == "true" ? "Globally installing" : "Locally installing") + ' "${lib.name}"...');
|
||||
Sys.command('haxelib install ${lib.name} ${lib.version != null ? " " + lib.version : " "}$globalSuffix$commandSuffix');
|
||||
case "git":
|
||||
prettyPrint((lib.global == "true" ? "Globally installing" : "Locally installing") + ' "${lib.name}" from git url "${lib.url}"');
|
||||
Sys.command('haxelib git ${lib.name} ${lib.url}${lib.ref != null ? ' ${lib.ref}' : ''}$globalSuffix$commandSuffix');
|
||||
case "custom":
|
||||
Sys.command('haxelib dev ${lib.name} "./libraries/${lib.name}"');
|
||||
default:
|
||||
prettyPrint('Cannot resolve library of type "${lib.type}"');
|
||||
}
|
||||
case CMD:
|
||||
var cmd:CmdData = event.data;
|
||||
var lib = cmd.inLib;
|
||||
var oldCwd = Sys.getCwd();
|
||||
if(lib != null) {
|
||||
var libPrefix = '.haxelib/$lib';
|
||||
if(FileSystem.exists(libPrefix)) {
|
||||
if(FileSystem.exists(libPrefix + '/.dev')) { // haxelib dev
|
||||
var devPath = File.getContent(libPrefix + '/.dev');
|
||||
if(!FileSystem.exists(devPath)) {
|
||||
Sys.println('Cannot find dev path $devPath for $lib');
|
||||
Sys.setCwd(oldCwd);
|
||||
continue;
|
||||
}
|
||||
Sys.setCwd(devPath);
|
||||
} else if(FileSystem.exists(libPrefix + '/.current')) {
|
||||
var version = StringTools.replace(File.getContent(libPrefix + '/.current'), ".", ",");
|
||||
if(!FileSystem.exists(libPrefix + '/$version')) {
|
||||
Sys.println('Cannot find version $version of $lib');
|
||||
Sys.setCwd(oldCwd);
|
||||
continue;
|
||||
}
|
||||
Sys.setCwd(libPrefix + '/$version');
|
||||
} else {
|
||||
Sys.println('Cannot find .dev or .current file in $libPrefix');
|
||||
Sys.setCwd(oldCwd);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
for(line in cmd.lines) {
|
||||
var line = StringTools.replace(line, "$PLATFORM", platform);
|
||||
//Sys.println(line);
|
||||
Sys.command(line);
|
||||
}
|
||||
Sys.setCwd(oldCwd);
|
||||
case PRINT:
|
||||
var data:PrintData = event.data;
|
||||
if(data.pretty)
|
||||
prettyPrint(data.text);
|
||||
else
|
||||
Sys.println(data.text);
|
||||
}
|
||||
}
|
||||
|
||||
var proc = new Process('haxe --version');
|
||||
/*var proc = new Process('haxe --version');
|
||||
proc.exitCode(true);
|
||||
var haxeVer = proc.stdout.readLine();
|
||||
if (haxeVer != "4.2.5") {
|
||||
@@ -86,7 +208,7 @@ class Update {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
// vswhere.exe its used to find any visual studio related installations on the system, including full visual studio ide installations, visual studio build tools installations, and other related components - Nex
|
||||
if (CHECK_VSTUDIO && Compiler.getBuildTarget().toLowerCase() == "windows" && new Process('"C:/Program Files (x86)/Microsoft Visual Studio/Installer/vswhere.exe" -property catalog_productDisplayVersion').exitCode(true) == 1) {
|
||||
@@ -144,3 +266,24 @@ typedef Library = {
|
||||
var ?ref:String;
|
||||
var ?url:String;
|
||||
}
|
||||
|
||||
typedef Event = {
|
||||
var type:EventType;
|
||||
var data:Dynamic;
|
||||
}
|
||||
|
||||
typedef CmdData = {
|
||||
var ?inLib:String;
|
||||
var lines:Array<String>;
|
||||
}
|
||||
|
||||
typedef PrintData = {
|
||||
var text:String;
|
||||
var ?pretty:Bool;
|
||||
}
|
||||
|
||||
enum abstract EventType(Int) {
|
||||
var INSTALL = 0;
|
||||
var CMD = 1;
|
||||
var PRINT = 2;
|
||||
}
|
||||
Reference in New Issue
Block a user