Skip to content

Commit

Permalink
Convert lime.tools.Architecture to enum abstract.
Browse files Browse the repository at this point in the history
This improves compatibility with `hxp.HostArchitecture` and provides a more user-friendly API than `try { Type.createEnum() }`.
  • Loading branch information
player-03 committed Jan 28, 2024
1 parent a414f64 commit 3453c51
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 25 deletions.
69 changes: 59 additions & 10 deletions src/lime/tools/Architecture.hx
Original file line number Diff line number Diff line change
@@ -1,14 +1,63 @@
package lime.tools;

enum Architecture
import hxp.HostArchitecture;

#if (haxe_ver >= 4.0) enum #else @:enum #end abstract Architecture(String) to String
{
ARMV5;
ARMV6;
ARMV7;
ARMV7S;
ARM64;
X86;
X64;
MIPS;
MIPSEL;
var ARMV5 = "ARMV5";
var ARMV6 = "ARMV6";
var ARMV7 = "ARMV7";
var ARMV7S = "ARMV7S";
var ARM64 = "ARM64";
var X86 = "X86";
var X64 = "X64";
var MIPS = "MIPS";
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;
}
}
}
12 changes: 6 additions & 6 deletions src/lime/tools/ProjectXMLParser.hx
Original file line number Diff line number Diff line change
Expand Up @@ -1330,21 +1330,21 @@ class ProjectXMLParser extends HXProject
case "architecture":
if (element.has.name)
{
var name = substitute(element.att.name);
var name:Architecture = substitute(element.att.name).toUpperCase();

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)
{
var exclude = substitute(element.att.exclude);
var exclude:Architecture = substitute(element.att.exclude).toUpperCase();

if (Reflect.hasField(Architecture, exclude.toUpperCase()))
if (exclude != null)
{
ArrayTools.addUnique(excludeArchitectures, Reflect.field(Architecture, exclude.toUpperCase()));
ArrayTools.addUnique(excludeArchitectures, exclude);
}
}

Expand Down
13 changes: 4 additions & 9 deletions tools/CommandLineTools.hx
Original file line number Diff line number Diff line change
Expand Up @@ -2221,17 +2221,12 @@ class CommandLineTools
{
if (argument.substr(0, 4) == "-arm")
{
try
{
var name = argument.substr(1).toUpperCase();
var value = Type.createEnum(Architecture, name);
var value:Architecture = argument.substr(1).toUpperCase();

if (value != null)
{
overrides.architectures.push(value);
}
if (value != null)
{
overrides.architectures.push(value);
}
catch (e:Dynamic) {}
}
else if (argument == "-64")
{
Expand Down

0 comments on commit 3453c51

Please sign in to comment.