1
0
Fork 0
mirror of https://github.com/ninjamuffin99/Funkin.git synced 2024-11-05 22:34:36 +00:00
Funkin/source/funkin/util/macro/HaxelibVersions.hx
Mike Welsh 91ab1cb520 Remove hmm dependency to fix HTML5 target
Remove the `hmm` haxelib dependency from the build.

Linking to `hmm` caused `utest` to be transitively linked, which
eventually caused OpenFL to act strangely and instatiate the
application twice on the HTML5 target.

`hmm` was only used for `HaxelibVersions.getLibraryVersions` macro
call. Instead, manually parse the `hmm.json` ourselves to avoid
the dependency. This fixes the HTML5 target.

`hmm` is still used for package management, but no longer linked
in to the build itself.
2024-02-15 00:23:24 -08:00

57 lines
1.7 KiB
Haxe

package funkin.util.macro;
import haxe.io.Path;
class HaxelibVersions
{
public static macro function getLibraryVersions():haxe.macro.Expr.ExprOf<Array<String>>
{
#if !display
return macro $v{formatHmmData()};
#else
// `#if display` is used for code completion. In this case returning an
// empty string is good enough; We don't want to call functions on every hint.
var commitHash:Array<String> = [];
return macro $v{commitHash};
#end
}
#if (macro)
@SuppressWarnings('checkstyle:Dynamic')
static function formatHmmData():Array<String>
{
var result:Array<String> = [];
var hmmData:Dynamic = haxe.Json.parse(sys.io.File.getContent('hmm.json'));
var dependencies:Array<Dynamic> = cast hmmData.dependencies;
for (library in dependencies)
{
switch (library.type)
{
case 'haxelib':
result.push('${library.name} haxelib(${library.version ?? 'None'})');
case 'git':
result.push('${library.name} git(${library.url}/${library.dir ?? ''}:${library.ref ?? 'None'}');
case 'mercurial':
result.push('${library.name} mercurial(${library.url}/${library.dir ?? ''}:${library.ref ?? 'None'})');
case 'dev':
result.push('${library.name} dev(${library.path})');
case ty:
throw 'Unhandled hmm library type ${ty}';
}
}
return result;
}
static function readLibraryCurrentVersion(libraryName:String):String
{
var path = Path.join([Path.addTrailingSlash(Sys.getCwd()), '.haxelib', libraryName, '.current']);
// This is compile time so we should always have Sys available.
var result = sys.io.File.getContent(path);
return result;
}
#end
}