X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fgnuarchiver.cpp;h=dc0b78494c90f4293ba3fa50379cbf12a2a3d479;hb=edd4771292a2273080fbcbac266c6831834b0b86;hp=3f96cbfd9a94135d6c7c6348b3f91b53e358b3a0;hpb=25a315f3cb5805614c513ac762ea1bd512ce82cb;p=builder.git diff --git a/source/gnuarchiver.cpp b/source/gnuarchiver.cpp index 3f96cbf..dc0b784 100644 --- a/source/gnuarchiver.cpp +++ b/source/gnuarchiver.cpp @@ -1,11 +1,9 @@ #include #include #include -#include #include #include "builder.h" #include "component.h" -#include "externaltask.h" #include "gnuarchiver.h" #include "objectfile.h" #include "sourcepackage.h" @@ -15,60 +13,43 @@ using namespace std; using namespace Msp; GnuArchiver::GnuArchiver(Builder &b, const Architecture &a): - Tool(b, a, "AR") + Tool(b, &a, "AR") { - string command = "ar"; - if(architecture->is_cross()) - command = format("%s-%s", architecture->get_cross_prefix(), command); - executable = builder.get_vfs().find_binary(command); - + set_command("ar", true); input_suffixes.push_back(".o"); + processing_unit = COMPONENT; + set_run_external(_run); } -Target *GnuArchiver::create_target(const list &sources, const string &) const +Target *GnuArchiver::create_target(const vector &sources, const string &) { if(sources.empty()) throw invalid_argument("GnuArchiver::create_target"); - list objs; - for(list::const_iterator i=sources.begin(); i!=sources.end(); ++i) - { - if(ObjectFile *obj = dynamic_cast(*i)) - objs.push_back(obj); - else - throw invalid_argument("GnuArchiver::create_target"); - } + vector objs; + objs.reserve(sources.size()); + for(Target *s: sources) + objs.push_back(&dynamic_cast(*s)); - const Component &comp = objs.front()->get_component(); + const Component &comp = *objs.front()->get_component(); StaticLibrary *lib = new StaticLibrary(builder, comp, objs); lib->set_tool(*this); return lib; } -Task *GnuArchiver::run(const Target &target) const +ExternalTask::Arguments GnuArchiver::_run(const StaticLibrary &lib, FS::Path &work_dir) { - const StaticLibrary &lib = dynamic_cast(target); - const Component &comp = *lib.get_component(); + const Tool &tool = *lib.get_tool(); vector argv; - argv.push_back(executable->get_path().str()); + argv.push_back(tool.get_executable()->get_path().str()); argv.push_back("rc"); - FS::Path work_dir = comp.get_package().get_source(); - argv.push_back(relative(lib.get_path(), work_dir).str()); - const Target::Dependencies &deps = lib.get_depends(); - for(Target::Dependencies::const_iterator i=deps.begin(); i!=deps.end(); ++i) - if(ObjectFile *obj = dynamic_cast(*i)) + for(Target *d: lib.get_dependencies()) + if(ObjectFile *obj = dynamic_cast(d)) argv.push_back(relative(obj->get_path(), work_dir).str()); - if(!builder.get_dry_run()) - { - FS::mkpath(FS::dirname(lib.get_path()), 0755); - if(FS::exists(lib.get_path())) - FS::unlink(lib.get_path()); - } - - return new ExternalTask(argv, work_dir); + return argv; }