Skip to content

Commit

Permalink
Generate usage message copyright year automatically (#256)
Browse files Browse the repository at this point in the history
* Automate copyright year message generation

The copyright year displayed in cli usage messages is now automatically
generated when neko is compiled.

This required adding a `$neko_build_year()` builtin function to neko.

* Fix typo in nekoc help message
  • Loading branch information
tobil4sk authored Mar 27, 2023
1 parent ca4d761 commit 9aa2aae
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ set(NEKO_VERSION_MAJOR 2)
set(NEKO_VERSION_MINOR 4)
set(NEKO_VERSION_PATCH 0)

string(TIMESTAMP NEKO_BUILD_YEAR "%Y")

# NEKO_VERSION is cached such that we can query it by `cmake -L -N -B . | grep NEKO_VERSION`
set(NEKO_VERSION ${NEKO_VERSION_MAJOR}.${NEKO_VERSION_MINOR}.${NEKO_VERSION_PATCH} CACHE STRING INTERNAL)

Expand Down
3 changes: 2 additions & 1 deletion src/neko/Main.nml
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@ function complete(dir) {

try {
var v = Sys.version;
var head = "Neko Compiler v" + v.maj + "." + v.min + "." + v.build + " - (c)2005-2022 Haxe Foundation\n Usage : neko [options] files...";
var year : int = neko "$neko_build_year()";
var head = "Neko Compiler v" + v.maj + "." + v.min + "." + v.build + " - (c)2005-" + year + " Haxe Foundation\n Usage : nekoc [options] files...";
var link = &None;
var links = &[];
var version = &0;
Expand Down
3 changes: 2 additions & 1 deletion src/nekoml/Main.nml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ exception FileNotFound : string;

try {
var v = Sys.version;
var head = "NekoML Compiler v" + v.maj + "." + v.min + "." + v.build + " - (c)2005-2019 Haxe Foundation\n Usage : nekoml [options] files...";
var year : int = neko "$neko_build_year()";
var head = "NekoML Compiler v" + v.maj + "." + v.min + "." + v.build + " - (c)2005-" + year + " Haxe Foundation\n Usage : nekoml [options] files...";
var path = &[""];
var files = &[];
var neko = &false;
Expand Down
3 changes: 2 additions & 1 deletion src/tools/Tools.nml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ function invalid_arg(f) {
}

try {
var head = "Neko Tools v1.0 - (c)2005-2022 Haxe Foundation\nUsage : nekotools [options]";
var year : int = neko "$neko_build_year()";
var head = "Neko Tools v1.0 - (c)2005-" + year + " Haxe Foundation\nUsage : nekotools [options]";
var decl = [
("server", Args.Void (function() {
erase_argument();
Expand Down
9 changes: 9 additions & 0 deletions vm/builtins.c
Original file line number Diff line number Diff line change
Expand Up @@ -1507,6 +1507,14 @@ static value builtin_version() {
return alloc_int(NEKO_VERSION);
}

/**
$neko_build_year : void -> int
<doc>Return the year that Neko was compiled.</doc>
**/
static value builtin_neko_build_year() {
return alloc_int(NEKO_BUILD_YEAR);
}

/**
$setresolver : function:2? -> void
<doc>Set a function to callback with object and field id when an object field is not found.</doc>
Expand Down Expand Up @@ -1618,6 +1626,7 @@ void neko_init_builtins() {
BUILTIN(excstack,0);
BUILTIN(callstack,0);
BUILTIN(version,0);
BUILTIN(neko_build_year,0);
BUILTIN(setresolver,1);
}

Expand Down
2 changes: 1 addition & 1 deletion vm/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ int main( int argc, char *argv[] ) {
# ifdef NEKO_STANDALONE
report(vm,alloc_string("No embedded module in this executable"),0);
# else
printf("NekoVM %d.%d.%d (c)2005-2022 Haxe Foundation\n Usage : neko <file>\n",NEKO_VERSION_MAJOR,NEKO_VERSION_MINOR,NEKO_VERSION_PATCH);
printf("NekoVM %d.%d.%d (c)2005-%d Haxe Foundation\n Usage : neko <file>\n",NEKO_VERSION_MAJOR,NEKO_VERSION_MINOR,NEKO_VERSION_PATCH,NEKO_BUILD_YEAR);
# endif
mload = NULL;
r = 1;
Expand Down
2 changes: 2 additions & 0 deletions vm/neko.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@
#define NEKO_VERSION_PATCH @NEKO_VERSION_PATCH@
#define NEKO_VERSION @NEKO_VERSION_MAJOR@@NEKO_VERSION_MINOR@@NEKO_VERSION_PATCH@

#define NEKO_BUILD_YEAR @NEKO_BUILD_YEAR@

#define NEKO_MODULE_PATH "@NEKO_MODULE_PATH@"

typedef intptr_t int_val;
Expand Down

0 comments on commit 9aa2aae

Please sign in to comment.