summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam <Adam@anope.org>2012-02-15 00:06:25 -0500
committerAdam <Adam@anope.org>2012-02-15 00:06:25 -0500
commite1f5fc6a0c139eae035d20facb95914642cad50c (patch)
tree60a12e03999b2cbd1ec77dd5b5bf6aef6b0057b3
parentdb59f1a70f75d26a94df73492dc4aa462546f3d9 (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.
-rwxr-xr-xConfig18
-rw-r--r--include/CMakeLists.txt2
-rw-r--r--include/anope.h1
-rw-r--r--include/modules.h15
-rw-r--r--include/version.cpp66
-rw-r--r--src/misc.cpp9
-rw-r--r--src/module.cpp6
-rw-r--r--src/modulemanager.cpp35
-rw-r--r--src/version.sh3
9 files changed, 84 insertions, 71 deletions
diff --git a/Config b/Config
index 9220befca..664aaba17 100755
--- a/Config
+++ b/Config
@@ -209,23 +209,7 @@ if [ ! "$NO_INTRO" ] ; then
;;
esac
. $SOURCE_DIR/src/version.sh
- if [ -d .git ] ; then
- VERSION=`git describe --tags`
- VERSION_BUILD=`echo "$VERSION" | cut -d'-' -f2`
- if [ "$SOURCE_DIR" = "." ] ; then
- test -d build || mkdir -p build/include
- BUILD_DIR="build"
- else
- BUILD_DIR="."
- fi
- VERSION_EXTRA=`echo "$VERSION" | cut -d'-' -f3`
- # Only do this if we are not on a tag, src/version.sh will be all we need then.
- if [ "$VERSION_BUILD" != "$VERSION_EXTRA" ] ; then
- echo "#define VERSION_BUILD $VERSION_BUILD" > $BUILD_DIR/include/version.h
- echo "#define VERSION_EXTRA \"-$VERSION_EXTRA\"" >> $BUILD_DIR/include/version.h
- fi
- fi
- cat $SOURCE_DIR/.BANNER | sed "s/CURVER/$VERSION/" | sed "s@SOURCE_DIR@$SOURCE_DIR@" | $PAGER
+ cat $SOURCE_DIR/.BANNER | sed "s/CURVER/$VERSION_MAJOR.$VERSION_MINOR.$VERSION_PATCH$VERSION_EXTRA/" | sed "s@SOURCE_DIR@$SOURCE_DIR@" | $PAGER
echo ""
else
echo ""
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();
diff --git a/src/misc.cpp b/src/misc.cpp
index bb8658a56..5f36358d3 100644
--- a/src/misc.cpp
+++ b/src/misc.cpp
@@ -769,12 +769,16 @@ const Anope::string Anope::LastError()
ModuleVersion Module::GetVersion() const
{
- return ModuleVersion(VERSION_MAJOR, VERSION_MINOR, VERSION_BUILD);
+ return ModuleVersion(VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH);
}
Anope::string Anope::Version()
{
- return stringify(VERSION_MAJOR) + "." + stringify(VERSION_MINOR) + "." + stringify(VERSION_PATCH) + VERSION_EXTRA + " (" + stringify(VERSION_BUILD) + ")";
+#ifdef VERSION_GIT
+ return stringify(VERSION_MAJOR) + "." + stringify(VERSION_MINOR) + "." + stringify(VERSION_PATCH) + VERSION_EXTRA + " (" + VERSION_GIT + ")";
+#else
+ return stringify(VERSION_MAJOR) + "." + stringify(VERSION_MINOR) + "." + stringify(VERSION_PATCH) + VERSION_EXTRA;
+#endif
}
Anope::string Anope::VersionShort()
@@ -790,7 +794,6 @@ Anope::string Anope::VersionBuildString()
int Anope::VersionMajor() { return VERSION_MAJOR; }
int Anope::VersionMinor() { return VERSION_MINOR; }
int Anope::VersionPatch() { return VERSION_PATCH; }
-int Anope::VersionBuild() { return VERSION_BUILD; }
/**
* Normalize buffer stripping control characters and colors
diff --git a/src/module.cpp b/src/module.cpp
index d3406ec22..8a253042a 100644
--- a/src/module.cpp
+++ b/src/module.cpp
@@ -84,7 +84,7 @@ void Module::SetAuthor(const Anope::string &nauthor)
this->author = nauthor;
}
-ModuleVersion::ModuleVersion(int vMajor, int vMinor, int vBuild) : Major(vMajor), Minor(vMinor), Build(vBuild)
+ModuleVersion::ModuleVersion(int vMajor, int vMinor, int vPatch) : Major(vMajor), Minor(vMinor), Patch(vPatch)
{
}
@@ -102,8 +102,8 @@ int ModuleVersion::GetMinor() const
return this->Minor;
}
-int ModuleVersion::GetBuild() const
+int ModuleVersion::GetPatch() const
{
- return this->Build;
+ return this->Patch;
}
diff --git a/src/modulemanager.cpp b/src/modulemanager.cpp
index 39a4fcc45..d16b71cad 100644
--- a/src/modulemanager.cpp
+++ b/src/modulemanager.cpp
@@ -186,22 +186,30 @@ ModuleReturn ModuleManager::LoadModule(const Anope::string &modname, User *u)
ModuleVersion v = m->GetVersion();
if (v.GetMajor() < Anope::VersionMajor() || (v.GetMajor() == Anope::VersionMajor() && v.GetMinor() < Anope::VersionMinor()))
{
- Log() << "Module " << modname << " is compiled against an older version of Anope " << v.GetMajor() << "." << v.GetMinor() << ", this is " << Anope::VersionMajor() << "." << Anope::VersionMinor();
+ Log() << "Module " << modname << " is compiled against an older version of Anope " << v.GetMajor() << "." << v.GetMinor() << ", this is " << Anope::VersionShort();
DeleteModule(m);
return MOD_ERR_VERSION;
}
else if (v.GetMajor() > Anope::VersionMajor() || (v.GetMajor() == Anope::VersionMajor() && v.GetMinor() > Anope::VersionMinor()))
{
- Log() << "Module " << modname << " is compiled against a newer version of Anope " << v.GetMajor() << "." << v.GetMinor() << ", this is " << Anope::VersionMajor() << "." << Anope::VersionMinor();
+ Log() << "Module " << modname << " is compiled against a newer version of Anope " << v.GetMajor() << "." << v.GetMinor() << ", this is " << Anope::VersionShort();
DeleteModule(m);
return MOD_ERR_VERSION;
}
- else if (v.GetBuild() < Anope::VersionBuild())
- Log() << "Module " << modname << " is compiled against an older revision of Anope " << v.GetBuild() << ", this is " << Anope::VersionBuild();
- else if (v.GetBuild() > Anope::VersionBuild())
- Log() << "Module " << modname << " is compiled against a newer revision of Anope " << v.GetBuild() << ", this is " << Anope::VersionBuild();
- else if (v.GetBuild() == Anope::VersionBuild())
- Log(LOG_DEBUG) << "Module " << modname << " compiled against current version of Anope " << v.GetBuild();
+ else if (v.GetPatch() < Anope::VersionPatch())
+ {
+ Log() << "Module " << modname << " is compiled against an older version of Anope, " << v.GetMajor() << "." << v.GetMinor() << "." << v.GetPatch() << ", this is " << Anope::VersionShort();
+ DeleteModule(m);
+ return MOD_ERR_VERSION;
+ }
+ else if (v.GetPatch() > Anope::VersionPatch())
+ {
+ Log() << "Module " << modname << " is compiled against a newer version of Anope, " << v.GetMajor() << "." << v.GetMinor() << "." << v.GetPatch() << ", this is " << Anope::VersionShort();
+ DeleteModule(m);
+ return MOD_ERR_VERSION;
+ }
+ else
+ Log(LOG_DEBUG) << "Module " << modname << " is compiled against current version of Anope " << Anope::VersionShort();
if (m->type == PROTOCOL && ModuleManager::FindFirstOf(PROTOCOL) != m)
{
@@ -251,7 +259,7 @@ Module *ModuleManager::FindFirstOf(ModType type)
return NULL;
}
-void ModuleManager::RequireVersion(int major, int minor, int patch, int build)
+void ModuleManager::RequireVersion(int major, int minor, int patch)
{
if (Anope::VersionMajor() > major)
return;
@@ -268,16 +276,11 @@ void ModuleManager::RequireVersion(int major, int minor, int patch, int build)
else if (Anope::VersionPatch() > patch)
return;
else if (Anope::VersionPatch() == patch)
- {
- if (build == -1)
- return;
- else if (Anope::VersionBuild() >= build)
- return;
- }
+ return;
}
}
- throw ModuleException("This module requires version " + stringify(major) + "." + stringify(minor) + "." + stringify(patch) + "-" + build + " - this is " + Anope::Version());
+ throw ModuleException("This module requires version " + stringify(major) + "." + stringify(minor) + "." + stringify(patch) + " - this is " + Anope::VersionShort());
}
ModuleReturn ModuleManager::DeleteModule(Module *m)
diff --git a/src/version.sh b/src/version.sh
index 6b3f3be14..c50b9c1a1 100644
--- a/src/version.sh
+++ b/src/version.sh
@@ -1,8 +1,7 @@
#!/bin/sh
+
VERSION_MAJOR="1"
VERSION_MINOR="9"
VERSION_PATCH="7"
VERSION_EXTRA="-avoid-direct-visual-contact"
-VERSION="$VERSION_MAJOR.$VERSION_MINOR.$VERSION_PATCH$VERSION_EXTRA"
-