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