-
Notifications
You must be signed in to change notification settings - Fork 6
/
HeaderDependencyBuild.cpp
61 lines (57 loc) · 1.67 KB
/
HeaderDependencyBuild.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include<iostream>
#include<fstream>
#include<set>
#include<algorithm>
#include<map>
#include<string>
template<typename T>
std::ostream& operator<<(std::ostream& os,std::set<T> const& l)
{
std::for_each(l.begin(),l.end(),
[&os](T t){
os<<" - "<<t<<"\n";
});
return os;
}
using namespace std;
// this files only requires list of files from grep and aftre that a little preprocessing
// grep '#include' * > files_list
// it outputs in following format
// file_name: #include "header.h" or <header.h>
// and this program takes format
// file_name header.h
// so all it requires is:
// a. removal of #include,
// b. removal of quotes/ angle brackets
// c. removal of the colon(:) sign
int main()
{
//the files is represented as follows
//file1 file2
//that means file1 includes file2 as header
const char* file_name = "files_list";
ifstream fp(file_name);
if(!fp.is_open())
return -1;
pair<string,string> file_include_pair;
map<string,set<string> > dep_list;
while(fp.good()){
fp >> file_include_pair.first;
fp >> file_include_pair.second;
//what we want is an index on header file
//so that we know how many files include this particular header-file
dep_list[file_include_pair.second].insert(file_include_pair.first);
}
//print the list
//make sure the dm_dir is already there
ofstream ofp("dm_dir/include_dependency.yaml");
if(!ofp.is_open())
return -1;
map<string,set<string> >::iterator dep_list_iter;
for_each(dep_list.begin(), dep_list.end(),
[&ofp](pair<string,set<string> > p){
std::cout<<"\nPrinting "<<p.first<<" and "<<p.second;
ofp<<p.first<<":\n"<<p.second<<"\n";
});
return 0;
}