Skip to content

Commit b61e00c

Browse files
committed
recursive deps
1 parent ae14a74 commit b61e00c

File tree

6 files changed

+159
-71
lines changed

6 files changed

+159
-71
lines changed

module.cpp

+77-22
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ module::module(std::string basePath, std::string module)
5555
if(!module_header.empty())
5656
{
5757
getMetaData( utilities::normalize_path(module_header) );
58+
std::cout << module << " : metaData " << metaData.size() << std::endl;
59+
std::cout << "dependencies length: " << metaData["dependencies"].length() << std::endl;
5860
}
5961
}
6062

@@ -67,10 +69,41 @@ void module::print()
6769
std::cout << "Description : " << metaData["description"] << std::endl;
6870
std::cout << "Website : " << metaData["website"] << std::endl;
6971
std::cout << "License : " << metaData["license"] << std::endl;
70-
auto deps = getDependencies();
72+
73+
auto list = utilities::getValueList( metaData["dependencies"] );
74+
for(auto const& item : list)
75+
{
76+
std::cout << "<< dep >> " << item << std::endl;
77+
}
78+
79+
list = utilities::getValueList( metaData["OSXFrameworks"] );
80+
for(auto const& item : list)
81+
{
82+
std::cout << "<< OSXFramework >> " << item << std::endl;
83+
}
84+
85+
list = utilities::getValueList( metaData["iOSFrameworks"] );
86+
for(auto const& item : list)
87+
{
88+
std::cout << "<< iOSFrameworks >> " << item << std::endl;
89+
}
90+
91+
list = utilities::getValueList( metaData["linuxLibs"] );
92+
for(auto const& item : list)
93+
{
94+
std::cout << "<< linuxLibs >> " << item << std::endl;
95+
}
96+
97+
list = utilities::getValueList( metaData["linuxPackages"] );
98+
for(auto const& item : list)
99+
{
100+
std::cout << "<< linuxPackages >> " << item << std::endl;
101+
}
102+
103+
auto deps = utilities::getValueList( metaData["mingwLibs"] );
71104
for(auto const& dep : deps)
72105
{
73-
std::cout << "<< dep >> " << dep << std::endl;
106+
std::cout << "<< mingwLibs >> " << dep << std::endl;
74107
}
75108
}
76109

@@ -109,16 +142,34 @@ std::string module::getLicense()
109142
return metaData["license"];
110143
}
111144

112-
std::vector<std::string> module::getDependencies()
145+
std::string module::getDependencies()
113146
{
114-
std::string d = utilities::trim( metaData["dependencies"] );
115-
auto list = utilities::split(d,' ');
116-
for(auto &item : list)
117-
{
118-
std::string val = utilities::trim(item);
119-
item = utilities::remove(val, ",");
120-
}
121-
return list;
147+
return metaData["dependencies"];
148+
}
149+
150+
std::string module::getOSXFrameworks()
151+
{
152+
return metaData["OSXFrameworks"];
153+
}
154+
155+
std::string module::getiOSFrameworks()
156+
{
157+
return metaData["iOSFrameworks"];
158+
}
159+
160+
std::string module::getLinuxLibs()
161+
{
162+
return metaData["linuxLibs"];
163+
}
164+
165+
std::string module::getLinuxPackages()
166+
{
167+
return metaData["linuxPackages"];
168+
}
169+
170+
std::string module::getMingwLibs()
171+
{
172+
return metaData["mingwLibs"];
122173
}
123174

124175
void module::getMetaData(std::string inpfile)
@@ -138,8 +189,6 @@ void module::getMetaData(std::string inpfile)
138189
if (!is)
139190
throw std::runtime_error("Error opening file: " + inpfile);
140191

141-
metaData.clear();
142-
143192
std::string line;
144193
while (std::getline(is, line)) {
145194

@@ -159,31 +208,37 @@ void module::getMetaData(std::string inpfile)
159208
}
160209
else
161210
{
162-
ss << line << "\n";
211+
ss << line << " \n";
163212
}
164213
}
165214
}
166215

