#include <msp/fs/utils.h>
#include <msp/strings/format.h>
+#include <msp/strings/utils.h>
#include "binary.h"
#include "builder.h"
#include "component.h"
#include "sharedlibrary.h"
#include "sourcepackage.h"
#include "staticlibrary.h"
+#include "tool.h"
using namespace std;
using namespace Msp;
{ }
Binary::Binary(Builder &b, const Component &c, const string &p, const list<ObjectFile *> &objs):
- FileTarget(b, c.get_package(), c.get_package().get_out_dir()/p)
+ FileTarget(b, c.get_package(), c.get_package().get_out_dir()/p),
+ objects(objs)
{
component = &c;
- for(list<ObjectFile *>::const_iterator i=objs.begin(); i!=objs.end(); ++i)
+ for(list<ObjectFile *>::const_iterator i=objects.begin(); i!=objects.end(); ++i)
add_dependency(**i);
}
add_dependency(**i);
}
}
+
+string Binary::create_build_signature() const
+{
+ set<const Tool *> object_tools;
+ for(list<ObjectFile *>::const_iterator i=objects.begin(); i!=objects.end(); ++i)
+ object_tools.insert((*i)->get_tool());
+
+ list<string> sigs;
+ sigs.push_back(tool->create_build_signature(component->get_build_info()));
+ for(set<const Tool *>::const_iterator i=object_tools.begin(); i!=object_tools.end(); ++i)
+ sigs.push_back((*i)->create_build_signature(component->get_build_info()));
+ sigs.sort();
+
+ return join(sigs.begin(), sigs.end(), ";");
+}
class Binary: public FileTarget
{
protected:
+ std::list<ObjectFile *> objects;
+
Binary(Builder &, const Msp::FS::Path &);
Binary(Builder &, const Component &, const std::string &, const std::list<ObjectFile *> &);
-public:
virtual void find_dependencies();
+
+ virtual std::string create_build_signature() const;
};
#endif
#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 "tool.h"
using namespace std;
using namespace Msp;
}
}
- if(!needs_rebuild() && package && package->get_config().get_mtime()>mtime)
- mark_rebuild("Package options changed");
+ if(!needs_rebuild() && package)
+ {
+ if(package->get_config().get_mtime()>mtime)
+ mark_rebuild("Package options changed");
+
+ 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");
+ }
+ }
+}
+
+string FileTarget::create_build_signature() const
+{
+ if(!package)
+ return string();
+
+ const BuildInfo &binfo = (component ? component->get_build_info() : package->get_build_info());
+ return tool->create_build_signature(binfo);
}
Task *FileTarget::build()
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);
}
protected:
virtual void check_rebuild();
+ virtual std::string create_build_signature() const;
+
public:
virtual Task *build();
return obj;
}
+string GnuCompiler::create_build_signature(const BuildInfo &binfo) const
+{
+ string result = FS::basename(executable->get_path());
+ result += ',';
+ if(binfo.debug)
+ result += 'g';
+ if(binfo.optimize)
+ {
+ result += 'O';
+ result += (binfo.optimize>0 ? '0'+binfo.optimize : 's');
+ }
+ return result;
+}
+
Task *GnuCompiler::run(const Target &target) const
{
const ObjectFile &object = dynamic_cast<const ObjectFile &>(target);
public:
virtual Target *create_target(const std::list<Target *> &, const std::string &) const;
+ virtual std::string create_build_signature(const BuildInfo &) const;
virtual Task *run(const Target &) const;
};
#include <msp/fs/dir.h>
#include <msp/fs/utils.h>
#include <msp/strings/format.h>
+#include <msp/strings/utils.h>
#include "builder.h"
#include "component.h"
#include "executable.h"
return parent.create_target(sources, arg);
}
+string GnuLinker::Linker::create_build_signature(const BuildInfo &binfo) const
+{
+ string result = FS::basename(executable->get_path());
+ result += ',';
+ if(binfo.libmode<=BuildInfo::STATIC)
+ result += 't';
+ else
+ result += 'd';
+ if(binfo.strip)
+ result += 's';
+ result += ",l";
+ result += join(binfo.libs.begin(), binfo.libs.end(), ",l");
+ return result;
+}
+
Task *GnuLinker::Linker::run(const Target &target) const
{
const Binary &bin = dynamic_cast<const Binary &>(target);
Linker(GnuLinker &, const std::string &);
virtual Target *create_target(const std::list<Target *> &, const std::string &) const;
+ virtual std::string create_build_signature(const BuildInfo &) const;
virtual Task *run(const Target &) const;
};
class Architecture;
class Builder;
+class BuildInfo;
class Component;
class FileTarget;
class Target;
alternative target type for tools that can create multiple kinds of targets. */
virtual Target *create_target(const std::list<Target *> &, const std::string & = std::string()) const = 0;
+ virtual std::string create_build_signature(const BuildInfo &) const { return std::string(); }
+
/** Invokes the tool to build a target. This should not be called directly;
use Target::build() instead. */
virtual Task *run(const Target &) const = 0;