2024-01-10 00:16:51 -05:00
|
|
|
package funkin.util.macro;
|
|
|
|
|
|
|
|
import haxe.io.Path;
|
|
|
|
|
|
|
|
class HaxelibVersions
|
|
|
|
{
|
|
|
|
public static macro function getLibraryVersions():haxe.macro.Expr.ExprOf<Array<String>>
|
|
|
|
{
|
|
|
|
#if !display
|
2024-02-15 03:15:21 -05:00
|
|
|
return macro $v{formatHmmData()};
|
2024-01-10 00:16:51 -05:00
|
|
|
#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)
|
2024-02-15 03:15:21 -05:00
|
|
|
@SuppressWarnings('checkstyle:Dynamic')
|
|
|
|
static function formatHmmData():Array<String>
|
2024-01-10 00:16:51 -05:00
|
|
|
{
|
|
|
|
var result:Array<String> = [];
|
|
|
|
|
2024-02-15 03:15:21 -05:00
|
|
|
var hmmData:Dynamic = haxe.Json.parse(sys.io.File.getContent('hmm.json'));
|
|
|
|
var dependencies:Array<Dynamic> = cast hmmData.dependencies;
|
|
|
|
for (library in dependencies)
|
2024-01-10 00:16:51 -05:00
|
|
|
{
|
2024-02-15 03:15:21 -05:00
|
|
|
switch (library.type)
|
2024-01-10 00:16:51 -05:00
|
|
|
{
|
2024-02-15 03:15:21 -05:00
|
|
|
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}';
|
2024-01-10 00:16:51 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|