This is another piece required for inheritance-less tool customization.
build_info.libs.push_back("gnustl_static");
}
-void AndroidCompiler::do_prepare()
+void AndroidCompiler::do_prepare(ToolData &tool) const
{
- GnuCompiler::do_prepare();
+ const Architecture &arch = *static_cast<const Tool &>(tool).get_architecture();
+
+ GnuCompiler::do_prepare(tool);
if(tag=="CXX")
{
+ unsigned version = tool.extra_data;
string version_str = format("%d.%d.%d", version>>16, (version>>8)&0xFF, version&0xFF);
FS::Path libstdcxx_dir = ndk.get_root_dir()/"sources"/"cxx-stl"/"gnu-libstdc++";
FS::Path libstdcxx_path;
string::size_type dot = version_str.rfind('.');
if(dot==string::npos)
{
- problems.push_back("C++ standard library not found");
+ tool.problems.push_back("C++ standard library not found");
return;
}
}
FS::Path public_dir = libstdcxx_path/"include";
- system_path.push_back(public_dir);
- build_info.incpath.push_back(public_dir);
+ tool.system_path.push_back(public_dir);
+ tool.build_info.incpath.push_back(public_dir);
FS::Path arch_path = libstdcxx_path/"libs";
builder.get_logger().log("files", "Traversing %s", arch_path.str());
- string arch_dir = architecture->best_match(list_files(arch_path));
+ string arch_dir = arch.best_match(list_files(arch_path));
if(!arch_dir.empty())
{
- build_info.incpath.push_back(libstdcxx_path/"libs"/arch_dir/"include");
- build_info.libpath.push_back(libstdcxx_path/"libs"/arch_dir);
+ tool.build_info.incpath.push_back(libstdcxx_path/"libs"/arch_dir/"include");
+ tool.build_info.libpath.push_back(libstdcxx_path/"libs"/arch_dir);
}
}
}
AndroidCompiler(Builder &, const Architecture &, const std::string &, const AndroidNdk &);
protected:
- void do_prepare() override;
+ void do_prepare(ToolData &) const override;
};
#endif
return apk;
}
-void ApkBuilder::do_prepare()
+void ApkBuilder::do_prepare(ToolData &tool) const
{
- jarsigner = &builder.get_toolchain().get_tool("JSGN");
+ Tool *jarsigner = &builder.get_toolchain().get_tool("JSGN");
jarsigner->prepare();
+ tool.extra_data = jarsigner;
}
Task *ApkBuilder::_run(const AndroidPackageFile &apk)
task->set_stdin(FS::basename(input_path));
task->set_stdout(FS::relative(apk.get_path(), work_dir));
ChainedTask *chain = new ChainedTask(task);
- chain->add_task(tool.jarsigner->run(apk));
+ chain->add_task(tool.extra_data.value<Tool *>()->run(apk));
return chain;
}
class ApkBuilder: public Tool
{
-private:
- Tool *jarsigner = 0;
-
public:
ApkBuilder(Builder &);
Target *create_target(const std::vector<Target *> &, const std::string &) override;
protected:
- void do_prepare() override;
+ void do_prepare(ToolData &) const override;
private:
static Task *_run(const AndroidPackageFile &);
}
GnuCompiler::GnuCompiler(Builder &b, const Architecture &a, const string &t):
- Tool(b, &a, t),
- version(0)
+ Tool(b, &a, t)
{
if(tag=="CC")
{
return result;
}
-void GnuCompiler::do_prepare()
+void GnuCompiler::do_prepare(ToolData &tool) const
{
- prepare_syspath();
- prepare_version();
+ prepare_syspath(tool);
+ prepare_version(tool);
}
-void GnuCompiler::prepare_syspath()
+void GnuCompiler::prepare_syspath(ToolData &tool) const
{
bool path_found = false;
- const FS::Path &sysroot = build_info.sysroot;
+ const FS::Path &sysroot = tool.build_info.sysroot;
+ const std::string &tool_tag = static_cast<Tool &>(tool).get_tag();
- if(executable)
+ const FileTarget *exe = static_cast<Tool &>(tool).get_executable();
+ if(exe)
{
ExternalTask::Arguments argv;
- argv.push_back(executable->get_path().str());
+ argv.push_back(exe->get_path().str());
argv.push_back("-Wp,-v");
argv.push_back("-E");
if(tag=="CXX")
else if(record_path)
{
FS::Path path = strip(output.substr(start, newline-start));
- builder.get_logger().log("tools", "Got %s system path: %s", tag, path);
- system_path.push_back(path);
+ builder.get_logger().log("tools", "Got %s system path: %s", tool_tag, path);
+ tool.system_path.push_back(path);
}
start = newline+1;
}
if(!path_found)
{
- builder.get_logger().log("tools", "No %s system path found, using defaults", tag);
+ builder.get_logger().log("tools", "No %s system path found, using defaults", tool_tag);
+ const Architecture &arch = *static_cast<Tool &>(tool).get_architecture();
if(!sysroot.empty())
- system_path.push_back(sysroot/"usr/include");
- else if(architecture->is_native())
- system_path.push_back("/usr/include");
+ tool.system_path.push_back(sysroot/"usr/include");
+ else if(arch.is_native())
+ tool.system_path.push_back("/usr/include");
else
- system_path.push_back(format("/usr/%s/include", architecture->get_cross_prefix()));
+ tool.system_path.push_back(format("/usr/%s/include", arch.get_cross_prefix()));
}
}
-void GnuCompiler::prepare_version()
+void GnuCompiler::prepare_version(ToolData &tool) const
{
- if(!executable)
+ const FileTarget *exe = static_cast<Tool &>(tool).get_executable();
+ if(!exe)
return;
- string exe_path = executable->get_path().str();
- version = query_version("-dumpversion");
+ string exe_path = exe->get_path().str();
+ unsigned version = query_version(exe_path, "-dumpversion");
if(version>=0x70000)
- version = query_version("-dumpfullversion");
- builder.get_logger().log("tools", "%s version is %d.%d.%d", FS::basename(executable->get_path()), version>>16, (version>>8)&0xFF, version&0xFF);
+ version = query_version(exe_path, "-dumpfullversion");
+ tool.extra_data = version;
+ builder.get_logger().log("tools", "%s version is %d.%d.%d", FS::basename(exe->get_path()), version>>16, (version>>8)&0xFF, version&0xFF);
}
-unsigned GnuCompiler::query_version(const string &arg) const
+unsigned GnuCompiler::query_version(const string &exe_path, const string &arg) const
{
ExternalTask::Arguments argv;
- argv.push_back(executable->get_path().str());
+ argv.push_back(exe_path);
argv.push_back(arg);
builder.get_logger().log("auxcommands", "Running %s", join(argv.begin(), argv.end()));
Task *GnuCompiler::_run(const ObjectFile &object)
{
- const GnuCompiler &tool = dynamic_cast<const GnuCompiler &>(*object.get_tool());
+ const Tool &tool = *object.get_tool();
const Architecture &arch = *tool.get_architecture();
ExternalTask::Arguments argv;
{
argv.push_back("-Wextra");
argv.push_back("-Wundef");
- if(tool.version>=0x80000)
+ unsigned version = tool.get_extra_data();
+ if(version>=0x80000)
argv.push_back("-Wno-cast-function-type");
}
if(binfo.warning_level>=3)
*/
class GnuCompiler: public Tool
{
-protected:
- unsigned version;
-
public:
GnuCompiler(Builder &, const Architecture &, const std::string &);
Target *create_target(const std::vector<Target *> &, const std::string &) override;
std::string create_build_signature(const BuildInfo &) const override;
protected:
- void do_prepare() override;
- void prepare_syspath();
- void prepare_version();
- unsigned query_version(const std::string &) const;
+ void do_prepare(ToolData &) const override;
+ void prepare_syspath(ToolData &) const;
+ void prepare_version(ToolData &) const;
+ unsigned query_version(const std::string &, const std::string &) const;
private:
static Task *_run(const ObjectFile &);
return result;
}
-void GnuLinker::do_prepare()
+void GnuLinker::do_prepare(ToolData &tool) const
{
bool path_found = false;
- const FS::Path &sysroot = build_info.sysroot;
+ const FS::Path &sysroot = tool.build_info.sysroot;
+ const std::string &tool_tag = static_cast<Tool &>(tool).get_tag();
- if(executable)
+ const FileTarget *exe = static_cast<Tool &>(tool).get_executable();
+ if(exe)
{
ExternalTask::Arguments argv;
- argv.push_back(executable->get_path().str());
+ argv.push_back(exe->get_path().str());
argv.push_back("-Wl,--verbose");
argv.push_back("-nostdlib");
if(!sysroot.empty())
}
path /= output.substr(search_dir, end-search_dir);
- builder.get_logger().log("tools", "Got %s system path: %s", tag, path);
- system_path.push_back(path);
+ builder.get_logger().log("tools", "Got %s system path: %s", tool_tag, path);
+ tool.system_path.push_back(path);
path_found = true;
start = end+3;
if(!path_found)
{
- builder.get_logger().log("tools", "No %s system path found, using defaults", tag);
+ builder.get_logger().log("tools", "No %s system path found, using defaults", tool_tag);
if(!sysroot.empty())
- system_path.push_back(sysroot/"usr/lib");
+ tool.system_path.push_back(sysroot/"usr/lib");
else if(architecture->is_native())
{
- system_path.push_back("/lib");
- system_path.push_back("/usr/lib");
+ tool.system_path.push_back("/lib");
+ tool.system_path.push_back("/usr/lib");
if(architecture->match_name("pc-32-linux"))
{
- system_path.push_back("/lib/i386-linux-gnu");
- system_path.push_back("/usr/lib/i386-linux-gnu");
+ tool.system_path.push_back("/lib/i386-linux-gnu");
+ tool.system_path.push_back("/usr/lib/i386-linux-gnu");
}
else if(architecture->match_name("pc-64-linux"))
{
- system_path.push_back("/lib/x86_64-linux-gnu");
- system_path.push_back("/usr/lib/x86_64-linux-gnu");
+ tool.system_path.push_back("/lib/x86_64-linux-gnu");
+ tool.system_path.push_back("/usr/lib/x86_64-linux-gnu");
}
}
else
- system_path.push_back(format("/usr/%s/lib", architecture->get_cross_prefix()));
+ tool.system_path.push_back(format("/usr/%s/lib", architecture->get_cross_prefix()));
}
}
Target *create_install(Target &) const override;
std::string create_build_signature(const BuildInfo &) const override;
protected:
- void do_prepare() override;
+ void do_prepare(ToolData &) const override;
private:
static Task *_run(const Binary &);
};
return result;
}
-void MsvcCompiler::do_prepare()
+void MsvcCompiler::do_prepare(ToolData &tool) const
{
+ const std::string &tool_tag = static_cast<Tool &>(tool).get_tag();
+
const FS::Path &vc_base_dir = ms_tools.get_vc_base_dir();
- system_path.push_back(vc_base_dir/"include");
+ tool.system_path.push_back(vc_base_dir/"include");
const FS::Path &win_sdk_dir = ms_tools.get_windows_sdk_dir();
const string &win_sdk_ver = ms_tools.get_windows_sdk_version();
- system_path.push_back(win_sdk_dir/"include"/win_sdk_ver/"ucrt");
- system_path.push_back(win_sdk_dir/"include"/win_sdk_ver/"shared");
- system_path.push_back(win_sdk_dir/"include"/win_sdk_ver/"um");
+ tool.system_path.push_back(win_sdk_dir/"include"/win_sdk_ver/"ucrt");
+ tool.system_path.push_back(win_sdk_dir/"include"/win_sdk_ver/"shared");
+ tool.system_path.push_back(win_sdk_dir/"include"/win_sdk_ver/"um");
string path;
- for(const FS::Path &p: system_path)
+ for(const FS::Path &p: tool.system_path)
{
append(path, ";", p.str());
- builder.get_logger().log("tools", "Got %s system path: %s", tag, p);
+ builder.get_logger().log("tools", "Got %s system path: %s", tool_tag, p);
}
setenv("INCLUDE", path);
std::string create_build_signature(const BuildInfo &) const override;
protected:
- void do_prepare() override;
+ void do_prepare(ToolData &) const override;
public:
static Task *_run(const ObjectFile &);
return result;
}
-void MsvcLinker::do_prepare()
+void MsvcLinker::do_prepare(ToolData &tool) const
{
- string arch_dir = (architecture->get_bits()==64 ? "x64" : "x86");
+ const std::string &tool_tag = static_cast<Tool &>(tool).get_tag();
+ const Architecture &arch = *static_cast<Tool &>(tool).get_architecture();
+ string arch_dir = (arch.get_bits()==64 ? "x64" : "x86");
const FS::Path &vc_base_dir = ms_tools.get_vc_base_dir();
- system_path.push_back(vc_base_dir/"lib"/arch_dir);
+ tool.system_path.push_back(vc_base_dir/"lib"/arch_dir);
const FS::Path &win_sdk_dir = ms_tools.get_windows_sdk_dir();
const string &win_sdk_ver = ms_tools.get_windows_sdk_version();
- system_path.push_back(win_sdk_dir/"lib"/win_sdk_ver/"ucrt"/arch_dir);
- system_path.push_back(win_sdk_dir/"lib"/win_sdk_ver/"um"/arch_dir);
+ tool.system_path.push_back(win_sdk_dir/"lib"/win_sdk_ver/"ucrt"/arch_dir);
+ tool.system_path.push_back(win_sdk_dir/"lib"/win_sdk_ver/"um"/arch_dir);
string path;
- for(const FS::Path &p: system_path)
+ for(const FS::Path &p: tool.system_path)
{
append(path, ";", p.str());
- builder.get_logger().log("tools", "Got %s system path: %s", tag, p);
+ builder.get_logger().log("tools", "Got %s system path: %s", tool_tag, p);
}
setenv("LIB", path);
std::string create_build_signature(const BuildInfo &) const override;
protected:
- void do_prepare() override;
+ void do_prepare(ToolData &data) const override;
public:
static Task *_run(const Binary &);
return create_target(sources, arg);
}
-void Tool::prepare()
+void Tool::prepare(Tool *tool)
{
- if(prepared)
+ if(!tool)
+ tool = this;
+ else if(tool->get_base_tool()!=this)
+ throw invalid_argument("Tool::prepare");
+
+ if(tool->prepared)
return;
- prepared = true;
- if(!command.empty())
- executable = builder.get_vfs().find_binary(command);
- do_prepare();
+ tool->prepared = true;
+ if(!tool->command.empty())
+ tool->executable = builder.get_vfs().find_binary(tool->command);
+ do_prepare(*tool);
if(!command.empty() && !executable)
{
- builder.get_logger().log("problems", "Can't find executable %s for %s", command, tag);
- problems.push_back(format("Can't find executable %s", command));
+ builder.get_logger().log("problems", "Can't find executable %s for %s", tool->command, tool->tag);
+ tool->problems.push_back(format("Can't find executable %s", tool->command));
}
}
class FileTarget;
class Target;
+class ToolData
+{
+public:
+ VirtualFileSystem::SearchPath system_path;
+ BuildInfo build_info;
+ Msp::Variant extra_data;
+ std::vector<std::string> problems;
+};
+
/**
Base class for tools. Tools are used to turn targets into other targets.
Examples include compilers and linkers.
*/
-class Tool
+class Tool: protected ToolData
{
public:
enum ProcessingUnit
std::vector<std::string> input_suffixes;
std::vector<std::string> aux_suffixes;
ProcessingUnit processing_unit = ONE_FILE;
- VirtualFileSystem::SearchPath system_path;
- BuildInfo build_info;
std::function<Task *(const Target &)> run_func;
bool prepared = false;
- std::vector<std::string> problems;
Tool(Builder &b, const std::string &t): Tool(b, 0, t) { }
Tool(Builder &b, const Architecture *a, const std::string &t): builder(b), architecture(a), tag(t) { }
+
public:
virtual ~Tool() { }
tool is architecture-agnostic. */
const Architecture *get_architecture() const { return architecture; }
+ virtual const Tool *get_base_tool() const { return this; }
+
protected:
void set_run(std::function<Task *(const Target &)>);
the chain. */
const BuildInfo &get_build_info() const { return build_info; }
+ const Msp::Variant &get_extra_data() const { return extra_data; }
+
/// Creates a source file appropriate for this tool.
virtual Target *create_source(const Component &, const Msp::FS::Path &) const { return 0; }
virtual std::string create_build_signature(const BuildInfo &) const;
- void prepare();
+ void prepare(Tool * = 0);
protected:
- virtual void do_prepare() { }
+ virtual void do_prepare(ToolData &) const { }
public:
const std::vector<std::string> &get_problems() const { return problems; }