]> 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 71edc42d57d26d09560c9ddc1b389e0febcedae9..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,27 +16,19 @@ using namespace Msp;
 GnuArchiver::GnuArchiver(Builder &b, const Architecture &a):
        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;
 }
 
-Target *GnuArchiver::create_target(const list<Target *> &sources, const string &) const
+Target *GnuArchiver::create_target(const list<Target *> &sources, const string &)
 {
        if(sources.empty())
                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);
@@ -54,21 +45,13 @@ Task *GnuArchiver::run(const Target &target) const
        argv.push_back(executable->get_path().str());
        argv.push_back("rc");
 
-       FS::Path work_dir = comp.get_package().get_source();
+       FS::Path work_dir = comp.get_package().get_source_directory();
 
        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<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());
 
-       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);
 }