Skip to content

Commit

Permalink
Fix nested dependencies (#252)
Browse files Browse the repository at this point in the history
#[changelog] #[pg]
  • Loading branch information
armadillu authored Oct 9, 2020
1 parent 90a1f0a commit e35cc07
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 22 deletions.
6 changes: 5 additions & 1 deletion ofxProjectGenerator/src/addons/ofAddon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ void ofAddon::parseConfig(){
}
}

void ofAddon::fromFS(string path, string platform){
bool ofAddon::fromFS(std::string path, const std::string & platform){
clear();
this->platform = platform;
string prefixPath;
Expand All @@ -464,6 +464,9 @@ void ofAddon::fromFS(string path, string platform){
prefixPath = pathToOF;
}

if(!ofDirectory::doesDirectoryExist(path)){
return false;
}

string srcPath = ofFilePath::join(path, "/src");
ofLogVerbose() << "in fromFS, trying src " << srcPath;
Expand Down Expand Up @@ -648,6 +651,7 @@ void ofAddon::fromFS(string path, string platform){

parseConfig();

return true;
}

//void ofAddon::fromXML(string installXmlName){
Expand Down
2 changes: 1 addition & 1 deletion ofxProjectGenerator/src/addons/ofAddon.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class ofAddon {

ofAddon();

void fromFS(std::string path, std::string platform);
bool fromFS(std::string path, const std::string & platform);
// void fromXML(std::string installXmlName);
void clear();

Expand Down
60 changes: 51 additions & 9 deletions ofxProjectGenerator/src/projects/baseProject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,30 +260,62 @@ bool baseProject::save(){
return saveProjectFile();
}

bool baseProject::isAddonInCache(const std::string & addonPath, const std::string platform){
auto it = addonsCache.find(platform);
if (it == addonsCache.end()) return false;
auto it2 = it->second.find(addonPath);
return it2 != it->second.end();
}


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



auto localPath = ofFilePath::join(addon.pathToProject, addonName);

bool addonOK = false;

bool inCache = isAddonInCache(addonName, target);
//inCache = false; //to test no-cache scenario

if (ofDirectory(addonName).exists()){
// if it's an absolute path, convert to relative...
string relativePath = ofFilePath::makeRelative(addon.pathToProject, addonName);
addonName = relativePath;
addon.isLocalAddon = true;
addon.fromFS(addonName, target);
if(!inCache){
addonOK = addon.fromFS(addonName, target);
}else{
addon = addonsCache[target][addonName];
addonOK = true;
}
} else if(ofDirectory(localPath).exists()){
addon.isLocalAddon = true;
addon.fromFS(addonName, target);
if(!inCache){
addonOK = addon.fromFS(addonName, target);
}else{
addon = addonsCache[target][addonName];
addonOK = true;
}
}else{
addon.isLocalAddon = false;
auto standardPath = ofFilePath::join(ofFilePath::join(getOFRoot(), "addons"), addonName);
addon.fromFS(standardPath, target);
if(!inCache){
addonOK = addon.fromFS(standardPath, target);
}else{
addon = addonsCache[target][addonName];
addonOK = true;
}
}
if(!addonOK){
ofLogVerbose() << "Ignoring addon that doesn't seem to exist: " << addonName;
return; //if addon does not exist, stop early
}

if(!inCache){
addonsCache[target][addonName] = addon; //cache the addon so we dont have to be reading form disk all the time
}
addAddon(addon);

// Process values from ADDON_DATA
Expand Down Expand Up @@ -401,14 +433,24 @@ void baseProject::addSrcRecursively(std::string srcPath){
}

void baseProject::addAddon(ofAddon & addon){

for(int i=0;i<(int)addons.size();i++){
if(addons[i].name==addon.name) return;
}
if(addons[i].name==addon.name){
return;
}
}

for(int i=0;i<addon.dependencies.size();i++){
addAddon(addon.dependencies[i]);
for(int j=0;j<(int)addons.size();j++){
if(addon.dependencies[i] != addons[j].name){ //make sure dependencies of addons arent already added to prj
addAddon(addon.dependencies[i]);
}else{
ofLogVerbose() << "trying to add duplicated addon dependency! skipping: " << addon.dependencies[i];
}
}
}


addons.push_back(addon);

ofLogVerbose("baseProject") << "libs in addAddon " << addon.libs.size();
Expand Down
4 changes: 4 additions & 0 deletions ofxProjectGenerator/src/projects/baseProject.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ class baseProject {

std::vector<ofAddon> addons;
std::vector<std::string> extSrcPaths;

//cached addons - if an addon is requested more than once, avoid loading from disk as it's quite slow
std::map<std::string,std::map<std::string, ofAddon>> addonsCache; //indexed by [platform][supplied path]
bool isAddonInCache(const std::string & addonPath, const std::string platform); //is this addon in the mem cache?
};


1 change: 1 addition & 0 deletions ofxProjectGenerator/src/projects/visualStudioProject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,7 @@ void visualStudioProject::addAddon(ofAddon & addon){
baseProject::addAddon(addon.dependencies[i]);
}

ofLogNotice() << "adding addon: " << addon.name;
addons.push_back(addon);

for(int i=0;i<(int)addon.includePaths.size();i++){
Expand Down
21 changes: 14 additions & 7 deletions ofxProjectGenerator/src/projects/xcodeProject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1223,16 +1223,27 @@ void xcodeProject::addCPPFLAG(std::string cppflag, LibType libType){
}

void xcodeProject::addAddon(ofAddon & addon){
ofLogNotice() << "adding addon " << addon.name;
for(int i=0;i<(int)addons.size();i++){
if(addons[i].name==addon.name) return;
if(addons[i].name==addon.name){
return;
}
}

for(int i=0;i<addon.dependencies.size();i++){
baseProject::addAddon(addon.dependencies[i]);
}

addons.push_back(addon);
for(int i=0;i<addon.dependencies.size();i++){
for(int j=0;j<(int)addons.size();j++){
if(addon.dependencies[i] != addons[j].name){ //make sure dependencies of addons arent already added to prj
baseProject::addAddon(addon.dependencies[i]);
}else{
//trying to add duplicated addon dependency... skipping!
}
}
}
ofLogNotice() << "adding addon: " << addon.name;
addons.push_back(addon);

for(int i=0;i<(int)addon.includePaths.size();i++){
ofLogVerbose() << "adding addon include path: " << addon.includePaths[i];
Expand Down Expand Up @@ -1293,9 +1304,5 @@ void xcodeProject::addAddon(ofAddon & addon){
addon.filesToFolders[addon.frameworks[i]]);
}
}

//

}

}
8 changes: 5 additions & 3 deletions ofxProjectGenerator/src/utils/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,9 +284,11 @@ void getFrameworksRecursively( const std::string & path, std::vector < std::stri



void getPropsRecursively(const std::string & path, std::vector < std::string > & props, std::string platform) {
ofDirectory dir;
dir.listDir(path);
void getPropsRecursively(const std::string & path, std::vector < std::string > & props, const std::string & platform) {

if(!ofDirectory::doesDirectoryExist(path)) return; //check for dir existing before listing to prevent lots of "source directory does not exist" errors printed on console
ofDirectory dir;
dir.listDir(path);

for (auto & temp : dir) {
if (temp.isDirectory()) {
Expand Down
2 changes: 1 addition & 1 deletion ofxProjectGenerator/src/utils/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ void getFoldersRecursively(const std::string & path, std::vector < std::string >
void getFilesRecursively(const std::string & path, std::vector < std::string > & fileNames);
void getLibsRecursively(const std::string & path, std::vector < std::string > & libFiles, std::vector < LibraryBinary > & libLibs, std::string platform = "", std::string arch = "", std::string target = "");
void getFrameworksRecursively( const std::string & path, std::vector < std::string > & frameworks, std::string platform = "" );
void getPropsRecursively(const std::string & path, std::vector < std::string > & props, std::string platform);
void getPropsRecursively(const std::string & path, std::vector < std::string > & props, const std::string & platform);
void getDllsRecursively(const std::string & path, std::vector < std::string > & dlls, std::string platform);


Expand Down

0 comments on commit e35cc07

Please sign in to comment.