Skip to content

Commit

Permalink
V76 - fix json issues and make library paths relative (#573)
Browse files Browse the repository at this point in the history
  • Loading branch information
dimitre authored Sep 12, 2024
1 parent 349c02d commit 7117f0d
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 46 deletions.
5 changes: 3 additions & 2 deletions commandLine/src/addons/ofAddon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -739,9 +739,9 @@ void ofAddon::parseLibsPath(const fs::path & libsPath, const fs::path & parentFo
// Maybe it is the same situation for all others fixPath occurences?
if (!isLocalAddon) {
for (auto & l : libs) {
// alert("fixpath before " + l.path);
// alert("fixpath before " + ofPathToString(l.path));
l.path = fixPath(l.path);
// alert("fixpath after " + l.path);
// alert("fixpath after " + ofPathToString(l.path));
}
}

Expand Down Expand Up @@ -871,6 +871,7 @@ bool ofAddon::fromFS(const fs::path & path, const string & platform){

// lib paths are directories to parse for libs
for (auto & a : libsPaths) {
// alert(a, 33);
parseLibsPath((path / a), parentFolder);
}

Expand Down
8 changes: 4 additions & 4 deletions commandLine/src/defines.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#define OFPROJECTGENERATOR_MAJOR_VERSION 0
#define OFPROJECTGENERATOR_MINOR_VERSION 75
#define OFPROJECTGENERATOR_PATCH_VERSION 0
#define OFPROJECTGENERATOR_MAJOR_VERSION "0"
#define OFPROJECTGENERATOR_MINOR_VERSION "76"
#define OFPROJECTGENERATOR_PATCH_VERSION "0"

#define PG_VERSION "0.75.0"
#define PG_VERSION (OFPROJECTGENERATOR_MAJOR_VERSION "." OFPROJECTGENERATOR_MINOR_VERSION "." OFPROJECTGENERATOR_PATCH_VERSION)
116 changes: 76 additions & 40 deletions commandLine/src/projects/xcodeProject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ void xcodeProject::saveMakefile(){


bool xcodeProject::loadProjectFile(){ //base
addCommand("# ---- PG VERSION " + getPGVersion());
addCommand("Add :_OFProjectGeneratorVersion string " + getPGVersion());

renameProject();
Expand Down Expand Up @@ -296,26 +297,26 @@ string xcodeProject::getFolderUUID(const fs::path & folder, bool isFolder, fs::p
addCommand("Add :objects:"+thisUUID+":name string " + folderName);

// FIXME: Inspect if this is really being used
// if (isFolder) {
// alert("getFolderUUID, isFolder INSIDE " , 31);
// fs::path filePath;
// fs::path filePath_full { relRoot / fullPath };
// // FIXME: known issue: doesn't handle files with spaces in name.
//
// if (fs::exists(filePath_full)) {
// filePath = filePath_full;
// }
// if (fs::exists(fullPath)) {
// filePath = fullPath;
// }
//
// if (!filePath.empty()) {
// addCommand("Add :objects:"+thisUUID+":path string " + ofPathToString(filePath));
// } else {
// }
// } else {
if (isFolder) {
alert("getFolderUUID, isFolder INSIDE " , 31);
fs::path filePath;
fs::path filePath_full { relRoot / fullPath };
// FIXME: known issue: doesn't handle files with spaces in name.

if (fs::exists(filePath_full)) {
filePath = filePath_full;
}
if (fs::exists(fullPath)) {
filePath = fullPath;
}

if (!filePath.empty()) {
addCommand("Add :objects:"+thisUUID+":path string " + ofPathToString(filePath));
} else {
}
} else {
// alert("getFolderUUID isFolder false", 31);
// }
}

addCommand("Add :objects:"+thisUUID+":isa string PBXGroup");

Expand Down Expand Up @@ -532,7 +533,8 @@ void xcodeProject::addInclude(const fs::path & includeName){
void xcodeProject::addLibrary(const LibraryBinary & lib){
// alert( "xcodeProject::addLibrary " + lib.path , 33);
for (auto & c : buildConfigs) {
addCommand("Add :objects:"+c+":buildSettings:OTHER_LDFLAGS: string " + ofPathToString(lib.path));
// addCommand("Add :objects:"+c+":buildSettings:OTHER_LDFLAGS: string " + ofPathToString(lib.path));
addCommand("Add :objects:"+c+":buildSettings:OTHER_LDFLAGS: string " + ofPathToString(fs::relative(lib.path)));
}
}

Expand Down Expand Up @@ -858,8 +860,6 @@ bool xcodeProject::saveProjectFile(){

// debugCommands = true;

// addCommand("# ---- PG VERSION " + getPGVersion());
// addCommand("Add :a_OFProjectGeneratorVersion string " + getPGVersion());

fileProperties fp;
// fp.isGroupWithoutFolder = true;
Expand Down Expand Up @@ -894,18 +894,27 @@ bool xcodeProject::saveProjectFile(){
// JSON Block - Multiplatform

std::ifstream contents(fileName);
// std::cout << contents.rdbuf() << std::endl;
json j;
try {
j = { json::parse(contents) };
} catch (json::parse_error& ex) {

// Ugly hack to make nlohmann json work with v 3.11.3
auto dump = j.dump(1, ' ');
if (dump[0] == '[') {
// alert("OWWW BUCETA", 31);
j = j[0];
}

} catch (json::parse_error & ex) {
ofLogError(xcodeProject::LOG_NAME) << "JSON parse error at byte" << ex.byte;
ofLogError(xcodeProject::LOG_NAME) << "fileName" << fileName;
}

contents.close();

for (auto & c : commands) {
//alert (c, 31);
// alert (c, 31);
// readable comments enabled now.
if (c != "" && c[0] != '#') {
vector<string> cols { ofSplitString(c, " ") };
Expand All @@ -916,47 +925,74 @@ bool xcodeProject::saveProjectFile(){
//if (cols[0] == "Set") {
try {
json::json_pointer p { json::json_pointer(thispath) };

if (cols[2] == "string") {
// find position after find word
auto stringStart { c.find("string ") + 7 };
j[p] = c.substr(stringStart);
try {
j[p] = c.substr(stringStart);
} catch (std::exception & e) {

ofLogError() << "substr " << c.substr(stringStart) << "\n" <<
"pointer " << p << "\n" <<
e.what();
}
// j[p] = cols[3];
}
else if (cols[2] == "array") {
j[p] = {};
try {
j[p] = {};
} catch (std::exception & e) {
ofLogError() << "array " << e.what();
}
}
} catch (std::exception & e) {
cout << "xcodeProject saveProjectFile() first json error " << endl;
cout << e.what() << endl;
cout << " error at this path: " << thispath << endl;
}
catch (std::exception & e) {
cout << "pointer " << thispath;
ofLogError(xcodeProject::LOG_NAME) << "first json error ";
ofLogError() << e.what();
ofLogError() << thispath;
ofLogError() << "-------------------------";
}


}
else {
thispath = thispath.substr(0, thispath.length() -1);
// cout << thispath << endl;
json::json_pointer p { json::json_pointer(thispath) };
try {
// Fixing XCode one item array issue
if (!j[p].is_array()) {
auto v { j[p] };
j[p] = json::array();
if (!v.is_null()) {
j[p].emplace_back(v);
}
}
// if (!j[p].is_array()) {
// cout << endl;
// alert (c, 31);
// cout << "this is not array, creating" << endl;
// cout << thispath << endl;
// auto v { j[p] };
// j[p] = json::array();
// if (!v.is_null()) {
// cout << "thispath" << endl;
// j[p].emplace_back(v);
// }
// }
// alert (c, 31);
// alert ("emplace back " + cols[3] , 32);
j[p].emplace_back(cols[3]);

} catch (std::exception & e) {
cout << "xcodeProject saveProjectFile() json error " << endl;
cout << e.what() << endl;
cout << " error at this path: " << thispath << endl;
ofLogError(xcodeProject::LOG_NAME) << "json error ";
ofLogError() << e.what();
ofLogError() << thispath;
ofLogError() << "-------------------------";
}
}
// alert("-----", 32);
}
}


std::ofstream jsonFile(fileName);

// This is not pretty but address some differences in nlohmann json 3.11.2 to 3.11.3
auto dump = j.dump(1, ' ');
if (dump[0] == '[') {
Expand Down

0 comments on commit 7117f0d

Please sign in to comment.