Skip to content
Snippets Groups Projects
Commit 63e71d0d authored by Fabian Tërnava's avatar Fabian Tërnava
Browse files

added comparison between new generation and existing file

parent 585af1bb
No related branches found
No related tags found
No related merge requests found
......@@ -91,6 +91,11 @@ int main(int argc, char* argv[])
}
std::filesystem::path input_file(filename);
if (!std::filesystem::exists(input_file))
{
std::cerr << "The input file does not exist!" << std::endl;
}
if (input_file.extension().string() != ".xml")
{
std::cerr << "The file you passed has the wrong type." << std::endl;
......@@ -98,6 +103,8 @@ int main(int argc, char* argv[])
std::string new_name_with_extension = input_file.filename().replace_extension("").string();
new_name_with_extension += ".aron.generated.h";
std::string output_file_path = output + "/" + new_name_with_extension;
std::filesystem::path output_file(output_file_path);
reader.parseFile(input_file);
if (verbose)
......@@ -121,14 +128,10 @@ int main(int argc, char* argv[])
std::cout << "--> Found " << writer.getTypeClasses().size() << " type classes." << std::endl;
}
std::ofstream ofs;
std::string output_current_file = output + "/" + new_name_with_extension;
ofs.open(output_current_file);
time_t now = time(0);
char* dt = ctime(&now);
std::stringstream file_new_content;
ofs << "/* \n\
file_new_content << "\
/* \n\
* This file is part of ArmarX. \n\
* \n\
* Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), \n\
......@@ -151,7 +154,6 @@ int main(int argc, char* argv[])
************************************************************************* \n\
* WARNING: This file is autogenerated. \n\
* Original file: " + filename + " \n\
* Timestamp of generation: " + dt + "\
* Please do not edit since your changes may be overwritten on the next generation \n\
* If you have any questions please contact: Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) \n\
************************************************************************* \n\
......@@ -169,7 +171,7 @@ int main(int argc, char* argv[])
CppWriterPtr w = CppWriterPtr(new CppWriter());
c->writeCpp(w);
ofs << w->getString();
file_new_content << w->getString();
if (verbose)
{
......@@ -178,17 +180,33 @@ int main(int argc, char* argv[])
if (i != writer.getTypeClasses().size())
{
ofs << "\n";
ofs << "// *************\n";
ofs << "// Here comes another auto-generated class. Don't mind the duplicated includes - everything is guarded!\n";
ofs << "// *************\n";
ofs << "\n";
file_new_content << "\n";
file_new_content << "// *************\n";
file_new_content << "// Here comes another auto-generated class. Don't mind the duplicated includes - everything is guarded!\n";
file_new_content << "// *************\n";
file_new_content << "\n";
}
}
// check if file already exists
if (std::filesystem::exists(output_file))
{
std::ifstream ifs(output_file_path);
std::string file_content((std::istreambuf_iterator<char>(ifs)), (std::istreambuf_iterator<char>()));
if (file_content == file_new_content.str())
{
std::cout << "File content not changed for <" + output_file_path + ">" << std::endl;
exit(0);
}
}
std::ofstream ofs;
ofs.open(output_file_path);
ofs << file_new_content.str();
ofs.close();
std::cout << "Finished generating <" + output_current_file + ">" << std::endl;
std::cout << "Finished generating <" + output_file_path + ">" << std::endl;
}
catch (const cxxopts::OptionException& e)
{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment