]> git.tdb.fi Git - builder.git/blobdiff - source/gnuarchiver.cpp
Delay locating tool executables until the tool is needed
[builder.git] / source / gnuarchiver.cpp
index 168a163449e9814e234bf4f1ee1187cc7a0be61a..7482b0d17caf004d66125f4a82c8c098d0bb2331 100644 (file)
@@ -17,15 +17,10 @@ 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);
-
        input_suffixes.push_back(".o");
 }
 
-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");
@@ -45,6 +40,14 @@ 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);
@@ -63,12 +66,5 @@ Task *GnuArchiver::run(const Target &target) const
                if(ObjectFile *obj = dynamic_cast<ObjectFile *>(*i))
                        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);
 }