From f645673bae0f18dc1ad9cb4a99a41cbd05a34a66 Mon Sep 17 00:00:00 2001 From: Mattes D Date: Thu, 4 Jun 2015 12:23:38 +0200 Subject: [PATCH 1/4] APIDump: Added timestamp to all generated HTML pages. Ref.: #2204 --- MCServer/Plugins/APIDump/main.css | 2 +- MCServer/Plugins/APIDump/main_APIDump.lua | 29 ++++++++++++++++------- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/MCServer/Plugins/APIDump/main.css b/MCServer/Plugins/APIDump/main.css index 8041e0d01..e5685caab 100644 --- a/MCServer/Plugins/APIDump/main.css +++ b/MCServer/Plugins/APIDump/main.css @@ -61,7 +61,7 @@ footer font-family: Segoe UI Light, Helvetica; } -#content +#content, #timestamp { padding: 0px 25px 25px 25px; } diff --git a/MCServer/Plugins/APIDump/main_APIDump.lua b/MCServer/Plugins/APIDump/main_APIDump.lua index e841922b6..f1966d013 100644 --- a/MCServer/Plugins/APIDump/main_APIDump.lua +++ b/MCServer/Plugins/APIDump/main_APIDump.lua @@ -153,6 +153,16 @@ end +--- Returns the timestamp in HTML format +-- The timestamp will be inserted to all generated HTML files +local function GetHtmlTimestamp() + return string.format("
Generated on %s
", os.date("%Y-%m-%d %H:%M:%S")) +end + + + + + local function WriteArticles(f) f:write([[

Articles

