6 #include <msp/fs/path.h>
17 Base class for tools. Tools are used to turn targets into other targets.
18 Examples include compilers and linkers.
23 typedef std::list<Msp::FS::Path> SearchPath;
24 typedef std::list<std::string> SuffixList;
28 const Architecture *architecture;
30 FileTarget *executable;
31 SuffixList input_suffixes;
32 SuffixList aux_suffixes;
33 SearchPath system_path;
35 std::list<std::string> problems;
37 Tool(Builder &, const std::string &);
38 Tool(Builder &, const Architecture &, const std::string &);
42 const std::string &get_tag() const { return tag; }
44 /** Returns the architecture this tool build for. May return null if the
45 tool is architecture-agnostic. */
46 const Architecture *get_architecture() const { return architecture; }
48 /** Returns a target for the tool's own executable. If the tool does not
49 use an external program, returns null. */
50 FileTarget *get_executable() const { return executable; }
52 /// Returns a list of suffixes that can be processed with this tool.
53 const SuffixList &get_input_suffixes() const { return input_suffixes; }
55 /** Returns a list of suffixes that are associated with this tool, but can't
56 be processed directly. For example C and C++ headers. */
57 const SuffixList &get_auxiliary_suffixes() const { return aux_suffixes; }
59 /** Indicates whether the tool can accept a suffix. If aux is true,
60 auxiliary suffixes are considered as well */
61 bool accepts_suffix(const std::string &, bool aux = false) const;
63 /// Returns the systemwide search path for source files.
64 const SearchPath &get_system_path() const { return system_path; }
66 /// Creates a source file appropriate for this tool.
67 virtual Target *create_source(const Component &, const Msp::FS::Path &) const { return 0; }
69 /** Creates a package-less source file appropriate for this tool. This is
70 called during dependency discovery when no package has created a target for
72 virtual Target *create_source(const Msp::FS::Path &) const { return 0; }
74 /// Convenience function to create a target from a single source.
75 Target *create_target(Target &, const std::string & = std::string());
77 /** Creates a target from sources. The exact types of accepted sources
78 depends on the tool. The optional second argument can be used to select an
79 alternative target type for tools that can create multiple kinds of targets. */
80 virtual Target *create_target(const std::list<Target *> &, const std::string & = std::string()) = 0;
82 /** Creates an install target for a target created by this tool. Can return
83 null if the tool does not want to handle installing in a special way. */
84 virtual Target *create_install(Target &) const { return 0; }
86 virtual std::string create_build_signature(const BuildInfo &) const { return std::string(); }
91 virtual void do_prepare() { }
93 /** Locates an executable for the tool from the VFS. If it isn't found, a
94 problem is reported. If cross is true and the architecture is not native,
95 a cross prefix is added to the command. */
96 void set_executable(const std::string &command, bool cross = false);
99 const std::list<std::string> &get_problems() const { return problems; }
101 /** Invokes the tool to build a target. This should not be called directly;
102 use Target::build() instead. */
103 virtual Task *run(const Target &) const = 0;
107 Intermediate base class for tool facets. For example, a linker may need to
108 use different commands depending on whether C++ source files are present or
109 not, but their presence can't be directly determined from the object files.
111 class SubTool: public Tool