6 #include <msp/fs/path.h>
18 Base class for tools. Tools are used to turn targets into other targets.
19 Examples include compilers and linkers.
31 typedef std::list<Msp::FS::Path> SearchPath;
32 typedef std::list<std::string> SuffixList;
36 const Architecture *architecture;
39 FileTarget *executable;
40 SuffixList input_suffixes;
41 SuffixList aux_suffixes;
42 ProcessingUnit processing_unit;
43 SearchPath system_path;
46 std::list<std::string> problems;
48 Tool(Builder &, const std::string &);
49 Tool(Builder &, const Architecture &, const std::string &);
53 const std::string &get_tag() const { return tag; }
55 /** Returns the architecture this tool build for. May return null if the
56 tool is architecture-agnostic. */
57 const Architecture *get_architecture() const { return architecture; }
59 /** Overrides the command used by the tool. The new command should accept
60 the same command line arguments. Only works on tools that use an external
61 command. If cross is true and the architecture is not native, a cross
62 prefix is added to the command. May have no effect after prepare() has been
64 void set_command(const std::string &cmd, bool cross = false);
66 /** Returns a target for the tool's own executable. If the tool does not
67 use an external program, returns null. The tool must be prepared first. */
68 FileTarget *get_executable() const { return executable; }
70 /// Returns a list of suffixes that can be processed with this tool.
71 const SuffixList &get_input_suffixes() const { return input_suffixes; }
73 /** Returns a list of suffixes that are associated with this tool, but can't
74 be processed directly. For example C and C++ headers. */
75 const SuffixList &get_auxiliary_suffixes() const { return aux_suffixes; }
77 /** Indicates whether the tool can accept a suffix. If aux is true,
78 auxiliary suffixes are considered as well */
79 bool accepts_suffix(const std::string &, bool aux = false) const;
81 /** Returns the grouping unit this tool prefers to process. */
82 ProcessingUnit get_processing_unit() const { return processing_unit; }
84 /// Returns the systemwide search path for source files.
85 const SearchPath &get_system_path() const { return system_path; }
87 /** Returns tool-specific build info. This can be used by other tools down
89 const BuildInfo &get_build_info() const { return build_info; }
91 /// Creates a source file appropriate for this tool.
92 virtual Target *create_source(const Component &, const Msp::FS::Path &) const { return 0; }
94 /** Creates a package-less source file appropriate for this tool. This is
95 called during dependency discovery when no package has created a target for
97 virtual Target *create_source(const Msp::FS::Path &) const { return 0; }
99 /// Convenience function to create a target from a single source.
100 Target *create_target(Target &, const std::string & = std::string());
102 /** Creates a target from sources. The exact types of accepted sources
103 depends on the tool. The optional second argument can be used to select an
104 alternative target type for tools that can create multiple kinds of targets. */
105 virtual Target *create_target(const std::list<Target *> &, const std::string & = std::string()) = 0;
107 /** Creates an install target for a target created by this tool. Can return
108 null if the tool does not want to handle installing in a special way. */
109 virtual Target *create_install(Target &) const { return 0; }
111 virtual std::string create_build_signature(const BuildInfo &) const { return std::string(); }
116 virtual void do_prepare() { }
119 const std::list<std::string> &get_problems() const { return problems; }
121 /** Invokes the tool to build a target. This should not be called directly;
122 use Target::build() instead. */
123 virtual Task *run(const Target &) const = 0;
127 Intermediate base class for tool facets. For example, a linker may need to
128 use different commands depending on whether C++ source files are present or
129 not, but their presence can't be directly determined from the object files.
131 class SubTool: public Tool
139 virtual Target *create_source(const Component &, const Msp::FS::Path &) const;
140 virtual Target *create_source(const Msp::FS::Path &) const;
141 virtual Target *create_target(const std::list<Target *> &, const std::string & = std::string());
142 virtual Target *create_install(Target &) const;
143 virtual std::string create_build_signature(const BuildInfo &) const;
147 void operator>>(const Msp::LexicalConverter &, Tool::ProcessingUnit &);