diff options
author | fireice-uk <fireice-uk@users.noreply.github.com> | 2017-11-14 11:01:57 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-11-14 11:01:57 +0000 |
commit | 288363814fb091ccfc452f0408bfa53727fc30c0 (patch) | |
tree | e460f1baa5d8436dee82c671ab9758be999fc1ef | |
parent | b1645f6e26a7f1d0d907b4911ddf4ac6bc933166 (diff) | |
parent | 04e4d28c98a76e9b0982674fdeb9f27a82a6790e (diff) | |
download | xmr-stak-288363814fb091ccfc452f0408bfa53727fc30c0.zip xmr-stak-288363814fb091ccfc452f0408bfa53727fc30c0.tar.gz |
Merge pull request #103 from fireice-uk/topic-versioning
Versioning
-rw-r--r-- | .gitattributes | 1 | ||||
-rw-r--r-- | CMakeLists.txt | 36 | ||||
-rw-r--r-- | doc/usage.md | 2 | ||||
-rw-r--r-- | xmrstak/cli/cli-miner.cpp | 25 | ||||
-rw-r--r-- | xmrstak/http/webdesign.cpp | 13 | ||||
-rw-r--r-- | xmrstak/misc/executor.cpp | 12 | ||||
-rw-r--r-- | xmrstak/net/jpsock.cpp | 4 | ||||
-rw-r--r-- | xmrstak/version.cpp | 52 | ||||
-rw-r--r-- | xmrstak/version.hpp | 19 |
9 files changed, 146 insertions, 18 deletions
diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..71ed00d --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +xmrstak/version.cpp export-subst diff --git a/CMakeLists.txt b/CMakeLists.txt index 656abe0..6e0f282 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -74,7 +74,7 @@ if(CUDA_ENABLE) find_package(CUDA 7.5) if(CUDA_FOUND) - + list(APPEND BACKEND_TYPES "nvidia") option(XMR-STAK_LARGEGRID "Support large CUDA block count > 128" ON) if(XMR-STAK_LARGEGRID) add_definitions("-DXMR_STAK_LARGEGRID=${XMR-STAK_LARGEGRID}") @@ -244,6 +244,7 @@ if(OpenCL_ENABLE) # find package will use the previews searched path variables find_package(OpenCL) if(OpenCL_FOUND) + list(APPEND BACKEND_TYPES "amd") include_directories(SYSTEM ${OpenCL_INCLUDE_DIRS}) #set(LIBS ${LIBS} ${OpenCL_LIBRARY}) link_directories(${OpenCL_LIBRARY}) @@ -261,6 +262,8 @@ endif() option(CPU_ENABLE "Enable or disable CPU support" ON) if(NOT CPU_ENABLE) add_definitions("-DCONF_NO_CPU") +else() + list(APPEND BACKEND_TYPES "cpu") endif() ################################################################################ @@ -370,6 +373,37 @@ if(WIN32) endif() ################################################################################ +# Versioning +################################################################################ + +# Get the current working branch +execute_process( + COMMAND git rev-parse --abbrev-ref HEAD + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + OUTPUT_VARIABLE GIT_BRANCH + OUTPUT_STRIP_TRAILING_WHITESPACE +) + +# Get the latest abbreviated commit hash of the working branch +execute_process( + COMMAND git log -1 --format=%h + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + OUTPUT_VARIABLE GIT_COMMIT_HASH + OUTPUT_STRIP_TRAILING_WHITESPACE +) + +if(NOT "${GIT_COMMIT_HASH}" STREQUAL "") + add_definitions("-DGIT_COMMIT_HASH=${GIT_COMMIT_HASH}") +endif() +if(NOT "${GIT_BRANCH}" STREQUAL "") + add_definitions("-DGIT_BRANCH=${GIT_BRANCH}") +endif() + +# generate backend string +string(REPLACE ";" "-" STR_BACKEND_TYPES "${BACKEND_TYPES}") +add_definitions("-DBACKEND_TYPE=${STR_BACKEND_TYPES}") + +################################################################################ # Compile & Link ################################################################################ diff --git a/doc/usage.md b/doc/usage.md index a0fd871..ca379ab 100644 --- a/doc/usage.md +++ b/doc/usage.md @@ -32,6 +32,8 @@ The miner allow to overwrite some of the settings via command line options. Usage: xmr-stak [OPTION]... -h, --help show this help + -v, --version show version number + -V, --version-long show long version number -c, --config FILE common miner configuration file --currency NAME currency to mine: monero or aeon --noCPU disable the CPU miner backend diff --git a/xmrstak/cli/cli-miner.cpp b/xmrstak/cli/cli-miner.cpp index 5c16c1b..284cf4a 100644 --- a/xmrstak/cli/cli-miner.cpp +++ b/xmrstak/cli/cli-miner.cpp @@ -63,6 +63,8 @@ void help() cout<<"Usage: "<<params::inst().binaryName<<" [OPTION]..."<<endl; cout<<" "<<endl; cout<<" -h, --help show this help"<<endl; + cout<<" -v, --version show version number"<<endl; + cout<<" -V, --version-long show long version number"<<endl; cout<<" -c, --config FILE common miner configuration file"<<endl; #if (!defined(CONF_NO_AEON)) && (!defined(CONF_NO_MONERO)) cout<<" --currency NAME currency to mine: monero or aeon"<<endl; @@ -85,7 +87,7 @@ void help() cout<<" -u, --user USERNAME pool user name or wallet address"<<endl; cout<<" -p, --pass PASSWD pool password, in the most cases x or empty \"\""<<endl; cout<<" \n"<<endl; - cout<<XMR_STAK_NAME<<" "<<XMR_STAK_VERSION<<endl; + cout<< "Version: " << get_version_str_short() << endl; cout<<"Brought to by fireice_uk and psychocrypt under GPLv3."<<endl; } @@ -296,6 +298,16 @@ int main(int argc, char *argv[]) //win_exit(); return 0; } + if(opName.compare("-v") == 0 || opName.compare("--version") == 0) + { + std::cout<< "Version: " << get_version_str_short() << std::endl; + return 0; + } + else if(opName.compare("-V") == 0 || opName.compare("--version-long") == 0) + { + std::cout<< "Version: " << get_version_str() << std::endl; + return 0; + } else if(opName.compare("--noCPU") == 0) { params::inst().useCPU = false; @@ -433,17 +445,18 @@ int main(int argc, char *argv[]) #endif printer::inst()->print_str("-------------------------------------------------------------------\n"); - printer::inst()->print_str( XMR_STAK_NAME" " XMR_STAK_VERSION " mining software.\n"); + printer::inst()->print_str(get_version_str_short().c_str()); + printer::inst()->print_str("\n\n"); + printer::inst()->print_str("Brought to you by fireice_uk and psychocrypt under GPLv3.\n"); printer::inst()->print_str("Based on CPU mining code by wolf9466 (heavily optimized by fireice_uk).\n"); #ifndef CONF_NO_CUDA - printer::inst()->print_str("NVIDIA mining code was written by KlausT and psychocrypt.\n"); + printer::inst()->print_str("Based on NVIDIA mining code by KlausT and psychocrypt.\n"); #endif #ifndef CONF_NO_OPENCL - printer::inst()->print_str("AMD mining code was written by wolf9466.\n"); + printer::inst()->print_str("Based on OpenCL mining code by wolf9466.\n"); #endif - printer::inst()->print_str("Brought to you by fireice_uk and psychocrypt under GPLv3.\n\n"); char buffer[64]; - snprintf(buffer, sizeof(buffer), "Configurable dev donation level is set to %.1f %%\n\n", fDevDonationLevel * 100.0); + snprintf(buffer, sizeof(buffer), "\nConfigurable dev donation level is set to %.1f%%\n\n", fDevDonationLevel * 100.0); printer::inst()->print_str(buffer); printer::inst()->print_str("You can use following keys to display reports:\n"); printer::inst()->print_str("'h' - hashrate\n"); diff --git a/xmrstak/http/webdesign.cpp b/xmrstak/http/webdesign.cpp index 1cb76c3..3c33e1f 100644 --- a/xmrstak/http/webdesign.cpp +++ b/xmrstak/http/webdesign.cpp @@ -1,6 +1,6 @@ #include <stdlib.h> -extern const char sHtmlCssEtag [] = "00000006"; +extern const char sHtmlCssEtag [] = "00000008"; extern const char sHtmlCssFile [] = "body {" "font-family: Tahoma, Arial, sans-serif;" @@ -38,7 +38,13 @@ extern const char sHtmlCssFile [] = "color: white;" "padding: 10px;" "font-weight: bold;" - "margin: 10px 0px;" + "margin: 0px;" + "margin-bottom: 10px;" + "}" + + ".version {" + "font-size: 75%;" + "text-align: right;" "}" ".links {" @@ -108,6 +114,7 @@ extern const char sHtmlCommonHeader [] = "<link rel='stylesheet' href='style.css' /><title>%s</title></head>" "<body>" "<div class='all'>" + "<div class='version'>%s</div>" "<div class='header'><span style='color: rgb(255, 160, 0)'>XMR</span>-Stak Monero Miner</div>" "<div class='flex-container'>" @@ -192,6 +199,8 @@ extern const char sJsonApiConnectionError[] = extern const char sJsonApiFormat [] = "{" + "\"version\":\"%s\"," + "\"hashrate\":{" "\"threads\":[%s]," "\"total\":%s," diff --git a/xmrstak/misc/executor.cpp b/xmrstak/misc/executor.cpp index c568fe9..454d1cf 100644 --- a/xmrstak/misc/executor.cpp +++ b/xmrstak/misc/executor.cpp @@ -34,6 +34,7 @@ #include "xmrstak/jconf.hpp" #include "xmrstak/misc/console.hpp" #include "xmrstak/donate-level.hpp" +#include "xmrstak/version.hpp" #include "xmrstak/http/webdesign.hpp" #include <thread> @@ -44,6 +45,7 @@ #include <assert.h> #include <time.h> + #ifdef _WIN32 #define strncasecmp _strnicmp #endif // _WIN32 @@ -848,7 +850,7 @@ void executor::http_hashrate_report(std::string& out) out.reserve(4096); - snprintf(buffer, sizeof(buffer), sHtmlCommonHeader, "Hashrate Report", "Hashrate Report"); + snprintf(buffer, sizeof(buffer), sHtmlCommonHeader, "Hashrate Report", ver_html, "Hashrate Report"); out.append(buffer); snprintf(buffer, sizeof(buffer), sHtmlHashrateBodyHigh, (unsigned int)nthd + 3); @@ -893,7 +895,7 @@ void executor::http_result_report(std::string& out) out.reserve(4096); - snprintf(buffer, sizeof(buffer), sHtmlCommonHeader, "Result Report", "Result Report"); + snprintf(buffer, sizeof(buffer), sHtmlCommonHeader, "Result Report", ver_html, "Result Report"); out.append(buffer); size_t iGoodRes = vMineResults[0].count, iTotalRes = iGoodRes; @@ -939,7 +941,7 @@ void executor::http_connection_report(std::string& out) out.reserve(4096); - snprintf(buffer, sizeof(buffer), sHtmlCommonHeader, "Connection Report", "Connection Report"); + snprintf(buffer, sizeof(buffer), sHtmlCommonHeader, "Connection Report", ver_html, "Connection Report"); out.append(buffer); jpsock* pool = pick_pool_by_id(current_pool_id); @@ -1079,11 +1081,11 @@ void executor::http_json_report(std::string& out) cn_error.append(buffer); } - size_t bb_size = 1024 + hr_thds.size() + res_error.size() + cn_error.size(); + size_t bb_size = 2048 + hr_thds.size() + res_error.size() + cn_error.size(); std::unique_ptr<char[]> bigbuf( new char[ bb_size ] ); int bb_len = snprintf(bigbuf.get(), bb_size, sJsonApiFormat, - hr_thds.c_str(), hr_buffer, a, + get_version_str().c_str(), hr_thds.c_str(), hr_buffer, a, int_port(iPoolDiff), int_port(iGoodRes), int_port(iTotalRes), fAvgResTime, int_port(iPoolHashes), int_port(iTopDiff[0]), int_port(iTopDiff[1]), int_port(iTopDiff[2]), int_port(iTopDiff[3]), int_port(iTopDiff[4]), int_port(iTopDiff[5]), int_port(iTopDiff[6]), int_port(iTopDiff[7]), int_port(iTopDiff[8]), int_port(iTopDiff[9]), diff --git a/xmrstak/net/jpsock.cpp b/xmrstak/net/jpsock.cpp index f6f5c1f..cb586d2 100644 --- a/xmrstak/net/jpsock.cpp +++ b/xmrstak/net/jpsock.cpp @@ -509,8 +509,8 @@ bool jpsock::cmd_login() { char cmd_buffer[1024]; - snprintf(cmd_buffer, sizeof(cmd_buffer), "{\"method\":\"login\",\"params\":{\"login\":\"%s\",\"pass\":\"%s\",\"agent\":\"" AGENTID_STR "\"},\"id\":1}\n", - usr_login.c_str(), usr_pass.c_str()); + snprintf(cmd_buffer, sizeof(cmd_buffer), "{\"method\":\"login\",\"params\":{\"login\":\"%s\",\"pass\":\"%s\",\"agent\":\"%s\"},\"id\":1}\n", + usr_login.c_str(), usr_pass.c_str(), get_version_str().c_str()); opq_json_val oResult(nullptr); diff --git a/xmrstak/version.cpp b/xmrstak/version.cpp new file mode 100644 index 0000000..3b8a19d --- /dev/null +++ b/xmrstak/version.cpp @@ -0,0 +1,52 @@ +#include "version.hpp" + +//! git will put "#define GIT_ARCHIVE 1" on the next line inside archives. $Format:%n#define GIT_ARCHIVE 1$ +#if defined(GIT_ARCHIVE) && !defined(GIT_COMMIT_HASH) +#define GIT_COMMIT_HASH $Format:%h$ +#endif + +#ifndef GIT_COMMIT_HASH +#define GIT_COMMIT_HASH 0000000 +#endif + +#ifndef GIT_BRANCH +#define GIT_BRANCH unknown +#endif + +#ifndef BACKEND_TYPE +#define BACKEND_TYPE unknown +#endif + +#define XMR_STAK_NAME "xmr-stak" +#define XMR_STAK_VERSION "2.0.0" + +#if defined(_WIN32) +#define OS_TYPE "win" +#elif defined(__APPLE__) +#define OS_TYPE "mac" +#elif defined(__FreeBSD__) +#define OS_TYPE "bsd" +#elif defined(__linux__) +#define OS_TYPE "lin" +#else +#define OS_TYPE "unk" +#endif + +#if defined(CONF_NO_AEON) +#define COIN_TYPE "monero" +#elif defined(CONF_NO_MONERO) +#define COIN_TYPE "aeon" +#else +#define COIN_TYPE "aeon-monero" +#endif + +#define XMRSTAK_PP_TOSTRING1(str) #str +#define XMRSTAK_PP_TOSTRING(str) XMRSTAK_PP_TOSTRING1(str) + +#define VERSION_LONG XMR_STAK_NAME "/" XMR_STAK_VERSION "/" XMRSTAK_PP_TOSTRING(GIT_COMMIT_HASH) "/" XMRSTAK_PP_TOSTRING(GIT_BRANCH) "/" OS_TYPE "/" XMRSTAK_PP_TOSTRING(BACKEND_TYPE) "/" COIN_TYPE "/" +#define VERSION_SHORT XMR_STAK_NAME " " XMR_STAK_VERSION " " XMRSTAK_PP_TOSTRING(GIT_COMMIT_HASH) +#define VERSION_HTML "v" XMR_STAK_VERSION "-" XMRSTAK_PP_TOSTRING(GIT_COMMIT_HASH) + +const char ver_long[] = VERSION_LONG; +const char ver_short[] = VERSION_SHORT; +const char ver_html[] = VERSION_HTML; diff --git a/xmrstak/version.hpp b/xmrstak/version.hpp index 44214c8..cdf82f3 100644 --- a/xmrstak/version.hpp +++ b/xmrstak/version.hpp @@ -1,4 +1,19 @@ #pragma once -#define XMR_STAK_NAME "xmr-stak" -#define XMR_STAK_VERSION "2.0.0-predev" +#include <inttypes.h> +#include <string> +#include "donate-level.hpp" + +extern const char ver_long[]; +extern const char ver_short[]; +extern const char ver_html[]; + +inline std::string get_version_str() +{ + return std::string(ver_long) + std::to_string(uint32_t(fDevDonationLevel * 1000)) ; +} + +inline std::string get_version_str_short() +{ + return std::string(ver_short); +} |