]> git.tdb.fi Git - builder.git/blob - source/tool.cpp
Use shortcut functions for find calls
[builder.git] / source / tool.cpp
1 #include <msp/core/algorithm.h>
2 #include <msp/strings/format.h>
3 #include "architecture.h"
4 #include "builder.h"
5 #include "tool.h"
6
7 using namespace std;
8 using namespace Msp;
9
10 Tool::Tool(Builder &b, const string &t):
11         builder(b),
12         architecture(0),
13         tag(t),
14         executable(0),
15         processing_unit(ONE_FILE),
16         prepared(false)
17 { }
18
19 Tool::Tool(Builder &b, const Architecture &a, const string &t):
20         builder(b),
21         architecture(&a),
22         tag(t),
23         executable(0),
24         processing_unit(ONE_FILE),
25         prepared(false)
26 { }
27
28 void Tool::set_command(const string &cmd, bool cross)
29 {
30         if(cmd.empty())
31                 throw invalid_argument("Tool::set_command");
32
33         if(cross && architecture->is_cross() && !FS::Path(cmd).is_absolute())
34                 command = format("%s-%s", architecture->get_cross_prefix(), cmd);
35         else
36                 command = cmd;
37 }
38
39 bool Tool::accepts_suffix(const string &suffix, bool aux) const
40 {
41         return (any_equals(input_suffixes, suffix) || (aux && any_equals(aux_suffixes, suffix)));
42 }
43
44 Target *Tool::create_target(Target &source, const string &arg)
45 {
46         list<Target *> sources;
47         sources.push_back(&source);
48         return create_target(sources, arg);
49 }
50
51 void Tool::prepare()
52 {
53         if(prepared)
54                 return;
55
56         prepared = true;
57         do_prepare();
58         if(!executable && !command.empty())
59         {
60                 executable = builder.get_vfs().find_binary(command);
61                 if(!executable)
62                 {
63                         builder.get_logger().log("problems", format("Can't find executable %s for %s", command, tag));
64                         problems.push_back(format("Can't find executable %s", command));
65                 }
66         }
67 }
68
69
70 SubTool::SubTool(Tool &p):
71         Tool(p),
72         parent(p)
73 { }
74
75 Target *SubTool::create_source(const Component &c, const FS::Path &p) const
76 {
77         return parent.create_source(c, p);
78 }
79
80 Target *SubTool::create_source(const FS::Path &p) const
81 {
82         return parent.create_source(p);
83 }
84
85 Target *SubTool::create_target(const list<Target *> &s, const string &a)
86 {
87         return parent.create_target(s, a);
88 }
89
90 Target *SubTool::create_install(Target &t) const
91 {
92         return parent.create_install(t);
93 }
94
95 string SubTool::create_build_signature(const BuildInfo &bi) const
96 {
97         return parent.create_build_signature(bi);
98 }
99
100
101 void operator>>(const LexicalConverter &conv, Tool::ProcessingUnit &unit)
102 {
103         const string &str = conv.get();
104         if(str=="FILE")
105                 unit = Tool::ONE_FILE;
106         else if(str=="DIRECTORY")
107                 unit = Tool::DIRECTORY;
108         else if(str=="COMPONENT")
109                 unit = Tool::COMPONENT;
110         else
111                 throw lexical_error(format("conversion of '%s' to ProcessingUnit", str));
112 }