Skip to content

Commit

Permalink
PG of::filesystem fix (#322)
Browse files Browse the repository at this point in the history
  • Loading branch information
dimitre authored Mar 10, 2023
1 parent a0f7fbe commit ebeb73a
Show file tree
Hide file tree
Showing 11 changed files with 292 additions and 359 deletions.
284 changes: 147 additions & 137 deletions ofxProjectGenerator/src/addons/ofAddon.cpp

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions ofxProjectGenerator/src/projects/CBLinuxProject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ bool CBLinuxProject::createProjectFile(){
if (relRoot != "../../../"){
std::string relPath2 = relRoot;
relPath2.erase(relPath2.end()-1);
findandreplaceInTexfile(projectDir + "Makefile", "../../..", relPath2);
findandreplaceInTexfile(projectDir + "config.make", "../../..", relPath2);
findandreplaceInTexfile(projectDir / "Makefile", "../../..", relPath2);
findandreplaceInTexfile(projectDir / "config.make", "../../..", relPath2);
findandreplaceInTexfile(ofFilePath::join(projectDir , projectName + ".workspace"), "../../../", relRoot);
findandreplaceInTexfile(ofFilePath::join(projectDir , projectName + ".cbp"), "../../../", relRoot);
}
Expand Down
12 changes: 6 additions & 6 deletions ofxProjectGenerator/src/projects/CBWinProject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
std::string CBWinProject::LOG_NAME = "CBWinProject";
bool CBWinProject::createProjectFile(){

std::string project = projectDir + projectName + ".cbp";
std::string workspace = projectDir + projectName + ".workspace";
auto project = projectDir / (projectName + ".cbp");
auto workspace = projectDir / (projectName + ".workspace");


ofFile::copyFromTo(ofFilePath::join(templatePath,"emptyExample.cbp"),project, false, true);

ofFile::copyFromTo(ofFilePath::join(templatePath,"emptyExample.workspace"),workspace, false, true);
ofFile::copyFromTo(ofFilePath::join(templatePath,"icon.rc"), projectDir + "icon.rc", false, true);
ofFile::copyFromTo(ofFilePath::join(templatePath,"icon.rc"), projectDir / "icon.rc", false, true);

//let's do some renaming:
std::string relRoot = getOFRelPath(ofFilePath::removeTrailingSlash(projectDir));
Expand Down Expand Up @@ -48,7 +48,7 @@ bool CBWinProject::loadProjectFile(){

//project.open(ofFilePath::join(projectDir , projectName + ".cbp"));

ofFile project(projectDir + projectName + ".cbp");
ofFile project(projectDir / (projectName + ".cbp"));
if(!project.exists()){
ofLogError(LOG_NAME) << "error loading" << project.path() << "doesn't exist";
return false;
Expand All @@ -67,7 +67,7 @@ bool CBWinProject::saveProjectFile(){
ofLogError(LOG_NAME) << "can't set title";
}
}
return doc.save_file((projectDir + projectName + ".cbp").c_str());
return doc.save_file((projectDir / (projectName + ".cbp")).c_str());
}

void CBWinProject::addSrc(std::string srcName, std::string folder, SrcType type){
Expand All @@ -92,6 +92,6 @@ std::string CBWinProject::getName(){
return projectName;
}

std::string CBWinProject::getPath(){
of::filesystem::path CBWinProject::getPath(){
return projectDir;
}
2 changes: 1 addition & 1 deletion ofxProjectGenerator/src/projects/CBWinProject.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class CBWinProject: public baseProject {
void addLibrary(const LibraryBinary & lib);

std::string getName();
std::string getPath();
of::filesystem::path getPath();

static std::string LOG_NAME;

Expand Down
97 changes: 35 additions & 62 deletions ofxProjectGenerator/src/projects/baseProject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,17 +109,15 @@ vector<baseProject::Template> baseProject::listAvailableTemplates(std::string ta
return templates;
}

// FIXME: substitute to of::filesystem
bool baseProject::create(string path, std::string templateName){
cout << "baseProject::create " << path << endl;
bool baseProject::create(const of::filesystem::path & _path, std::string templateName){
templatePath = getPlatformTemplateDir();
addons.clear();
extSrcPaths.clear();
auto path = _path;

if(!ofFilePath::isAbsolute(path)){
path = (of::filesystem::current_path() / of::filesystem::path(path)).string();
}
// projectDir = ofFilePath::addTrailingSlash(path);
projectDir = path;

projectName = ofFilePath::getFileName(path);
Expand Down Expand Up @@ -160,68 +158,39 @@ bool baseProject::create(string path, std::string templateName){
parseConfigMake();

if (bDoesDirExist){

vector < string > fileNames;
getFilesRecursively(ofFilePath::join(projectDir , "src"), fileNames);

for (int i = 0; i < (int)fileNames.size(); i++){

fileNames[i].erase(fileNames[i].begin(), fileNames[i].begin() + projectDir.length());
getFilesRecursively(projectDir / "src", fileNames);

string first, last;
#ifdef TARGET_WIN32
splitFromLast(fileNames[i], "\\", first, last);
#else
splitFromLast(fileNames[i], "/", first, last);
#endif
if (fileNames[i] != "src/ofApp.cpp" &&
fileNames[i] != "src/ofApp.h" &&
fileNames[i] != "src/main.cpp" &&
fileNames[i] != "src/ofApp.mm" &&
fileNames[i] != "src/main.mm"){
addSrc(fileNames[i], first);
for (auto & f : fileNames) {
of::filesystem::path rel { of::filesystem::relative(f, projectDir) };
of::filesystem::path folder { rel.parent_path() };

std::string fileName = rel.string();

if (fileName != "src/ofApp.cpp" &&
fileName != "src/ofApp.h" &&
fileName != "src/main.cpp" &&
fileName != "src/ofApp.mm" &&
fileName != "src/main.mm") {
// cout << "add filename:: " << rel << " :: " << folder << endl;
addSrc(rel.string(), folder.string());
} else {
// cout << "not adding filename:: " << rel << " :: " << folder << endl;
}
}

// if( target == "ios" ){
// getFilesRecursively(ofFilePath::join(projectDir , "bin/data"), fileNames);
//
// for (int i = 0; i < (int)fileNames.size(); i++){
// fileNames[i].erase(fileNames[i].begin(), fileNames[i].begin() + projectDir.length());
//
// string first, last;
// splitFromLast(fileNames[i], "/", first, last);
// if (fileNames[i] != "Default.png" &&
// fileNames[i] != "src/ofApp.h" &&
// fileNames[i] != "src/main.cpp" &&
// fileNames[i] != "src/ofApp.mm" &&
// fileNames[i] != "src/main.mm"){
// addSrc(fileNames[i], first);
// }
// }
// }

// get a unique list of the paths that are needed for the includes.
list < string > paths;
vector < string > includePaths;
for (int i = 0; i < (int)fileNames.size(); i++){
size_t found;
#ifdef TARGET_WIN32
found = fileNames[i].find_last_of("\\");
#else
found = fileNames[i].find_last_of("/");
#endif
paths.push_back(fileNames[i].substr(0,found));
}

paths.sort();
paths.unique();
for (list<string>::iterator it=paths.begin(); it!=paths.end(); ++it){
includePaths.push_back(*it);
}

for (int i = 0; i < includePaths.size(); i++){
addInclude(includePaths[i]);
// only add unique paths
std::vector < of::filesystem::path > paths;
for (auto & f : fileNames) {
auto dir = of::filesystem::path(f).parent_path().filename();
if (std::find(paths.begin(), paths.end(), dir) == paths.end()) {
paths.emplace_back(dir);
// cout << "addInclude " << dir << endl;
addInclude(dir.string());
}
}

}
return true;
}
Expand Down Expand Up @@ -277,7 +246,9 @@ bool baseProject::isAddonInCache(const std::string & addonPath, const std::strin

void baseProject::addAddon(std::string addonName){
ofAddon addon;
addon.pathToOF = getOFRelPath(projectDir);
// cout << projectDir << endl;
addon.pathToOF = getOFRelPath(projectDir.string());
// cout << addon.pathToOF << endl;
addon.pathToProject = ofFilePath::getAbsolutePath(projectDir);

auto localPath = ofFilePath::join(addon.pathToProject, addonName);
Expand Down Expand Up @@ -383,7 +354,7 @@ void baseProject::addSrcRecursively(std::string srcPath){

std::map <std::string, std::string> uniqueIncludeFolders;
for( auto & fileToAdd : srcFilesToAdd){
// cout << "fileToAdd :: " << fileToAdd << endl;
//if it is an absolute path it is easy - add the file and enclosing folder to the project
if( ofFilePath::isAbsolute(fileToAdd) && !bMakeRelative ){
string folder = ofFilePath::getEnclosingDirectory(fileToAdd,false);
Expand Down Expand Up @@ -427,6 +398,7 @@ void baseProject::addSrcRecursively(std::string srcPath){
folder = ofFilePath::removeTrailingSlash(folder);

ofLogVerbose() << " adding file " << fileToAdd << " in folder " << folder << " to project ";

addSrc(relPathPathToAdd, folder);
uniqueIncludeFolders[includeFolder] = includeFolder;
}
Expand All @@ -435,6 +407,7 @@ void baseProject::addSrcRecursively(std::string srcPath){
//do it this way so we don't try and add a include folder for each file ( as it checks if they are already added ) so should be faster
for(auto & includeFolder : uniqueIncludeFolders){
ofLogVerbose() << " adding search include paths for folder " << includeFolder.second;
cout << "includeFolder.second " << includeFolder.second << endl;
addInclude(includeFolder.second);
}
}
Expand Down
7 changes: 4 additions & 3 deletions ofxProjectGenerator/src/projects/baseProject.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class baseProject {

virtual ~baseProject(){}

bool create(std::string path, std::string templateName="");
bool create(const of::filesystem::path & path, std::string templateName="");
void parseAddons();
void parseConfigMake();
bool save();
Expand Down Expand Up @@ -70,7 +70,8 @@ class baseProject {
virtual void addSrcRecursively(std::string srcPath);

std::string getName() { return projectName;}
std::string getPath() { return projectDir; }
// std::string getPath() { return projectDir; }
of::filesystem::path getPath() { return projectDir; }

std::vector<Template> listAvailableTemplates(std::string target);
std::unique_ptr<baseProject::Template> parseTemplate(const ofDirectory & templateDir);
Expand All @@ -79,7 +80,7 @@ class baseProject {
pugi::xml_document doc;
bool bLoaded;

std::string projectDir;
of::filesystem::path projectDir;
std::string projectName;
std::string templatePath;
std::string target;
Expand Down
10 changes: 5 additions & 5 deletions ofxProjectGenerator/src/projects/qtcreatorproject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ bool QtCreatorProject::createProjectFile(){
if (relRoot != "../../../"){
std::string relPath2 = relRoot;
relPath2.erase(relPath2.end()-1);
findandreplaceInTexfile(projectDir + "qtcreator.qbs", "../../..", relPath2);
findandreplaceInTexfile(projectDir + "Makefile", "../../..", relPath2);
findandreplaceInTexfile(projectDir + "config.make", "../../..", relPath2);
findandreplaceInTexfile(projectDir / "qtcreator.qbs", "../../..", relPath2);
findandreplaceInTexfile(projectDir / "Makefile", "../../..", relPath2);
findandreplaceInTexfile(projectDir / "config.make", "../../..", relPath2);
}

return true;
Expand All @@ -67,7 +67,7 @@ void QtCreatorProject::addSrc(std::string srcFile, std::string folder, baseProje
}

bool QtCreatorProject::loadProjectFile(){
ofFile project(projectDir + projectName + ".qbs",ofFile::ReadOnly,true);
ofFile project(projectDir / (projectName + ".qbs"),ofFile::ReadOnly,true);
if(!project.exists()){
ofLogError(LOG_NAME) << "error loading" << project.path() << "doesn't exist";
return false;
Expand Down Expand Up @@ -139,7 +139,7 @@ bool QtCreatorProject::saveProjectFile(){

// save final project
qbs.set(qbsStr);
ofFile project(projectDir + projectName + ".qbs",ofFile::WriteOnly,true);
ofFile project(projectDir / (projectName + ".qbs"),ofFile::WriteOnly,true);
project.writeFromBuffer(qbs);
return true;
}
Expand Down
8 changes: 4 additions & 4 deletions ofxProjectGenerator/src/projects/visualStudioProject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ bool visualStudioProject::createProjectFile(){
ofFile::copyFromTo(ofFilePath::join(templatePath,"emptyExample.vcxproj.user"),user, false, true);
ofFile::copyFromTo(ofFilePath::join(templatePath,"emptyExample.sln"),solution, false, true);
ofFile::copyFromTo(ofFilePath::join(templatePath,"emptyExample.vcxproj.filters"),filters, false, true);
ofFile::copyFromTo(ofFilePath::join(templatePath,"icon.rc"), projectDir + "icon.rc", false, true);
ofFile::copyFromTo(ofFilePath::join(templatePath,"icon.rc"), projectDir / "icon.rc", false, true);

ofFile filterFile(filters);
std::string temp = filterFile.readToBuffer();
Expand Down Expand Up @@ -54,7 +54,7 @@ bool visualStudioProject::createProjectFile(){

bool visualStudioProject::loadProjectFile(){

ofFile project(projectDir + projectName + ".vcxproj");
ofFile project(projectDir / (projectName + ".vcxproj"));
if(!project.exists()){
ofLogError(LOG_NAME) << "error loading " << project.path() << " doesn't exist";
return false;
Expand All @@ -67,11 +67,11 @@ bool visualStudioProject::loadProjectFile(){

bool visualStudioProject::saveProjectFile(){

std::string filters = projectDir + projectName + ".vcxproj.filters";
auto filters = projectDir / (projectName + ".vcxproj.filters");
filterXmlDoc.save_file(filters.c_str());


return doc.save_file((projectDir + projectName + ".vcxproj").c_str());
return doc.save_file((projectDir / (projectName + ".vcxproj")).c_str());
}


Expand Down
Loading

0 comments on commit ebeb73a

Please sign in to comment.