diff options
author | Adam <Adam@anope.org> | 2012-02-15 00:06:25 -0500 |
---|---|---|
committer | Adam <Adam@anope.org> | 2012-02-15 00:06:25 -0500 |
commit | e1f5fc6a0c139eae035d20facb95914642cad50c (patch) | |
tree | 60a12e03999b2cbd1ec77dd5b5bf6aef6b0057b3 /include | |
parent | db59f1a70f75d26a94df73492dc4aa462546f3d9 (diff) |
Remove revision numbers as they're only ever set by Config reading git since we've switched off of SVN. Instead just use the hash for the current head when building. Also recheck the hash on every make not just Config.
Diffstat (limited to 'include')
-rw-r--r-- | include/CMakeLists.txt | 2 | ||||
-rw-r--r-- | include/anope.h | 1 | ||||
-rw-r--r-- | include/modules.h | 15 | ||||
-rw-r--r-- | include/version.cpp | 66 |
4 files changed, 54 insertions, 30 deletions
diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt index 5579fdf30..e04fe31a8 100644 --- a/include/CMakeLists.txt +++ b/include/CMakeLists.txt @@ -7,7 +7,7 @@ get_target_property(version_BINARY version LOCATION) # Modify version.h from the above executable, with dependencies to version.cpp # and all of the source files in the main build add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/version_build - COMMAND ${version_BINARY} ${Anope_SOURCE_DIR}/src/version.sh ${CMAKE_CURRENT_BINARY_DIR}/version.h + COMMAND ${version_BINARY} ${Anope_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}/version.h DEPENDS version ${SRC_SRCS} ) # Add version to list of files for CPack to ignore diff --git a/include/anope.h b/include/anope.h index 992662650..421d735a3 100644 --- a/include/anope.h +++ b/include/anope.h @@ -341,7 +341,6 @@ namespace Anope extern CoreExport int VersionMajor(); extern CoreExport int VersionMinor(); extern CoreExport int VersionPatch(); - extern CoreExport int VersionBuild(); /** Check whether two strings match. * @param str The string to check against the pattern (e.g. foobar) diff --git a/include/modules.h b/include/modules.h index 722526382..1cb496a54 100644 --- a/include/modules.h +++ b/include/modules.h @@ -149,15 +149,15 @@ class ModuleVersion private: int Major; int Minor; - int Build; + int Patch; public: /** Constructor * @param vMajor The major version numbber * @param vMinor The minor version numbber - * @param vBuild The build version numbber + * @param vPatch The patch version numbber */ - ModuleVersion(int vMajor, int vMinor, int vBuild); + ModuleVersion(int vMajor, int vMinor, int vPatch); /** Destructor */ @@ -173,10 +173,10 @@ class ModuleVersion */ int GetMinor() const; - /** Get the build version this was built against - * @return The build version + /** Get the patch version this was built against + * @return The patch version */ - int GetBuild() const; + int GetPatch() const; }; @@ -1041,9 +1041,8 @@ class CoreExport ModuleManager * @param major The major version * @param minor The minor vesion * @param patch The patch version - * @param build The build version */ - static void RequireVersion(int major, int minor, int patch, int build); + static void RequireVersion(int major, int minor, int patch); /** Change the priority of one event in a module. * Each module event has a list of modules which are attached to that event type. If you wish to be called before or after other specific modules, you may use this diff --git a/include/version.cpp b/include/version.cpp index 37585a568..077ef28bb 100644 --- a/include/version.cpp +++ b/include/version.cpp @@ -15,21 +15,54 @@ #include <sstream> #include <list> +static std::string get_git_hash(const std::string &git_dir) +{ + std::fstream fd; + std::string filebuf; + + fd.open((git_dir + "/HEAD").c_str(), std::ios::in); + if (!fd.is_open()) + return ""; + if (!getline(fd, filebuf) || filebuf.find("ref: ") != 0) + { + fd.close(); + return ""; + } + + fd.close(); + + filebuf = filebuf.substr(5); + fd.open((git_dir + "/" + filebuf).c_str(), std::ios::in); + if (!fd.is_open()) + return ""; + if (!getline(fd, filebuf)) + { + fd.close(); + return ""; + } + fd.close(); + + return "g" + filebuf.substr(0, 7); +} + int main(int argc, char *argv[]) { if (argc < 3) { - std::cout << "Syntax: " << argv[0] << " <src/version.sh> <version.h>" << std::endl; + std::cerr << "Syntax: " << argv[0] << " <base> <version.h>" << std::endl; return 1; } + std::string version_sh = std::string(argv[1]) + "/src/version.sh"; + std::string git_dir = std::string(argv[1]) + "/.git"; + std::fstream fd; fd.clear(); - fd.open(argv[1], std::ios::in); + fd.open(version_sh.c_str(), std::ios::in); if (!fd.is_open()) { - std::cout << "Error: Unable to open src/version.sh for reading: " << argv[1] << std::endl; + std::cerr << "Error: Unable to open src/version.sh for reading: " << version_sh << std::endl; return 1; } @@ -41,7 +74,7 @@ int main(int argc, char *argv[]) { size_t eq = filebuf.find('='); - std::string type = filebuf.substr(8, 5); + std::string type = filebuf.substr(0, eq); std::string value = filebuf.substr(eq + 2, filebuf.length() - eq - 3); versions.push_back(std::make_pair(type, value)); } @@ -49,25 +82,19 @@ int main(int argc, char *argv[]) fd.close(); + std::string git_version = get_git_hash(git_dir); + if (!git_version.empty()) + versions.push_back(std::make_pair("VERSION_GIT", git_version)); + fd.clear(); fd.open(argv[2], std::ios::in); - std::string version_build = "#define VERSION_BUILD 1"; std::string build = "#define BUILD 1"; - std::string version_extra; if (fd.is_open()) { while (getline(fd, filebuf)) { - if (!filebuf.find("#define VERSION_BUILD")) - version_build = filebuf; - else if (!filebuf.find("#define VERSION_EXTRA")) - { - size_t q = filebuf.find('"'); - - version_extra = filebuf.substr(q + 1, filebuf.length() - q - 2); - } - else if (!filebuf.find("#define BUILD")) + if (!filebuf.find("#define BUILD")) { size_t tab = filebuf.find(' '); @@ -87,7 +114,7 @@ int main(int argc, char *argv[]) if (!fd.is_open()) { - std::cout << "Error: Unable to include/version.h for writing: " << argv[2] << std::endl; + std::cerr << "Error: Unable to include/version.h for writing: " << argv[2] << std::endl; return 1; } @@ -95,13 +122,12 @@ int main(int argc, char *argv[]) for (std::list<std::pair<std::string, std::string> >::iterator it = versions.begin(), it_end = versions.end(); it != it_end; ++it) { - if (it->first == "EXTRA") - fd << "#define VERSION_EXTRA \"" << (!version_extra.empty() ? version_extra : "") << (version_extra.find(it->second) == std::string::npos ? it->second : "") << "\"" << std::endl; + if (it->first == "VERSION_EXTRA" || it->first == "VERSION_GIT") + fd << "#define " << it->first << " \"" << it->second << "\"" << std::endl; else - fd << "#define VERSION_" << it->first << " " << it->second << std::endl; + fd << "#define " << it->first << " " << it->second << std::endl; } - fd << version_build << std::endl; fd << build << std::endl; fd.close(); |