@@ -296,7 +306,9 @@ local function WriteHtmlHook(a_Hook, a_HookNav) f:write("

", (example.Desc or "missing Desc"), "

\n"); f:write("
", (example.Code or "missing Code"), "\n
\n\n"); end - f:write([[]]); + f:write([[]]) + f:write(GetHtmlTimestamp()) + f:write([[]]) f:close(); end @@ -941,8 +953,10 @@ local function WriteHtmlClass(a_ClassAPI, a_ClassMenu) end end - cf:write([[]]); - cf:close(); + cf:write([[]]) + cf:write(GetHtmlTimestamp()) + cf:write([[]]) + cf:close() end @@ -1320,11 +1334,10 @@ local function DumpAPIHtml(a_API) WriteStats(f); - f:write([[ - - -]]); - f:close(); + f:write([[]]) + f:write(GetHtmlTimestamp()) + f:write([[]]) + f:close() LOG("API subfolder written"); end From 649921f4a822456921d460d5554ec46ee058a5d9 Mon Sep 17 00:00:00 2001 From: Mattes D Date: Fri, 5 Jun 2015 10:19:58 +0200 Subject: [PATCH 2/4] Provide some BuildInfo even for non-CI builds. Ref.: #2204 --- CMakeLists.txt | 27 +++++++++++++++++++++++++-- src/CMakeLists.txt | 1 + 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 81270438e..2a459b243 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,6 +24,7 @@ if(DEFINED ENV{TRAVIS_BUILD_WITH_COVERAGE}) endif() if(DEFINED ENV{MCSERVER_BUILD_ID}) + # The build info is defined by the build system (Travis / Jenkins) set(BUILD_ID $ENV{MCSERVER_BUILD_ID}) set(BUILD_SERIES_NAME $ENV{MCSERVER_BUILD_SERIES_NAME}) set(BUILD_DATETIME $ENV{MCSERVER_BUILD_DATETIME}) @@ -34,12 +35,34 @@ if(DEFINED ENV{MCSERVER_BUILD_ID}) execute_process( COMMAND git rev-parse HEAD RESULT_VARIABLE GIT_EXECUTED - OUTPUT_VARIABLE BUILD_COMMIT_ID) - string(STRIP ${BUILD_COMMIT_ID} BUILD_COMMIT_ID) + OUTPUT_VARIABLE BUILD_COMMIT_ID + ) + string(STRIP ${BUILD_COMMIT_ID} BUILD_COMMIT_ID) if (NOT (GIT_EXECUTED EQUAL 0)) message(FATAL_ERROR "Could not identifiy git commit id") endif() endif() +else() + # This is a local build, stuff in some basic info: + set(BUILD_ID "Unknown") + set(BUILD_SERIES_NAME "local build") + execute_process( + COMMAND git rev-parse HEAD + RESULT_VARIABLE GIT_EXECUTED + OUTPUT_VARIABLE BUILD_COMMIT_ID + ) + string(STRIP ${BUILD_COMMIT_ID} BUILD_COMMIT_ID) + execute_process( + COMMAND git log -1 --date=iso --pretty=format:%ai + OUTPUT_VARIABLE BUILD_DATETIME + ) + string(STRIP ${BUILD_DATETIME} BUILD_DATETIME) + + # The BUILD_COMMIT_ID and BUILD_DATETIME aren't updated on each repo pull + # They are only updated when cmake re-configures the project + # Therefore mark them as "approx: " + set(BUILD_COMMIT_ID "approx: ${BUILD_COMMIT_ID}") + set(BUILD_DATETIME "approx: ${BUILD_DATETIME}") endif() # We need C++11 features, Visual Studio has those from VS2012, but it needs a new platform toolset for those; VS2013 supports them natively: diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 5556ddc4d..c68795bb3 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -83,6 +83,7 @@ SET (HDRS BlockTracer.h Broadcaster.h BoundingBox.h + BuildInfo.h BuildInfo.h.cmake ByteBuffer.h ChatColor.h From 99b182b4bea0e845ca4c207f4ba6aad7ebbe626a Mon Sep 17 00:00:00 2001 From: Mattes D Date: Fri, 5 Jun 2015 10:34:13 +0200 Subject: [PATCH 3/4] Added Build info to the cRoot API. --- MCServer/Plugins/APIDump/APIDesc.lua | 10 ++-- MCServer/Plugins/APIDump/main_APIDump.lua | 5 +- src/Bindings/ManualBindings.cpp | 58 +++++++++++++++++++++-- 3 files changed, 65 insertions(+), 8 deletions(-) diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua index 4af01c0a4..f2b5d1ce8 100644 --- a/MCServer/Plugins/APIDump/APIDesc.lua +++ b/MCServer/Plugins/APIDump/APIDesc.lua @@ -2036,7 +2036,7 @@ a_Player:OpenWindow(Window); BroadcastChat = { { Params = "MessageText, MessageType", Return = "", Notes = "Broadcasts a message to all players, with its message type set to MessageType (default: mtCustom)." }, - { Params = "{{cCompositeChat|CompositeChat}}", Return = "", Notes = "Broadcasts a {{cCompositeChat|composite chat message} to all players." }, + { Params = "{{cCompositeChat|CompositeChat}}", Return = "", Notes = "Broadcasts a {{cCompositeChat|composite chat message}} to all players." }, }, BroadcastChatDeath = { Params = "MessageText", Return = "", Notes = "Broadcasts the specified message to all players, with its message type set to mtDeath. Use for when a player has died." }, BroadcastChatFailure = { Params = "MessageText", Return = "", Notes = "Broadcasts the specified message to all players, with its message type set to mtFailure. Use for a command that failed to run because of insufficient permissions, etc." }, @@ -2046,12 +2046,16 @@ a_Player:OpenWindow(Window); BroadcastChatLeave = { Params = "MessageText", Return = "", Notes = "Broadcasts the specified message to all players, with its message type set to mtLeave. Use for players leaving the server." }, BroadcastChatSuccess = { Params = "MessageText", Return = "", Notes = "Broadcasts the specified message to all players, with its message type set to mtSuccess. Use for success messages." }, BroadcastChatWarning = { Params = "MessageText", Return = "", Notes = "Broadcasts the specified message to all players, with its message type set to mtWarning. Use for concerning events, such as plugin reload etc." }, - CreateAndInitializeWorld = { Params = "WorldName", Return = "{{cWorld|cWorld}}", Notes = "Creates a new world and initializes it. If there is a world whith the same name it returns nil.

NOTEThis function is currently unsafe, do not use!" }, + CreateAndInitializeWorld = { Params = "WorldName", Return = "{{cWorld|cWorld}}", Notes = "Creates a new world and initializes it. If there is a world whith the same name it returns nil.

NOTE: This function is currently unsafe, do not use!" }, FindAndDoWithPlayer = { Params = "PlayerName, CallbackFunction", Return = "bool", Notes = "Calls the given callback function for the player with the name best matching the name string provided.
This function is case-insensitive and will match partial names.
Returns false if player not found or there is ambiguity, true otherwise. The CallbackFunction has the following signature:
function Callback({{cPlayer|Player}})
" }, DoWithPlayerByUUID = { Params = "PlayerUUID, CallbackFunction", Return = "bool", Notes = "If there is the player with the uuid, calls the CallbackFunction with the {{cPlayer}} parameter representing the player. The CallbackFunction has the following signature:
function Callback({{cPlayer|Player}})
The function returns false if the player was not found, or whatever bool value the callback returned if the player was found." }, ForEachPlayer = { Params = "CallbackFunction", Return = "", Notes = "Calls the given callback function for each player. The callback function has the following signature:
function Callback({{cPlayer|cPlayer}})
" }, ForEachWorld = { Params = "CallbackFunction", Return = "", Notes = "Calls the given callback function for each world. The callback function has the following signature:
function Callback({{cWorld|cWorld}})
" }, - Get = { Params = "", Return = "Root object", Notes = "(STATIC)This function returns the cRoot object." }, + Get = { Params = "", Return = "Root object", Notes = "(STATIC) This function returns the cRoot object." }, + GetBuildCommitID = { Params = "", Return = "string", Notes = "(STATIC) For official builds (Travis CI / Jenkins) it returns the exact commit hash used for the build. For unofficial local builds, returns the approximate commit hash (since the true one cannot be determined), formatted as \"approx: <CommitHash>\"." }, + GetBuildDateTime = { Params = "", Return = "string", Notes = "(STATIC) For official builds (Travic CI / Jenkins) it returns the date and time of the build. For unofficial local builds, returns the approximate datetime of the commit (since the true one cannot be determined), formatted as \"approx: <DateTime-iso8601>\"." }, + GetBuildID = { Params = "", Return = "string", Notes = "(STATIC) For official builds (Travis CI / Jenkins) it returns the unique ID of the build, as recognized by the build system. For unofficial local builds, returns the string \"Unknown\"." }, + GetBuildSeriesName = { Params = "", Return = "string", Notes = "(STATIC) For official builds (Travis CI / Jenkins) it returns the series name of the build (for example \"MCServer Windows x64 Master\"). For unofficial local builds, returns the string \"local build\"." }, GetCraftingRecipes = { Params = "", Return = "{{cCraftingRecipe|cCraftingRecipe}}", Notes = "Returns the CraftingRecipes object" }, GetDefaultWorld = { Params = "", Return = "{{cWorld|cWorld}}", Notes = "Returns the world object from the default world." }, GetFurnaceFuelBurnTime = { Params = "{{cItem|Fuel}}", Return = "number", Notes = "(STATIC) Returns the number of ticks for how long the item would fuel a furnace. Returns zero if not a fuel." }, diff --git a/MCServer/Plugins/APIDump/main_APIDump.lua b/MCServer/Plugins/APIDump/main_APIDump.lua index f1966d013..543a299af 100644 --- a/MCServer/Plugins/APIDump/main_APIDump.lua +++ b/MCServer/Plugins/APIDump/main_APIDump.lua @@ -156,7 +156,10 @@ end --- Returns the timestamp in HTML format -- The timestamp will be inserted to all generated HTML files local function GetHtmlTimestamp() - return string.format("
Generated on %s
", os.date("%Y-%m-%d %H:%M:%S")) + return string.format("
Generated on %s, Build ID %s, Commit %s
", + os.date("%Y-%m-%d %H:%M:%S"), + cRoot:GetBuildID(), cRoot:GetBuildCommitID() + ) end diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp index bce1891e2..7655d8c83 100644 --- a/src/Bindings/ManualBindings.cpp +++ b/src/Bindings/ManualBindings.cpp @@ -34,6 +34,7 @@ #include "../CompositeChat.h" #include "../StringCompression.h" #include "../CommandOutput.h" +#include "../BuildInfo.h" @@ -2079,6 +2080,50 @@ static int tolua_cLineBlockTracer_Trace(lua_State * tolua_S) +static int tolua_cRoot_GetBuildCommitID(lua_State * tolua_S) +{ + cLuaState L(tolua_S); + L.Push(BUILD_COMMIT_ID); + return 1; +} + + + + + +static int tolua_cRoot_GetBuildDateTime(lua_State * tolua_S) +{ + cLuaState L(tolua_S); + L.Push(BUILD_DATETIME); + return 1; +} + + + + + +static int tolua_cRoot_GetBuildID(lua_State * tolua_S) +{ + cLuaState L(tolua_S); + L.Push(BUILD_ID); + return 1; +} + + + + + +static int tolua_cRoot_GetBuildSeriesName(lua_State * tolua_S) +{ + cLuaState L(tolua_S); + L.Push(BUILD_SERIES_NAME); + return 1; +} + + + + + static int tolua_cRoot_GetFurnaceRecipe(lua_State * tolua_S) { cLuaState L(tolua_S); @@ -2092,7 +2137,8 @@ static int tolua_cRoot_GetFurnaceRecipe(lua_State * tolua_S) } // Check the input param: - cItem * Input = (cItem *)tolua_tousertype(L, 2, nullptr); + cItem * Input = nullptr; + L.GetStackValue(2, Input); if (Input == nullptr) { LOGWARNING("cRoot:GetFurnaceRecipe: the Input parameter is nil or missing."); @@ -2109,9 +2155,9 @@ static int tolua_cRoot_GetFurnaceRecipe(lua_State * tolua_S) } // Push the output, number of ticks and input as the three return values: - tolua_pushusertype(L, Recipe->Out, "const cItem"); - tolua_pushnumber (L, (lua_Number)(Recipe->CookTime)); - tolua_pushusertype(L, Recipe->In, "const cItem"); + L.Push(Recipe->Out); + L.Push(Recipe->CookTime); + L.Push(Recipe->In); return 3; } @@ -2868,6 +2914,10 @@ void cManualBindings::Bind(lua_State * tolua_S) tolua_function(tolua_S, "DoWithPlayerByUUID", DoWith ); tolua_function(tolua_S, "ForEachPlayer", ForEach); tolua_function(tolua_S, "ForEachWorld", ForEach); + tolua_function(tolua_S, "GetBuildCommitID", tolua_cRoot_GetBuildCommitID); + tolua_function(tolua_S, "GetBuildDateTime", tolua_cRoot_GetBuildDateTime); + tolua_function(tolua_S, "GetBuildID", tolua_cRoot_GetBuildID); + tolua_function(tolua_S, "GetBuildSeriesName", tolua_cRoot_GetBuildSeriesName); tolua_function(tolua_S, "GetFurnaceRecipe", tolua_cRoot_GetFurnaceRecipe); tolua_endmodule(tolua_S); From 5ee0657c6981a950e164ee2737d6057df6531a15 Mon Sep 17 00:00:00 2001 From: Mattes D Date: Fri, 5 Jun 2015 13:37:36 +0200 Subject: [PATCH 4/4] CMake: Added buildinfo workaround for src packs / systems without git. --- CMakeLists.txt | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2a459b243..01158a7e5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -51,11 +51,18 @@ else() RESULT_VARIABLE GIT_EXECUTED OUTPUT_VARIABLE BUILD_COMMIT_ID ) + if (NOT(GIT_EXECUTED EQUAL 0)) + set(BUILD_COMMIT_ID "Unknown") + endif() string(STRIP ${BUILD_COMMIT_ID} BUILD_COMMIT_ID) execute_process( COMMAND git log -1 --date=iso --pretty=format:%ai + RESULT_VARIABLE GIT_EXECUTED OUTPUT_VARIABLE BUILD_DATETIME ) + if (NOT(GIT_EXECUTED EQUAL 0)) + set(BUILD_DATETIME "Unknown") + endif() string(STRIP ${BUILD_DATETIME} BUILD_DATETIME) # The BUILD_COMMIT_ID and BUILD_DATETIME aren't updated on each repo pull