]> git.tdb.fi Git - builder.git/blobdiff - source/filetarget.cpp
Add support for statically linking the C++ standard library
[builder.git] / source / filetarget.cpp
index 9908c0d4d2836c36c5e05e1eda9aa221bab067b2..51a92d13b1a11f61c34671a1d8c39adfa710bdcc 100644 (file)
@@ -1,10 +1,13 @@
 #include <msp/fs/stat.h>
 #include <msp/fs/utils.h>
 #include <msp/strings/format.h>
+#include <msp/strings/utils.h>
 #include <msp/time/utils.h>
 #include "builder.h"
 #include "filetarget.h"
 #include "sourcepackage.h"
+#include "task.h"
+#include "tool.h"
 
 using namespace std;
 using namespace Msp;
@@ -27,9 +30,16 @@ void FileTarget::init(const SourcePackage *p)
 {
        size = 0;
        package = p;
+       nested_build_sig = false;
+       arch_in_build_sig = false;
 
        builder.get_vfs().register_path(path, this);
 
+       stat();
+}
+
+void FileTarget::stat()
+{
        if(FS::Stat st = FS::lstat(path))
        {
                mtime = st.get_modify_time();
@@ -39,15 +49,14 @@ void FileTarget::init(const SourcePackage *p)
 
 string FileTarget::generate_name(Builder &builder, const SourcePackage *pkg, const FS::Path &path)
 {
-       if(pkg && FS::descendant_depth(path, pkg->get_source())>=0)
+       if(pkg && FS::descendant_depth(path, pkg->get_source_directory())>=0)
        {
-               FS::Path relpath = FS::relative(path, pkg->get_source());
+               FS::Path relpath = FS::relative(path, pkg->get_source_directory());
                return format("<%s>%s", pkg->get_name(), relpath.str().substr(1));
        }
        else if(FS::descendant_depth(path, builder.get_prefix())>=0)
        {
                FS::Path relpath = FS::relative(path, builder.get_prefix());
-               builder.get_logger().log("debug", format("%s %s %s", path, builder.get_prefix(), relpath));
                return "<prefix>"+relpath.str().substr(1);
        }
 
@@ -57,12 +66,13 @@ string FileTarget::generate_name(Builder &builder, const SourcePackage *pkg, con
 void FileTarget::touch()
 {
        mtime = Time::now();
+       modified();
        signal_bubble_rebuild.emit();
 }
 
 void FileTarget::check_rebuild()
 {
-       if(!tool)
+       if(!tool || needs_rebuild())
                return;
 
        if(!mtime)
@@ -79,14 +89,89 @@ void FileTarget::check_rebuild()
                }
        }
 
-       if(!needs_rebuild() && package && package->get_config().get_mtime()>mtime)
-               mark_rebuild("Package options changed");
+       if(!needs_rebuild())
+       {
+               // Some side effects might not exist
+               for(Dependencies::iterator i=side_effects.begin(); (i!=side_effects.end() && !needs_rebuild()); ++i)
+                       if((*i)->needs_rebuild())
+                               mark_rebuild((*i)->get_name()+" needs rebuilding");
+       }
+
+       if(!needs_rebuild() && package)
+       {
+               if(package->get_config().get_mtime()>mtime)
+                       mark_rebuild("Package options changed");
+
+               if(tool->get_executable())
+               {
+                       string build_sig = create_build_signature();
+                       if(package->get_cache().has_key(this, "build_sig"))
+                       {
+                               if(package->get_cache().get_value(this, "build_sig")!=build_sig)
+                                       mark_rebuild("Build signature changed");
+                       }
+               }
+       }
 }
 
-Task *FileTarget::build()
+string FileTarget::create_build_signature() const
 {
-       if(tool && !builder.get_dry_run() && mtime)
-               FS::unlink(path);
+       if(!package)
+               return string();
+
+       const BuildInfo &binfo = (component ? component->get_build_info() : package->get_build_info());
+       list<string> sigs;
+       if(nested_build_sig && component)
+       {
+               set<const Tool *> depend_tools;
+               for(Dependencies::const_iterator i=depends.begin(); i!=depends.end(); ++i)
+                       if((*i)->get_component()==component && (*i)->get_tool())
+                               depend_tools.insert((*i)->get_tool());
+
+               for(set<const Tool *>::const_iterator i=depend_tools.begin(); i!=depend_tools.end(); ++i)
+                       sigs.push_back((*i)->create_build_signature(binfo));
+               sigs.sort();
+               sigs.push_front(tool->create_build_signature(binfo));
+       }
+       else
+               sigs.push_back(tool->create_build_signature(binfo));
 
-       return Target::build();
+       if(arch_in_build_sig)
+               if(const Architecture *arch = tool->get_architecture())
+                       sigs.push_front(arch->get_name());
+
+       return join(sigs.begin(), sigs.end(), ";");
+}
+
+void FileTarget::build(Task &task)
+{
+       task.add_file(path);
+       task.set_unlink(true);
+}
+
+void FileTarget::build_finished(bool success)
+{
+       if(success)
+       {
+               stat();
+               if(package)
+               {
+                       string build_sig = create_build_signature();
+                       if(!build_sig.empty())
+                               package->get_cache().set_value(this, "build_sig", build_sig);
+               }
+       }
+
+       Target::build_finished(success);
+}
+
+void FileTarget::clean()
+{
+       if(mtime)
+       {
+               FS::unlink(path);
+               mtime = Time::TimeStamp();
+               size = 0;
+               check_rebuild();
+       }
 }