]> git.tdb.fi Git - builder.git/blobdiff - source/gnuarchiver.cpp
Use dynamic_cast to reference when incorrect type is not acceptable
[builder.git] / source / gnuarchiver.cpp
index 7482b0d17caf004d66125f4a82c8c098d0bb2331..f802031f0ee8ea83d12eba4da1019dcb9d2e7142 100644 (file)
@@ -1,7 +1,6 @@
 #include <msp/fs/dir.h>
 #include <msp/fs/stat.h>
 #include <msp/fs/utils.h>
-#include <msp/strings/format.h>
 #include <stdexcept>
 #include "builder.h"
 #include "component.h"
@@ -17,7 +16,9 @@ using namespace Msp;
 GnuArchiver::GnuArchiver(Builder &b, const Architecture &a):
        Tool(b, a, "AR")
 {
+       set_command("ar", true);
        input_suffixes.push_back(".o");
+       processing_unit = COMPONENT;
 }
 
 Target *GnuArchiver::create_target(const list<Target *> &sources, const string &)
@@ -26,13 +27,8 @@ Target *GnuArchiver::create_target(const list<Target *> &sources, const string &
                throw invalid_argument("GnuArchiver::create_target");
 
        list<ObjectFile *> objs;
-       for(list<Target *>::const_iterator i=sources.begin(); i!=sources.end(); ++i)
-       {
-               if(ObjectFile *obj = dynamic_cast<ObjectFile *>(*i))
-                       objs.push_back(obj);
-               else
-                       throw invalid_argument("GnuArchiver::create_target");
-       }
+       for(Target *s: sources)
+               objs.push_back(&dynamic_cast<ObjectFile &>(*s));
 
        const Component &comp = *objs.front()->get_component();
        StaticLibrary *lib = new StaticLibrary(builder, comp, objs);
@@ -40,14 +36,6 @@ Target *GnuArchiver::create_target(const list<Target *> &sources, const string &
        return lib;
 }
 
-void GnuArchiver::do_prepare()
-{
-       string command = "ar";
-       if(architecture->is_cross())
-               command = format("%s-%s", architecture->get_cross_prefix(), command);
-       executable = builder.get_vfs().find_binary(command);
-}
-
 Task *GnuArchiver::run(const Target &target) const
 {
        const StaticLibrary &lib = dynamic_cast<const StaticLibrary &>(target);
@@ -61,9 +49,8 @@ Task *GnuArchiver::run(const Target &target) const
 
        argv.push_back(relative(lib.get_path(), work_dir).str());
 
-       const Target::Dependencies &deps = lib.get_dependencies();
-       for(Target::Dependencies::const_iterator i=deps.begin(); i!=deps.end(); ++i)
-               if(ObjectFile *obj = dynamic_cast<ObjectFile *>(*i))
+       for(Target *d: lib.get_dependencies())
+               if(ObjectFile *obj = dynamic_cast<ObjectFile *>(d))
                        argv.push_back(relative(obj->get_path(), work_dir).str());
 
        return new ExternalTask(argv, work_dir);