]> git.tdb.fi Git - builder.git/blob - source/buildinfo.cpp
Make BuildInfo able to handle chained dependencies
[builder.git] / source / buildinfo.cpp
1 #include <algorithm>
2 #include "buildinfo.h"
3
4 using namespace std;
5 using namespace Msp;
6
7 namespace {
8
9 /** Removes any duplicate entries from a list, leaving only the first one.  The
10 order of other elements is preserved.  O(n²) efficiency. */
11 void unique(StringList &l)
12 {
13         for(StringList::iterator i=l.begin(); i!=l.end(); ++i)
14                 for(StringList::iterator j=i; j!=l.end();)
15                 {
16                         if(j!=i && *j==*i)
17                                 j = l.erase(j);
18                         else
19                                 ++j;
20                 }
21 }
22
23 }
24
25
26 void BuildInfo::update_from(const BuildInfo &bi, UpdateLevel level)
27 {
28         cflags.insert(cflags.end(), bi.cflags.begin(), bi.cflags.end());
29         defines.insert(defines.end(), bi.defines.begin(), bi.defines.end());
30         incpath.insert(incpath.end(), bi.incpath.begin(), bi.incpath.end());
31         if(level!=CHAINED)
32         {
33                 ldflags.insert(ldflags.end(), bi.ldflags.begin(), bi.ldflags.end());
34                 libpath.insert(libpath.end(), bi.libpath.begin(), bi.libpath.end());
35                 libs.insert(libs.end(), bi.libs.begin(), bi.libs.end());
36         }
37         warnings.insert(warnings.end(), bi.warnings.begin(), bi.warnings.end());
38 }
39
40 void BuildInfo::unique()
41 {
42         ::unique(cflags);
43         ::unique(defines);
44         ::unique(incpath);
45         ::unique(ldflags);
46         ::unique(libpath);
47         ::unique(libs);
48
49         for(StringList::iterator i=warnings.begin(); i!=warnings.end(); ++i)
50         {
51                 bool flag = i->compare(0, 3, "no-");
52
53                 string warn = (flag ? *i : i->substr(3));
54                 string no_warn = "no-"+warn;
55
56                 for(StringList::iterator j=i; j!=warnings.end();)
57                 {
58                         if(j!=i && (*j==warn || *j==no_warn))
59                         {
60                                 flag = (*j==warn);
61                                 j = warnings.erase(j);
62                         }
63                         else
64                                 ++j;
65                 }
66
67                 *i = (flag ? warn : no_warn);
68         }
69 }
70
71
72 BuildInfo::Loader::Loader(BuildInfo &bi):
73         DataFile::ObjectLoader<BuildInfo>(bi)
74 {
75         add("cflag",   &Loader::cflag);
76         add("incpath", &Loader::incpath);
77         add("define",  &Loader::define);
78         add("ldflag",  &Loader::ldflag);
79         add("libpath", &Loader::libpath);
80         add("library", &Loader::library);
81         add("warning", &Loader::warning);
82 }
83
84 void BuildInfo::Loader::cflag(const std::string &s)
85 {
86         obj.cflags.push_back(s);
87 }
88
89 void BuildInfo::Loader::incpath(const std::string &s)
90 {
91         obj.incpath.push_back(s);
92 }
93
94 void BuildInfo::Loader::define(const std::string &s)
95 {
96         obj.defines.push_back(s);
97 }
98
99 void BuildInfo::Loader::ldflag(const std::string &s)
100 {
101         obj.ldflags.push_back(s);
102 }
103
104 void BuildInfo::Loader::libpath(const std::string &s)
105 {
106         obj.libpath.push_back(s);
107 }
108
109 void BuildInfo::Loader::library(const std::string &s)
110 {
111         obj.libs.push_back(s);
112 }
113
114 void BuildInfo::Loader::warning(const std::string &s)
115 {
116         obj.warnings.push_back(s);
117 }