From: Mikko Rasa Date: Sun, 8 Jul 2012 20:24:19 +0000 (+0300) Subject: Store a target representing the executable in each tool X-Git-Url: http://git.tdb.fi/?p=builder.git;a=commitdiff_plain;h=3e8f3a5e852e9dd5b78ec3d89c722ef1bae6bef5 Store a target representing the executable in each tool --- diff --git a/source/gnuarchiver.cpp b/source/gnuarchiver.cpp index 4916408..13b2054 100644 --- a/source/gnuarchiver.cpp +++ b/source/gnuarchiver.cpp @@ -16,6 +16,8 @@ using namespace Msp; GnuArchiver::GnuArchiver(Builder &b): Tool(b, "AR") { + executable = builder.get_vfs().find_binary("ar"); + input_suffixes.push_back(".o"); } @@ -45,7 +47,7 @@ Task *GnuArchiver::run(const Target &target) const const Component &comp = *lib.get_component(); vector argv; - argv.push_back("ar"); + argv.push_back(executable->get_path().str()); argv.push_back("rc"); FS::Path work_dir = comp.get_package().get_source(); diff --git a/source/gnucompiler.cpp b/source/gnucompiler.cpp index 5ecd293..87fd662 100644 --- a/source/gnucompiler.cpp +++ b/source/gnucompiler.cpp @@ -17,6 +17,8 @@ GnuCompiler::GnuCompiler(Builder &b, const string &t, const string &n): Tool(b, t), name(n) { + executable = builder.get_vfs().find_binary(name); + const Architecture &arch = builder.get_current_arch(); if(arch.is_native()) system_path.push_back("/usr/include"); @@ -40,7 +42,7 @@ Task *GnuCompiler::run(const Target &target) const const Component &comp = object.get_component(); ExternalTask::Arguments argv; - argv.push_back(name); + argv.push_back(executable->get_path().str()); argv.push_back("-c"); const BuildInfo &binfo = comp.get_build_info(); diff --git a/source/gnulinker.cpp b/source/gnulinker.cpp index 6eef8b3..32f2bf3 100644 --- a/source/gnulinker.cpp +++ b/source/gnulinker.cpp @@ -7,7 +7,7 @@ #include "component.h" #include "executable.h" #include "externaltask.h" -#include "gnucxxcompiler.h" +#include "gnucompiler.h" #include "gnulinker.h" #include "objectfile.h" #include "sharedlibrary.h" @@ -83,12 +83,20 @@ Task *GnuLinker::run(const Target &) const GnuLinker::Linker::Linker(GnuLinker &p, const string &compiler_tag): SubTool(p) { - if(compiler_tag=="CC") - command = "gcc"; - else if(compiler_tag=="CXX") - command = "g++"; + const Tool &compiler = builder.get_toolchain().get_tool(compiler_tag); + if(dynamic_cast(&compiler)) + executable = compiler.get_executable(); else - throw invalid_argument("GnuLinker::Linker::Linker"); + { + string command; + if(compiler_tag=="CC") + command = "gcc"; + else if(compiler_tag=="CXX") + command = "g++"; + else + throw invalid_argument("GnuLinker::Linker::Linker"); + executable = builder.get_vfs().find_binary(command); + } } Target *GnuLinker::Linker::create_target(const list &sources, const string &arg) const @@ -101,7 +109,7 @@ Task *GnuLinker::Linker::run(const Target &target) const const Binary &bin = dynamic_cast(target); vector argv; - argv.push_back(command); + argv.push_back(executable->get_path().str()); const Component &comp = *bin.get_component(); diff --git a/source/gnulinker.h b/source/gnulinker.h index 9f0475a..2fdaa3a 100644 --- a/source/gnulinker.h +++ b/source/gnulinker.h @@ -8,9 +8,6 @@ class GnuLinker: public Tool private: class Linker: public SubTool { - private: - std::string command; - public: Linker(GnuLinker &, const std::string &); diff --git a/source/tool.cpp b/source/tool.cpp index 1ab3660..a2c61bf 100644 --- a/source/tool.cpp +++ b/source/tool.cpp @@ -5,7 +5,8 @@ using namespace std; Tool::Tool(Builder &b, const string &t): builder(b), - tag(t) + tag(t), + executable(0) { } bool Tool::accepts_suffix(const string &suffix, bool aux) const diff --git a/source/tool.h b/source/tool.h index 36d1be1..7371103 100644 --- a/source/tool.h +++ b/source/tool.h @@ -7,6 +7,7 @@ class Builder; class Component; +class FileTarget; class Target; class Task; @@ -23,6 +24,7 @@ public: protected: Builder &builder; std::string tag; + FileTarget *executable; SuffixList input_suffixes; SuffixList aux_suffixes; SearchPath system_path; @@ -32,6 +34,8 @@ public: virtual ~Tool() { } const std::string &get_tag() const { return tag; } + // XXX The executable target should be retrieved when first needed + FileTarget *get_executable() const { return executable; } const SuffixList &get_input_suffixes() const { return input_suffixes; } const SuffixList &get_auxiliary_suffixes() const { return aux_suffixes; } bool accepts_suffix(const std::string &, bool = false) const;