X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2FcreaDevManagerLib%2FmodelCDMProject.cpp;h=5bc14e4d4b4ed8460aaef0b6cdab11dd3f578487;hb=2f886b3dbdc87d142f8363272b2bd226209b8b06;hp=51f642a0b097068da7d779cccbb84a6e561620dc;hpb=2fb5dd9262993efaf56bfc731f4297fdb96bf63e;p=crea.git diff --git a/lib/creaDevManagerLib/modelCDMProject.cpp b/lib/creaDevManagerLib/modelCDMProject.cpp index 51f642a..5bc14e4 100644 --- a/lib/creaDevManagerLib/modelCDMProject.cpp +++ b/lib/creaDevManagerLib/modelCDMProject.cpp @@ -87,7 +87,7 @@ modelCDMProject::modelCDMProject( CDMUtilities::splitter::split(nameBits, word, " ", CDMUtilities::splitter::no_empties); this->name = this->nameProject = ""; - for (int i = 0; i < nameBits.size(); i++) + for (int i = 0; i < (int)(nameBits.size()); i++) { if(i != 0) this->name += " "; @@ -261,10 +261,16 @@ bool modelCDMProject::SetVersion(const std::string& version, std::string*& resul CDMUtilities::splitter::split(vers, version, " .", CDMUtilities::splitter::no_empties); time_t now = time(0); - tm* ltm = localtime(&now); + + tm ltm; +#ifdef _WIN32 + localtime_s(<m, &now); +#else + ltm = *(localtime(&now)); +#endif std::stringstream date; - date << ltm->tm_mday << "/" << 1 + ltm->tm_mon << "/" << 1900 + ltm->tm_year; + date << ltm.tm_mday << "/" << 1 + ltm.tm_mon << "/" << 1900 + ltm.tm_year; //set name of library in CMakeLists inside copied folder std::string line; @@ -295,7 +301,11 @@ bool modelCDMProject::SetVersion(const std::string& version, std::string*& resul in.close(); out.close(); //delete old file and rename new file +#ifdef _WIN32 + std::string renameCommand = "move /Y \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt.tmp\" \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt\""; +#else std::string renameCommand = "mv \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt.tmp\" \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt\""; +#endif if(system(renameCommand.c_str())) { result = new std::string("An error occurred while running '" + renameCommand + "'."); @@ -335,31 +345,31 @@ modelCDMIProjectTreeNode* modelCDMProject::CreatePackage( //fixing input parameters std::vector words; - CDMUtilities::splitter::split(words,name," ",CDMUtilities::splitter::no_empties); + CDMUtilities::splitter::split(words,name," '/\"\\,.",CDMUtilities::splitter::no_empties); std::string nameFixed = ""; - for (int i = 0; i < words.size(); i++) + for (int i = 0; i < (int)(words.size()); i++) { nameFixed += words[i]; } words.clear(); - CDMUtilities::splitter::split(words,authors," ",CDMUtilities::splitter::no_empties); + CDMUtilities::splitter::split(words,authors," '/\"\\,.",CDMUtilities::splitter::no_empties); std::string authorFixed; - for (int i = 0; i < words.size(); i++) + for (int i = 0; i < (int)(words.size()); i++) { authorFixed += words[i]; } words.clear(); std::string descriptionFixed; - CDMUtilities::splitter::split(words,authorsEmail," ",CDMUtilities::splitter::no_empties); - for (int i = 0; i < words.size(); i++) + CDMUtilities::splitter::split(words,authorsEmail," '/\"\\,",CDMUtilities::splitter::no_empties); + for (int i = 0; i < (int)(words.size()); i++) { - descriptionFixed += words[i]; + descriptionFixed += words[i] + "/"; } words.clear(); - CDMUtilities::splitter::split(words,description," ",CDMUtilities::splitter::no_empties); - for (int i = 0; i < words.size(); i++) + CDMUtilities::splitter::split(words,description," '\"",CDMUtilities::splitter::no_empties); + for (int i = 0; i < (int)(words.size()); i++) { descriptionFixed += "_" + words[i]; } @@ -367,12 +377,24 @@ modelCDMIProjectTreeNode* modelCDMProject::CreatePackage( //call project to create package : use bbCreatePackage [author] [description] std::string creationCommand = "bbCreatePackage \"" + this->path + "\" \"" + nameFixed + "\" \"" + authorFixed + "\" \"" + descriptionFixed + "\""; //TODO: bbCreatePackage script always returning 0. It should return 1 or greater if any error - if(system(creationCommand.c_str())) + bool resultCommand = 0 != system(creationCommand.c_str()); +#ifdef _WIN32 + resultCommand = false; +#endif + if(resultCommand) { result = new std::string("An error occurred while running '" + creationCommand + "'."); return NULL; } + //add library to project CMakeLists + std::fstream out1((this->path + CDMUtilities::SLASH + "CMakeLists.txt").c_str(), std::fstream::in | std::fstream::out | std::fstream::app); + if (out1.is_open()) + { + out1 << "ADD_SUBDIRECTORY(bbtk_" << nameFixed << "_PKG)" << std::endl; + out1.close(); + } + //add library to model modelCDMPackage* package = new modelCDMPackage(this, this->path + CDMUtilities::SLASH + "bbtk_" + nameFixed + "_PKG", "bbtk_" + nameFixed + "_PKG", this->level + 1); this->packages.push_back(package); @@ -402,13 +424,14 @@ modelCDMIProjectTreeNode* modelCDMProject::CreateLibrary( modelCDMIProjectTreeNode* modelCDMProject::CreateApplication( const std::string& name, + const int& type, std::string*& result, const std::string& path ) { if(this->appli != NULL) { - return this->appli->CreateApplication(name, result); + return this->appli->CreateApplication(name, type, result); } result = new std::string("there is no appli folder in this project."); return NULL; @@ -463,7 +486,7 @@ const bool modelCDMProject::Refresh(std::string*& result) CDMUtilities::splitter::split(nameBits, word, " ", CDMUtilities::splitter::no_empties); this->name = this->nameProject = ""; - for (int i = 0; i < nameBits.size(); i++) + for (int i = 0; i < (int)(nameBits.size()); i++) { if(i != 0) this->name += " "; @@ -556,7 +579,7 @@ const bool modelCDMProject::Refresh(std::string*& result) else if(stdfileName.size() > 9 && stdfileName.substr(0,5) == "bbtk_" && stdfileName.substr(stdfileName.size()-4,4) == "_PKG") { bool found = false; - for (int i = 0; !found && i < this->packages.size(); i++) + for (int i = 0; !found && i < (int)(this->packages.size()); i++) { if (this->packages[i]->GetName() == stdfileName) { @@ -580,7 +603,7 @@ const bool modelCDMProject::Refresh(std::string*& result) else { bool found = false; - for (int i = 0; !found && i < this->children.size(); i++) + for (int i = 0; !found && i < (int)(this->children.size()); i++) { if (this->children[i]->GetName() == stdfileName) { @@ -626,7 +649,7 @@ const bool modelCDMProject::Refresh(std::string*& result) else { bool found = false; - for (int i = 0; !found && i < this->children.size(); i++) + for (int i = 0; !found && i < (int)(this->children.size()); i++) { if (this->children[i]->GetName() == stdfileName) { @@ -648,7 +671,7 @@ const bool modelCDMProject::Refresh(std::string*& result) } } - for (int i = 0; i < checkedPackages.size(); i++) + for (int i = 0; i < (int)(checkedPackages.size()); i++) { if(!checkedPackages[i]) { @@ -657,7 +680,7 @@ const bool modelCDMProject::Refresh(std::string*& result) i--; } } - for (int i = 0; i < checked.size(); i++) + for (int i = 0; i < (int)(checked.size()); i++) { if(!checked[i]) { @@ -678,6 +701,13 @@ bool modelCDMProject::ConfigureBuild(std::string*& result) //TODO: adjust for windows and mac #ifdef _WIN32 // ------ Windows + if(0 == system("cmake-gui")) + return true; + else + { + result = new std::string("There was an error opening cmake-gui. Please make sure it's installed and that cmake's bin folder is in the system path."); + return false; + } #elif __APPLE__ // ------ Apple #else @@ -717,6 +747,17 @@ bool modelCDMProject::Build(std::string*& result, const std::string& line) //TODO: adjust for windows and mac #ifdef _WIN32 // ------ Windows + //\\..\\IDE\\VCExpress.exe \"" + this->buildPath + CDMUtilities::SLASH + this->nameProject + ".sln\" +// std::string command = "\"" + std::string(getenv("VS90COMNTOOLS")) + "..\\IDE\\VCExpress.exe\" \"" + this->buildPath + CDMUtilities::SLASH + this->nameProject + ".sln\" &"; + std::string command = "\"\"%VS90COMNTOOLS%..\\IDE\\VCExpress.exe\" \"" + this->buildPath + CDMUtilities::SLASH + this->nameProject + ".sln\" &\""; + command = "start cmd.exe /k " + command + " &"; + if(0 == system(command.c_str())) + return true; + else + { + result = new std::string("An error has happened running: \"" + command + "\". Please make sure to have visual c++ express installed and to have the VS90COMNTOOLS environment variable set."); + return false; + } #elif __APPLE__ // ------ Apple #else @@ -762,29 +803,69 @@ bool modelCDMProject::Build(std::string*& result, const std::string& line) return true; } -bool modelCDMProject::Connect(std::string*& result) +bool modelCDMProject::Connect(std::string*& result, const std::string& folder) { - //TODO: adjust for windows and mac + //TODO: adjust for mac #ifdef _WIN32 // ------ Windows + //open binary folder + wxDir dir(crea::std2wx(folder)); + + //if binary folder can't be opened then return false + if (!dir.IsOpened()) + { + result = new std::string("The path could not be opened. Make sure the folder exists and contains a bbtkPackage file."); + return false; + } + //create plug command + std::string plugComm = "bbPlugPackage \"" + folder + "\""; + std::cout << "executing '" << plugComm << "'" << std::endl; + //execute plug command + if(system(std::string("start cmd.exe /k \"" + plugComm + "\"").c_str())) + { + //if there was an error then report it + result = new std::string("There was an error plugging the packages of the project, please check the console to read more about the problem."); + return false; + } #elif __APPLE__ // ------ Apple #else // ------ Linux //open binary folder - wxDir dir(crea::std2wx((this->buildPath).c_str())); + wxDir dir(crea::std2wx(folder)); //if binary folder can't be opened then return false if (!dir.IsOpened()) { - result = new std::string("The build path could not be opened. Make sure to configure the project before compiling it"); + result = new std::string("The path could not be opened. Make sure the folder exists and contains a bbtkPackage file."); return false; } //create plug command - std::string plugComm = "bbPlugPackage \"" + this->buildPath + "\" > \"" + this->buildPath + CDMUtilities::SLASH + "plugging.log\" 2>&1"; - std::cout << "executing '" << plugComm << "'" << std::endl; + std::string plugComm = "bbPlugPackage \"" + this->buildPath + "\""; + + std::string Comm = "gnome-terminal -e \"bash -c \\\""; + for (int i = 0; i < plugComm.size(); i++) + { + if(plugComm[i] == '"') + { + Comm+="\\\\\\\""; + } + else if(plugComm[i] == '\\') + { + Comm+="\\\\\\\\"; + } + else + { + Comm.push_back(plugComm[i]); + } + } + Comm += "; echo -e '\\a'; bash"; + Comm += "\\\"\""; + + + std::cout << "executing '" << Comm << "'" << std::endl; //execute plug command - if(system(plugComm.c_str())) + if(system(Comm.c_str())) { //if there was an error then report it result = new std::string("There was an error plugging the packages of the project, please check the console to read more about the problem."); @@ -802,7 +883,7 @@ void modelCDMProject::CheckStructure(std::map& properties) //set properties parameters based on model properties["project add appli"] = this->appli != NULL; properties["project add lib"] = this->lib != NULL; - for (int i = 0; i < this->packages.size(); i++) + for (int i = 0; i < (int)(this->packages.size()); i++) properties["project add " + packages[i]->GetName()] = false; //open cmakelists @@ -824,7 +905,7 @@ void modelCDMProject::CheckStructure(std::map& properties) { word = words[0]; CDMUtilities::splitter::split(words, word, " ", CDMUtilities::splitter::empties_ok); - for (int i = 0; i < words.size(); i++) + for (int i = 0; i < (int)(words.size()); i++) { if(words[i].substr(0,2) == "//") break; @@ -922,9 +1003,127 @@ void modelCDMProject::CheckStructure(std::map& properties) //check lib's structure this->lib->CheckStructure(properties); //check packages' structure - for (int i = 0; i < this->packages.size(); i++) + for (int i = 0; i < (int)(this->packages.size()); i++) { properties["package " + this->packages[i]->GetName()] = true; this->packages[i]->CheckStructure(properties); } } + +bool modelCDMProject::IsPackageIncluded(const std::string& package_name) +{ + if(this->HasCMakeLists()) + { + std::ifstream CMFile(this->CMakeLists->GetPath().c_str()); + if (CMFile.is_open()) + { + std::string line; + while(!CMFile.eof()) + { + std::getline(CMFile, line); + while(line[0]==' ') + line.erase(0); + if(line[0] != '#') + { + std::vector lineSeg; + CDMUtilities::splitter::split(lineSeg,line,"()",CDMUtilities::splitter::no_empties); + if(lineSeg.size() > 0 && lineSeg[0] == "ADD_SUBDIRECTORY" && lineSeg[1] == package_name) + { + CMFile.close(); + return true; + } + } + } + CMFile.close(); + } + } + return false; +} + +bool modelCDMProject::SetPackageInclude(const std::string& package_name, const bool& toInclude) +{ + if (this->HasCMakeLists()) + { + std::ifstream CMFile(this->CMakeLists->GetPath().c_str()); + if (CMFile.is_open()) + { + std::stringstream outs; + std::string line; + bool found = false; + while(!CMFile.eof()) + { + std::getline(CMFile, line); + if (CMFile.eof()) { + break; + } + if(line != "") + { + std::vector segs; + CDMUtilities::splitter::split(segs, line, " ", CDMUtilities::splitter::no_empties); + //is comment + if(segs.size() > 0 && segs[0][0] == '#') + { + if(toInclude) + { + CDMUtilities::splitter::split(segs, line, " #()", CDMUtilities::splitter::no_empties); + if (segs.size() > 1 && segs[0] == "ADD_SUBDIRECTORY" && segs[1] == package_name) + { + found = true; + outs << "ADD_SUBDIRECTORY(" << package_name << ")\n"; + } + else + outs << line << "\n"; + } + else + { + outs << line << "\n"; + } + } + //is not comment + else + { + if (segs.size() > 0 && !toInclude) + { + CDMUtilities::splitter::split(segs, line, " ()", CDMUtilities::splitter::no_empties); + if (segs.size() > 1 && segs[0] == "ADD_SUBDIRECTORY" && segs[1] == package_name) + { + outs << "#" << line << "\n"; + } + else + { + outs << line << "\n"; + } + } + else + { + CDMUtilities::splitter::split(segs, line, " ()", CDMUtilities::splitter::no_empties); + if (segs.size() > 1 && segs[0] == "ADD_SUBDIRECTORY" && segs[1] == package_name) + { + found = true; + } + outs << line << "\n"; + } + } + } + else + { + outs << "\n"; + } + } + + CMFile.close(); + + if(!found && toInclude) + outs << "ADD_SUBDIRECTORY(" << package_name << ")\n"; + + std::ofstream CMFileOut(this->CMakeLists->GetPath().c_str()); + if (CMFileOut.is_open()) + { + CMFileOut << outs.rdbuf(); + CMFileOut.close(); + return true; + } + } + } + return false; +}