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