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.
This commit is contained in:
Mike Welsh 2024-02-15 00:15:21 -08:00
parent 41b54fe7cc
commit 91ab1cb520
3 changed files with 17 additions and 34 deletions

View file

@ -113,7 +113,6 @@
<haxelib name="json2object" /> <!-- JSON parsing -->
<haxelib name="thx.semver" /> <!-- Version string handling -->
<haxelib name="hmm" /> <!-- Read library version data at compile time so it can be baked into logs -->
<haxelib name="hxcpp-debug-server" if="desktop debug" /> <!-- VSCode debug support -->
<!--Disable the Flixel core focus lost screen-->

View file

@ -64,11 +64,6 @@
"ref": "e9f880522e27134b29df4067f82df7d7e5237b70",
"url": "https://github.com/haxeui/haxeui-flixel"
},
{
"name": "hmm",
"type": "haxelib",
"version": "3.1.0"
},
{
"name": "hscript",
"type": "haxelib",

View file

@ -7,7 +7,7 @@ class HaxelibVersions
public static macro function getLibraryVersions():haxe.macro.Expr.ExprOf<Array<String>>
{
#if !display
return macro $v{formatHmmData(readHmmData())};
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.
@ -17,44 +17,33 @@ class HaxelibVersions
}
#if (macro)
static function readHmmData():hmm.HmmConfig
{
return hmm.HmmConfig.HmmConfigs.readHmmJsonOrThrow();
}
static function formatHmmData(hmmData:hmm.HmmConfig):Array<String>
@SuppressWarnings('checkstyle:Dynamic')
static function formatHmmData():Array<String>
{
var result:Array<String> = [];
for (library in hmmData.dependencies)
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)
switch (library.type)
{
case Haxelib(name, version):
result.push('${name} haxelib(${o(version)})');
case Git(name, url, ref, dir):
result.push('${name} git(${url}/${o(dir, '')}:${o(ref)})');
case Mercurial(name, url, ref, dir):
result.push('${name} mercurial(${url}/${o(dir, '')}:${o(ref)})');
case Dev(name, path):
result.push('${name} dev(${path})');
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 o(option:haxe.ds.Option<String>, defaultValue:String = 'None'):String
{
switch (option)
{
case Some(value):
return value;
case None:
return defaultValue;
}
}
static function readLibraryCurrentVersion(libraryName:String):String
{
var path = Path.join([Path.addTrailingSlash(Sys.getCwd()), '.haxelib', libraryName, '.current']);