]> git.tdb.fi Git - builder.git/blob - source/toolchain.cpp
Save caches before starting the build
[builder.git] / source / toolchain.cpp
1 #include <msp/core/maputils.h>
2 #include "tool.h"
3 #include "toolchain.h"
4
5 using namespace std;
6 using namespace Msp;
7
8 Toolchain::~Toolchain()
9 {
10         for(ToolMap::iterator i=tools.begin(); i!=tools.end(); ++i)
11                 delete i->second;
12         for(ToolchainList::iterator i=chains.begin(); i!=chains.end(); ++i)
13                 delete *i;
14 }
15
16 void Toolchain::add_tool(Tool *tool)
17 {
18         insert_unique(tools, tool->get_tag(), tool);
19 }
20
21 void Toolchain::add_toolchain(Toolchain *chain)
22 {
23         chains.push_back(chain);
24 }
25
26 bool Toolchain::has_tool(const string &tag) const
27 {
28         if(tools.count(tag))
29                 return true;
30         for(ToolchainList::const_iterator i=chains.begin(); i!=chains.end(); ++i)
31                 if((*i)->has_tool(tag))
32                         return true;
33         return false;
34 }
35
36 Tool &Toolchain::get_tool(const string &tag) const
37 {
38         if(!tools.count(tag))
39         {
40                 for(ToolchainList::const_iterator i=chains.begin(); i!=chains.end(); ++i)
41                         if((*i)->has_tool(tag))
42                                 return (*i)->get_tool(tag);
43         }
44
45         return *get_item(tools, tag);
46 }
47
48 Tool *Toolchain::get_tool_for_suffix(const string &suffix, bool aux) const
49 {
50         for(ToolMap::const_iterator i=tools.begin(); i!=tools.end(); ++i)
51                 if(i->second->accepts_suffix(suffix, aux))
52                         return i->second;
53
54         for(ToolchainList::const_iterator i=chains.begin(); i!=chains.end(); ++i)
55                 if(Tool *tool = (*i)->get_tool_for_suffix(suffix, aux))
56                         return tool;
57
58         return 0;
59 }