]> git.tdb.fi Git - builder.git/blob - source/tool.cpp
6e2b21431fc5d1808fef9fd691ccd83ff1bd3275
[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 void Tool::set_run(function<Task *(const Target &)> f)
24 {
25         run_func = move(f);
26 }
27
28 bool Tool::accepts_suffix(const string &suffix, bool aux) const
29 {
30         return (any_equals(input_suffixes, suffix) || (aux && any_equals(aux_suffixes, suffix)));
31 }
32
33 Target *Tool::create_target(Target &source, const string &arg)
34 {
35         vector<Target *> sources;
36         sources.push_back(&source);
37         return create_target(sources, arg);
38 }
39
40 void Tool::prepare()
41 {
42         if(prepared)
43                 return;
44
45         prepared = true;
46         if(!command.empty())
47                 executable = builder.get_vfs().find_binary(command);
48         do_prepare();
49         if(!executable)
50         {
51                 builder.get_logger().log("problems", "Can't find executable %s for %s", command, tag);
52                 problems.push_back(format("Can't find executable %s", command));
53         }
54 }
55
56 string Tool::create_build_signature(const BuildInfo &) const
57 {
58         if(executable)
59                 return format("%s=%s", tag, FS::basename(executable->get_path()));
60         else
61                 return string();
62 }
63
64
65 Target *SubTool::create_source(const Component &c, const FS::Path &p) const
66 {
67         return parent.create_source(c, p);
68 }
69
70 Target *SubTool::create_source(const FS::Path &p) const
71 {
72         return parent.create_source(p);
73 }
74
75 Target *SubTool::create_target(const vector<Target *> &s, const string &a)
76 {
77         return parent.create_target(s, a);
78 }
79
80 Target *SubTool::create_install(Target &t) const
81 {
82         return parent.create_install(t);
83 }
84
85 string SubTool::create_build_signature(const BuildInfo &bi) const
86 {
87         return parent.create_build_signature(bi);
88 }
89
90
91 void operator>>(const LexicalConverter &conv, Tool::ProcessingUnit &unit)
92 {
93         const string &str = conv.get();
94         if(str=="FILE")
95                 unit = Tool::ONE_FILE;
96         else if(str=="DIRECTORY")
97                 unit = Tool::DIRECTORY;
98         else if(str=="COMPONENT")
99                 unit = Tool::COMPONENT;
100         else
101                 throw lexical_error(format("conversion of '%s' to ProcessingUnit", str));
102 }