From 16b7db779fa7e5f1805c7566f208e5b7c25f366f Mon Sep 17 00:00:00 2001 From: Djeeberjr Date: Mon, 22 May 2023 22:36:11 +0200 Subject: [PATCH] use new lib: compiletime --- build.hxml | 1 + src/lib/BuildInfo.hx | 27 ++++++--------------------- src/lib/Debug.hx | 4 +--- 3 files changed, 8 insertions(+), 24 deletions(-) diff --git a/build.hxml b/build.hxml index 37538a4..ddae091 100644 --- a/build.hxml +++ b/build.hxml @@ -2,6 +2,7 @@ --library cctweaked:git:https://git.kapelle.org/niklas/cctweaked-haxelib.git --library tink_core +--library compiletime --dce full diff --git a/src/lib/BuildInfo.hx b/src/lib/BuildInfo.hx index b8f7020..bd15f78 100644 --- a/src/lib/BuildInfo.hx +++ b/src/lib/BuildInfo.hx @@ -7,36 +7,21 @@ class BuildInfo { /** Get the latest git commit. **/ - public static macro function getGitCommitHash():haxe.macro.Expr.ExprOf { + public static function getGitCommitHash():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}; + return CompileTime.buildGitCommitSha(); #end + return ""; } /** Get the time the file was build. **/ - public static macro function buildTime():haxe.macro.Expr.ExprOf { + public static function buildTime():Date { #if !display - return macro $v{Math.floor(Date.now().getTime())}; + return CompileTime.buildDate(); #else - return macro $v{0}; + return 0; #end } } diff --git a/src/lib/Debug.hx b/src/lib/Debug.hx index dc73cdf..eb97cb8 100644 --- a/src/lib/Debug.hx +++ b/src/lib/Debug.hx @@ -14,9 +14,7 @@ class Debug { public static function printBuildInfo() { Log.debug("Commit: " + BuildInfo.getGitCommitHash()); - var time:Date = Date.fromTime(BuildInfo.buildTime()); - - Log.debug("Build time: " + time.toString()); + Log.debug("Build time: " + BuildInfo.buildTime().toString()); Log.debug("CC/MC version:" + ComputerCraft._HOST); }