216+
metaData.clear();
217+
167218
std::string key;
168219
auto lines = utilities::split(ss.str(),'\n');
169220
for(auto &l : lines)
170221
{
171-
l = utilities::trim(l);
172222
if(l.find(':') != std::string::npos)
173223
{
174224
auto kv = utilities::split(l, ':');
175-
if(!kv.empty())
176-
{
177-
key = kv[0];
178-
metaData[key] = utilities::trim(kv[1]);
179-
}
225+
226+
std::string key = utilities::trim(kv[0]);
227+
std::string value = utilities::trim(kv[1]);
228+
229+
metaData[key] = value;
180230
}
181231
else
182232
{
183-
std::string value = metaData[key];
184-
metaData[key] += l;
233+
if(l.length() > 2)
234+
{
235+
std::replace( l.begin(), l.end(), ',', ' ');
236+
metaData[key] += " " + l;
237+
}
185238
}
186239
}
240+
241+
std::cout << "[dependencies] = [" << metaData["dependencies"] << "]" << std::endl;
187242
}
188243

189244
} //namespace pip2cmake

module.h

+7-3
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,18 @@ namespace pip2cmake
2020
std::string getDescription();
2121
std::string getWebsite();
2222
std::string getLicense();
23-
std::vector<std::string> getDependencies();
23+
std::string getDependencies();
24+
std::string getOSXFrameworks();
25+
std::string getiOSFrameworks();
26+
std::string getLinuxLibs();
27+
std::string getLinuxPackages();
28+
std::string getMingwLibs();
2429

2530
private:
2631
std::map<std::string, std::string> metaData;
2732
void getMetaData(std::string inpfile);
2833
void listFilesRecursively(std::string basePath, std::string filename);
29-
30-
std::string normalizePath(std::string &path);
34+
std::vector<std::string> getDependencies(std::string key);
3135

3236
std::string base_path;
3337
std::string sepd;

pip.cpp

+40-42
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ void pip::getMetaData(std::string inpfile)
3232
if (!is)
3333
throw std::runtime_error("Error opening file: " + inpfile);
3434

35-
metaData.clear();
36-
3735
std::string line;
3836
while (std::getline(is, line)) {
3937

@@ -58,27 +56,43 @@ void pip::getMetaData(std::string inpfile)
5856
}
5957
}
6058

59+
metaData.clear();
60+
6161
std::string key;
62+
std::string value;
6263
auto lines = utilities::split(ss.str(),'\n');
6364
for(auto &l : lines)
6465
{
65-
l = utilities::trim(l);
6666
if(l.find(':') != std::string::npos)
6767
{
6868
auto kv = utilities::split(l, ':');
69-
if(!kv.empty())
69+
70+
key = utilities::trim(kv[0]);
71+
value = utilities::trim(kv[1]);
72+
73+
if(value.find_last_of(",") == (value.length()-1))
7074
{
71-
key = kv[0];
72-
metaData[key] = utilities::trim(kv[1]);
75+
value.append(" ");
7376
}
77+
78+
metaData[key] = value;
7479
}
7580
else
7681
{
77-
std::string value = metaData[key];
78-
metaData[key] += l;
82+
if(l.length() > 2)
83+
{
84+
value = utilities::trim(l);
85+
if(value.find_last_of(",") == (value.length()-1))
86+
{
87+
value.append(" ");
88+
}
89+
metaData[key].append(value);
90+
}
7991
}
8092
}
8193

94+
std::cout << "[dependencies] = [" << metaData["dependencies"] << "]" << std::endl;
95+
8296
dependencies = utilities::split(metaData["dependencies"],',');
8397
for(auto &d : dependencies)
8498
{
@@ -98,24 +112,6 @@ void pip::getMetaData(std::string inpfile)
98112
}
99113
}
100114

101-
std::list<std::string> pip::getDependencies()
102-
{
103-
std::list<std::string> list;
104-
for(auto &item : modules)
105-
{
106-
list.push_back(item.second->getID());
107-
auto deps = item.second->getDependencies();
108-
for(auto &d : deps)
109-
{
110-
list.push_back(d);
111-
}
112-
}
113-
list.sort();
114-
list.unique();
115-
116-
return list;
117-
}
118-
119115
std::vector<std::string> pip::getExporters()
120116
{
121117
return exporters;
@@ -181,12 +177,6 @@ pip::pip(std::string infile, std::string outpath)
181177
getMetaData(infile);
182178

183179
getModules();
184-
185-
auto deps = getDependencies();
186-
for(auto &dep : deps)
187-
{
188-
std::cout << "dep: " << dep << std::endl;
189-
}
190180
}
191181

