another big refactor

This commit is contained in:
2022-12-19 21:06:23 +01:00
parent 3cb1811dcb
commit a6ed7818da
45 changed files with 85 additions and 95 deletions

42
src/lib/BuildInfo.hx Normal file
View File

@@ -0,0 +1,42 @@
package lib;
/**
Macros with static information.
**/
class BuildInfo {
/**
Get the latest git commit.
**/
public static macro function getGitCommitHash():haxe.macro.Expr.ExprOf<String> {
#if !display
var process = new sys.io.Process('git', ['rev-parse', 'HEAD']);
if (process.exitCode() != 0) {
var message = process.stderr.readAll().toString();
var pos = haxe.macro.Context.currentPos();
haxe.macro.Context.error("Cannot execute `git rev-parse HEAD`. " + message, pos);
}
// read the output of the process
var commitHash:String = process.stdout.readLine();
// Generates a string expression
return macro $v{commitHash};
#else
// `#if display` is used for code completion. In this case returning an
// empty string is good enough; We don't want to call git on every hint.
var commitHash:String = "";
return macro $v{commitHash};
#end
}
/**
Get the time the file was build.
**/
public static macro function buildTime():haxe.macro.Expr.ExprOf<Int> {
#if !display
return macro $v{Math.floor(Date.now().getTime())};
#else
return macro $v{0};
#end
}
}