1
0
mirror of https://github.com/anope/anope.git synced 2026-06-25 09:36:39 +02:00

Some OCDing over version.cpp, and make it so module.cpp doesn't need version.h (only main.cpp, modulemanager.cpp, and modules.cpp need version.h, to avoid rebuilding EVERYTHING every build)

This commit is contained in:
Naram Qashat
2010-06-28 23:15:16 -04:00
parent 1037a469d3
commit 950cfcd31e
2 changed files with 28 additions and 34 deletions
+28 -33
View File
@@ -17,68 +17,63 @@
int main(int argc, char *argv[])
{
using namespace std;
if (argc < 3)
{
cout << "Syntax: " << argv[0] << " <src/version.sh> <version.h>" << endl;
std::cout << "Syntax: " << argv[0] << " <src/version.sh> <version.h>" << std::endl;
return 1;
}
fstream fd;
std::fstream fd;
fd.clear();
fd.open(argv[1], ios::in);
fd.open(argv[1], std::ios::in);
if (!fd.is_open())
{
cout << "Error: Unable to open src/version.sh for reading: " << argv[1] << endl;
std::cout << "Error: Unable to open src/version.sh for reading: " << argv[1] << std::endl;
return 1;
}
string filebuf;
list<pair<string, string> > versions;
std::string filebuf;
std::list<std::pair<std::string, std::string> > versions;
while (getline(fd, filebuf))
{
if (filebuf.find("VERSION_") == 0)
if (!filebuf.find("VERSION_"))
{
size_t eq = filebuf.find('=');
string type = filebuf.substr(8, 5);
string value = filebuf.substr(eq + 2, filebuf.length() - eq - 3);
versions.push_back(make_pair(type, value));
std::string type = filebuf.substr(8, 5);
std::string value = filebuf.substr(eq + 2, filebuf.length() - eq - 3);
versions.push_back(std::make_pair(type, value));
}
}
fd.close();
fd.clear();
fd.open(argv[2], ios::in);
fd.open(argv[2], std::ios::in);
string version_build = "#define VERSION_BUILD 1";
string version_extra;
string build = "#define BUILD 1";
std::string version_build = "#define VERSION_BUILD 1";
std::string version_extra;
std::string build = "#define BUILD 1";
if (fd.is_open())
{
while (getline(fd, filebuf))
{
if (filebuf.find("#define VERSION_BUILD") == 0)
{
if (!filebuf.find("#define VERSION_BUILD"))
version_build = filebuf;
}
else if (filebuf.find("#define VERSION_EXTRA") == 0)
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") == 0)
else if (!filebuf.find("#define BUILD"))
{
size_t tab = filebuf.find(' ');
int ibuild = atoi(filebuf.substr(tab + 1).c_str());
++ibuild;
int ibuild = atoi(filebuf.substr(tab + 1).c_str()) + 1;
stringstream ss;
std::stringstream ss;
ss << "#define BUILD " << ibuild;
build = ss.str();
}
@@ -88,31 +83,31 @@ int main(int argc, char *argv[])
}
fd.clear();
fd.open(argv[2], ios::out);
fd.open(argv[2], std::ios::out);
if (!fd.is_open())
{
cout << "Error: Unable to include/version.h for writing: " << argv[2];
std::cout << "Error: Unable to include/version.h for writing: " << argv[2] << std::endl;
return 1;
}
fd << "/* This file is automatically generated by version.cpp - do not edit it! */" << endl;
fd << "/* This file is automatically generated by version.cpp - do not edit it! */" << std::endl;
for (list<pair<string, string> >::iterator it = versions.begin(), it_end = versions.end(); it != it_end; ++it)
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")
{
if (!version_extra.empty())
fd << "#define VERSION_EXTRA \"" << version_extra << "\"" << endl;
fd << "#define VERSION_EXTRA \"" << version_extra << "\"" << std::endl;
else
fd << "#define VERSION_EXTRA \"" << it->second << "\"" << endl;
fd << "#define VERSION_EXTRA \"" << it->second << "\"" << std::endl;
}
else
fd << "#define VERSION_" << it->first << " " << it->second << endl;
fd << "#define VERSION_" << it->first << " " << it->second << std::endl;
}
fd << version_build << endl;
fd << build << endl;
fd << version_build << std::endl;
fd << build << std::endl;
fd.close();
-1
View File
@@ -8,7 +8,6 @@
#include "modules.h"
#include "language.h"
#include "version.h"
Module::Module(const std::string &mname, const std::string &creator)
{