mirror of
https://github.com/ninjamuffin99/Funkin.git
synced 2025-03-21 09:29:41 +00:00
POV i learning how macros work
This commit is contained in:
parent
bc86724393
commit
3f84a5514f
|
@ -22,10 +22,11 @@ class Constants
|
|||
|
||||
#if debug
|
||||
public static final GIT_HASH = funkin.util.macro.GitCommit.getGitCommitHash();
|
||||
public static final GIT_BRANCH = funkin.util.macro.GitCommit.getGitBranch();
|
||||
|
||||
static function get_VERSION():String
|
||||
{
|
||||
return 'v${Application.current.meta.get('version')} (${GIT_HASH})' + VERSION_SUFFIX;
|
||||
return 'v${Application.current.meta.get('version')} (${GIT_BRANCH} : ${GIT_HASH})' + VERSION_SUFFIX;
|
||||
}
|
||||
#else
|
||||
static function get_VERSION():String
|
||||
|
|
|
@ -31,5 +31,31 @@ class GitCommit
|
|||
return macro $v{commitHashSplice};
|
||||
#end
|
||||
}
|
||||
|
||||
public static macro function getGitBranch():haxe.macro.Expr.ExprOf<String>
|
||||
{
|
||||
#if !display
|
||||
// Get the current line number.
|
||||
var pos = haxe.macro.Context.currentPos();
|
||||
var branchProcess = new sys.io.Process('git', ['rev-parse', '--abbrev-ref', 'HEAD']);
|
||||
|
||||
if (branchProcess.exitCode() != 0)
|
||||
{
|
||||
var message = branchProcess.stderr.readAll().toString();
|
||||
haxe.macro.Context.info('[WARN] Could not determine current git commit; is this a proper Git repository?', pos);
|
||||
}
|
||||
|
||||
var branchName:String = branchProcess.stdout.readLine();
|
||||
trace('Current Working Branch: ${branchName}');
|
||||
|
||||
// Generates a string expression
|
||||
return macro $v{branchName};
|
||||
#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 branchName:String = "";
|
||||
return macro $v{branchName};
|
||||
#end
|
||||
}
|
||||
}
|
||||
#end
|
||||
|
|
Loading…
Reference in a new issue