192182
void pip::print()
@@ -220,6 +210,7 @@ void pip::print()
220210
std::cout << "[Dependencies]\n";
221211
for(auto &mod : modules)
222212
{
213+
// std::cout << mod.second->getID() << std::endl;
223214
mod.second->print();
224215
}
225216
}
@@ -278,9 +269,23 @@ void pip::getModulesBasePath()
278269
}
279270
}
280271

281-
std::unique_ptr<module> pip::getModule(std::string name)
272+
void pip::addModulesRecursively(std::string dependencies)
282273
{
283-
return std::make_unique<module>(module_base_path, name);
274+
if(dependencies.empty())
275+
{
276+
return;
277+
}
278+
279+
auto list = utilities::getValueList(dependencies);
280+
281+
for(auto const& item : list)
282+
{
283+
if ( modules.find(item) == modules.end() )
284+
{
285+
modules[item] = std::make_unique<module>(module_base_path, item);
286+
addModulesRecursively( modules[item]->getDependencies() );
287+
}
288+
}
284289
}
285290

286291
void pip::getModules()
@@ -293,15 +298,8 @@ void pip::getModules()
293298
std::cout << "Module Base: " << module_base_path << std::endl;
294299

295300
modules.clear();
296-
for(auto const& item : dependencies)
297-
{
298-
modules[item] = getModule(item);
299-
}
300-
}
301301

302-
std::list<std::unique_ptr<module>> pip::getModuleList()
303-
{
304-
return std::list<std::unique_ptr<module>>();
302+
addModulesRecursively( metaData["dependencies"] );
305303
}
306304

307305
void pip::gen_cmake()

pip.h

+1-4
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ namespace pip2cmake
2222

2323
void gen_cmake();
2424
std::string get_cmake_file();
25-
std::list<std::string> getDependencies();
2625
std::vector<std::string> getExporters();
2726
std::vector<std::string> getModuleFlags();
2827
std::string getDescription();
@@ -33,13 +32,11 @@ namespace pip2cmake
3332
std::string getVersion();
3433
std::string getWebsite();
3534

36-
std::unique_ptr<module> getModule(std::string name);
37-
std::list<std::unique_ptr<module>> getModuleList();
38-
3935
private:
4036
void getMetaData(std::string inpfile);
4137
void getModules();
4238
void getModulesBasePath();
39+
void addModulesRecursively(std::string module);
4340
std::vector<std::string> dirSearch(const char* dir_path);
4441
std::string scandir_filter_value;
4542
static int scandir_filter_modules(const struct dirent* dir_ent);

utilities.cpp

+30
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <iostream>
66
#include <algorithm>
77
#include <stack>
8+
#include <map>
89

910
namespace pip2cmake
1011
{
@@ -38,6 +39,15 @@ namespace pip2cmake
3839
return s;
3940
}
4041

42+
bool replace(std::string& str, const std::string& from, const std::string& to)
43+
{
44+
size_t start_pos = str.find(from);
45+
if(start_pos == std::string::npos)
46+
return false;
47+
str.replace(start_pos, from.length(), to);
48+
return true;
49+
}
50+
4151
std::vector<std::string> split(const std::string& s, char delimiter)
4252
{
4353
std::vector<std::string> tokens;
@@ -50,6 +60,26 @@ namespace pip2cmake
5060
return tokens;
5161
}
5262

63+
std::vector<std::string> getValueList(std::string value)
64+
{
65+
if(value.empty())
66+
{
67+
return std::vector<std::string>();
68+
}
69+
70+
value = utilities::trim(value);
71+
while(replace(value, " ", " "));
72+
auto list = utilities::split(value,' ');
73+
//std::cout << "KeyValue List: [" << value << "]" << std::endl;
74+
for(auto &item : list)
75+
{
76+
std::replace( item.begin(), item.end(), ',', ' ');
77+
item = utilities::trim(item);
78+
}
79+
return list;
80+
}
81+
82+
5383
std::string normalize_path(std::string &path)
5484
{
5585
std::string sep = (path.find("\\") != std::string::npos) ? "\\" : "/";

0 commit comments

Comments
 (0)