Convert lime.tools.Architecture to enum abstract. (#1754)
* Convert `lime.tools.Architecture` to `enum abstract`.
This improves compatibility with `hxp.HostArchitecture` and provides a more user-friendly API than `try { Type.createEnum() }`.
* Add category functions to `Architecture`.
* Fix errors related to `Architecture`'s new type.
* Standardize formatting.
* Re-implement `Architecture.match()` for backwards compatibility.
* Add `Architecture` constructor for clarity.
This commit is contained in:
@@ -1,14 +1,104 @@
|
|||||||
package lime.tools;
|
package lime.tools;
|
||||||
|
|
||||||
enum Architecture
|
import haxe.macro.Expr;
|
||||||
|
import hxp.HostArchitecture;
|
||||||
|
|
||||||
|
#if (haxe_ver >= 4.0) enum #else @:enum #end abstract Architecture(String) to String
|
||||||
|
|
||||||
{
|
{
|
||||||
ARMV5;
|
var ARMV5 = "ARMV5";
|
||||||
ARMV6;
|
var ARMV6 = "ARMV6";
|
||||||
ARMV7;
|
var ARMV7 = "ARMV7";
|
||||||
ARMV7S;
|
var ARMV7S = "ARMV7S";
|
||||||
ARM64;
|
var ARM64 = "ARM64";
|
||||||
X86;
|
var X86 = "X86";
|
||||||
X64;
|
var X64 = "X64";
|
||||||
MIPS;
|
var MIPS = "MIPS";
|
||||||
MIPSEL;
|
var MIPSEL = "MIPSEL";
|
||||||
|
|
||||||
|
public static function exists(architecture:String):Bool
|
||||||
|
{
|
||||||
|
switch (architecture)
|
||||||
|
{
|
||||||
|
case ARMV5, ARMV6, ARMV7, ARMV7S, ARM64, X86, X64, MIPS, MIPSEL:
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@:from private static function fromHostArchitecture(hostArchitecture:HostArchitecture):Architecture
|
||||||
|
{
|
||||||
|
if (hostArchitecture == HostArchitecture.ARMV6)
|
||||||
|
{
|
||||||
|
return ARMV6;
|
||||||
|
}
|
||||||
|
else if (hostArchitecture == HostArchitecture.ARMV7)
|
||||||
|
{
|
||||||
|
return ARMV7;
|
||||||
|
}
|
||||||
|
else if (hostArchitecture == HostArchitecture.ARM64)
|
||||||
|
{
|
||||||
|
return ARM64;
|
||||||
|
}
|
||||||
|
else if (hostArchitecture == HostArchitecture.X86)
|
||||||
|
{
|
||||||
|
return X86;
|
||||||
|
}
|
||||||
|
else /* if (hostArchitecture == HostArchitecture.X64) */
|
||||||
|
{
|
||||||
|
return X64;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@:from private static function fromString(string:String):Architecture
|
||||||
|
{
|
||||||
|
if (exists(string))
|
||||||
|
{
|
||||||
|
return cast string;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Returns the given `Architecture` if available, or `null` otherwise.
|
||||||
|
**/
|
||||||
|
public inline function new(name:String)
|
||||||
|
{
|
||||||
|
this = fromString(name.toUpperCase());
|
||||||
|
}
|
||||||
|
|
||||||
|
public inline function is64():Bool
|
||||||
|
{
|
||||||
|
return this == ARM64 || this == X64;
|
||||||
|
}
|
||||||
|
|
||||||
|
public inline function isARM():Bool
|
||||||
|
{
|
||||||
|
return this.indexOf("ARM") == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public inline function isMIPS():Bool
|
||||||
|
{
|
||||||
|
return this == MIPS || this == MIPSEL;
|
||||||
|
}
|
||||||
|
|
||||||
|
public inline function isX():Bool
|
||||||
|
{
|
||||||
|
return this == X86 || this == X64;
|
||||||
|
}
|
||||||
|
|
||||||
|
@:noCompletion public macro function match(self:Expr, expr:Expr):Expr
|
||||||
|
{
|
||||||
|
return macro switch ($self)
|
||||||
|
{
|
||||||
|
case $expr:
|
||||||
|
true;
|
||||||
|
default:
|
||||||
|
false;
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1160,21 +1160,21 @@ class ProjectXMLParser extends HXProject
|
|||||||
case "architecture":
|
case "architecture":
|
||||||
if (element.has.name)
|
if (element.has.name)
|
||||||
{
|
{
|
||||||
var name = substitute(element.att.name);
|
var name = new Architecture(substitute(element.att.name));
|
||||||
|
|
||||||
if (Reflect.hasField(Architecture, name.toUpperCase()))
|
if (name != null)
|
||||||
{
|
{
|
||||||
ArrayTools.addUnique(architectures, Reflect.field(Architecture, name.toUpperCase()));
|
ArrayTools.addUnique(architectures, name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (element.has.exclude)
|
if (element.has.exclude)
|
||||||
{
|
{
|
||||||
var exclude = substitute(element.att.exclude);
|
var exclude = new Architecture(substitute(element.att.exclude));
|
||||||
|
|
||||||
if (Reflect.hasField(Architecture, exclude.toUpperCase()))
|
if (exclude != null)
|
||||||
{
|
{
|
||||||
ArrayTools.addUnique(excludeArchitectures, Reflect.field(Architecture, exclude.toUpperCase()));
|
ArrayTools.addUnique(excludeArchitectures, exclude);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2234,17 +2234,12 @@ class CommandLineTools
|
|||||||
{
|
{
|
||||||
if (argument.substr(0, 4) == "-arm")
|
if (argument.substr(0, 4) == "-arm")
|
||||||
{
|
{
|
||||||
try
|
var value = new Architecture(argument.substr(1));
|
||||||
{
|
|
||||||
var name = argument.substr(1).toUpperCase();
|
|
||||||
var value = Type.createEnum(Architecture, name);
|
|
||||||
|
|
||||||
if (value != null)
|
if (value != null)
|
||||||
{
|
{
|
||||||
overrides.architectures.push(value);
|
overrides.architectures.push(value);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (e:Dynamic) {}
|
|
||||||
}
|
}
|
||||||
else if (argument == "-64")
|
else if (argument == "-64")
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -112,10 +112,10 @@ class MacPlatform extends PlatformTarget
|
|||||||
project.architectures.remove(excludeArchitecture);
|
project.architectures.remove(excludeArchitecture);
|
||||||
}
|
}
|
||||||
|
|
||||||
targetArchitecture = Type.createEnum(Architecture, Type.enumConstructor(System.hostArchitecture));
|
targetArchitecture = System.hostArchitecture;
|
||||||
for (architecture in project.architectures)
|
for (architecture in project.architectures)
|
||||||
{
|
{
|
||||||
if (architecture.match(X86 | X64 | ARMV6 | ARMV7 | ARM64))
|
if (architecture.isARM() || architecture.isX())
|
||||||
{
|
{
|
||||||
targetArchitecture = architecture;
|
targetArchitecture = architecture;
|
||||||
break;
|
break;
|
||||||
|
|||||||
Reference in New Issue
Block a user