From: Mikko Rasa Date: Thu, 29 May 2008 00:27:08 +0000 (+0000) Subject: Include libmode in library lookup hash X-Git-Tag: 0.9~9 X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=be8a901dfc026f61db46d5d64a41cecc619bc97d;p=builder.git Include libmode in library lookup hash Redesign Target::build Always remove target before rebuilding to avoid trouble with ar --- diff --git a/source/builder.cpp b/source/builder.cpp index aabfc00..d3aabf9 100644 --- a/source/builder.cpp +++ b/source/builder.cpp @@ -285,8 +285,7 @@ Target *Builder::get_library(const string &lib, const list &path, LibMod for(list::const_iterator i=path.begin(); i!=path.end(); ++i) update_hash(hash, *i); - //XXX Incorporate mode into id - string id=hash+lib; + string id=hash+string(1, mode)+lib; TargetMap::iterator i=libraries.find(id); if(i!=libraries.end()) return i->second; diff --git a/source/executable.cpp b/source/executable.cpp index 488dd29..5d1e1c8 100644 --- a/source/executable.cpp +++ b/source/executable.cpp @@ -80,9 +80,9 @@ void Executable::find_depends() deps_ready=true; } -Action *Executable::build() +Action *Executable::create_action() { - return Target::build(new Link(builder, *this));; + return new Link(builder, *this); } /** diff --git a/source/executable.h b/source/executable.h index 7d6ea28..e415668 100644 --- a/source/executable.h +++ b/source/executable.h @@ -24,10 +24,11 @@ public: const char *get_type() const { return "Executable"; } const Component &get_component() const { return comp; } void find_depends(); - Action *build(); private: const Component ∁ + virtual Action *create_action(); + static std::string generate_target_name(const Component &); }; diff --git a/source/file.h b/source/file.h index 35c1087..cd3eccf 100644 --- a/source/file.h +++ b/source/file.h @@ -15,7 +15,8 @@ class File: public Target public: File(Builder &, const std::string &); virtual const char *get_type() const { return "File"; } - virtual Action *build() { return 0; } +private: + virtual Action *create_action() { return 0; } }; #endif diff --git a/source/install.cpp b/source/install.cpp index 6dcaef0..721f963 100644 --- a/source/install.cpp +++ b/source/install.cpp @@ -39,9 +39,9 @@ void Install::check_rebuild() } } -Action *Install::build() +Action *Install::create_action() { - return Target::build(new Copy(builder, *package, depends.front()->get_name(), name)); + return new Copy(builder, *package, depends.front()->get_name(), name); } string Install::generate_target_name(const Target &tgt) diff --git a/source/install.h b/source/install.h index 6721615..84c2b23 100644 --- a/source/install.h +++ b/source/install.h @@ -20,9 +20,10 @@ public: Install(Builder &, const SourcePackage &, Target &); const char *get_type() const { return "Install"; } void check_rebuild(); - Action *build(); private: - std::string generate_target_name(const Target &); + virtual Action *create_action(); + + static std::string generate_target_name(const Target &); }; #endif diff --git a/source/link.cpp b/source/link.cpp index 910387e..f775158 100644 --- a/source/link.cpp +++ b/source/link.cpp @@ -56,7 +56,7 @@ Link::Link(Builder &b, const Executable &exe): else if(SharedLibrary *shlib=dynamic_cast(tgt)) argv.push_back("-l"+shlib->get_libname()); else if(dynamic_cast(tgt)) - argv.push_back(relative((*i)->get_name(), work_dir).str()); + argv.push_back((*i)->get_name()); else if(SystemLibrary *syslib=dynamic_cast(tgt)) argv.push_back("-l"+syslib->get_libname()); } diff --git a/source/objectfile.cpp b/source/objectfile.cpp index 3fd88d2..6790082 100644 --- a/source/objectfile.cpp +++ b/source/objectfile.cpp @@ -48,10 +48,6 @@ void ObjectFile::find_depends() deps_ready=new_deps.empty(); } -Action *ObjectFile::build() -{ - return Target::build(new Compile(builder, *this)); -} /** Recursively looks for header targets and adds them as dependencies. @@ -91,6 +87,11 @@ void ObjectFile::add_depend(Target *tgt) new_deps.push_back(tgt); } +Action *ObjectFile::create_action() +{ + return new Compile(builder, *this); +} + string ObjectFile::generate_target_name(const Component &comp, const string &src) { const SourcePackage &pkg=comp.get_package(); diff --git a/source/objectfile.h b/source/objectfile.h index 21a988d..dbb49fe 100644 --- a/source/objectfile.h +++ b/source/objectfile.h @@ -23,13 +23,13 @@ public: const char *get_type() const { return "ObjectFile"; } const Component &get_component() const { return comp; } void find_depends(); - Action *build(); private: const Component ∁ TargetList new_deps; void find_depends(Target *); void add_depend(Target *); + virtual Action *create_action(); static std::string generate_target_name(const Component &, const std::string &); }; diff --git a/source/pkgconfig.cpp b/source/pkgconfig.cpp index d31ab9d..e8fca57 100644 --- a/source/pkgconfig.cpp +++ b/source/pkgconfig.cpp @@ -16,7 +16,7 @@ PkgConfig::PkgConfig(Builder &b, const SourcePackage &p): buildable=true; } -Action *PkgConfig::build() +Action *PkgConfig::create_action() { - return Target::build(new PkgConfigAction(builder, *this)); + return new PkgConfigAction(builder, *this); } diff --git a/source/pkgconfig.h b/source/pkgconfig.h index f88e248..20e5fbf 100644 --- a/source/pkgconfig.h +++ b/source/pkgconfig.h @@ -19,9 +19,10 @@ class PkgConfig: public Target public: PkgConfig(Builder &, const SourcePackage &); const char *get_type() const { return "PkgConfig"; } - Action *build(); private: const Package &pkg; + + virtual Action *create_action(); }; #endif diff --git a/source/sourcefile.h b/source/sourcefile.h index a6688d0..ea6ed05 100644 --- a/source/sourcefile.h +++ b/source/sourcefile.h @@ -23,10 +23,11 @@ public: const char *get_type() const { return "SourceFile"; } const Component *get_component() const { return comp; } void find_depends(); - Action *build() { return 0; } private: const Component *comp; StringList includes; + + virtual Action *create_action() { return 0; } }; #endif diff --git a/source/staticlibrary.cpp b/source/staticlibrary.cpp index 56d857e..9a35677 100644 --- a/source/staticlibrary.cpp +++ b/source/staticlibrary.cpp @@ -22,9 +22,9 @@ StaticLibrary::StaticLibrary(Builder &b, const Component &c, const std::list &); const char *get_type() const { return "StaticLibrary"; } const Component &get_component() const { return comp; } - Action *build(); private: const Component ∁ + virtual Action *create_action(); + std::string generate_target_name(const Component &); }; diff --git a/source/systemlibrary.h b/source/systemlibrary.h index a0b315a..2b56f4c 100644 --- a/source/systemlibrary.h +++ b/source/systemlibrary.h @@ -19,9 +19,10 @@ public: SystemLibrary(Builder &, const std::string &); const char *get_type() const { return "SystemLibrary"; } const std::string &get_libname() const { return libname; } - Action *build() { return 0; } private: std::string libname; + + virtual Action *create_action() { return 0; } }; #endif diff --git a/source/tarball.cpp b/source/tarball.cpp index 5d7678d..5782cec 100644 --- a/source/tarball.cpp +++ b/source/tarball.cpp @@ -45,9 +45,9 @@ void TarBall::find_depends() deps_ready=true; } -Action *TarBall::build() +Action *TarBall::create_action() { - return Target::build(new Tar(builder, *this)); + return new Tar(builder, *this); } string TarBall::create_target_name(const SourcePackage &pkg, const string &extra_ver) diff --git a/source/tarball.h b/source/tarball.h index 04cd661..cadd032 100644 --- a/source/tarball.h +++ b/source/tarball.h @@ -17,11 +17,12 @@ public: virtual const char *get_type() const { return "TarBall"; } const SourcePackage *get_package() const; virtual void find_depends(); - virtual Action *build(); private: std::string tarname; - std::string create_target_name(const SourcePackage &, const std::string &); + virtual Action *create_action(); + + static std::string create_target_name(const SourcePackage &, const std::string &); }; #endif diff --git a/source/target.cpp b/source/target.cpp index b094e94..f17b88e 100644 --- a/source/target.cpp +++ b/source/target.cpp @@ -68,6 +68,28 @@ void Target::prepare() } +Action *Target::build() +{ + if(!buildable) + { + rebuild=false; + return 0; + } + + if(!builder.get_dry_run() && exists(name)) + unlink(name); + + Action *action=create_action(); + if(action) + { + action->signal_done.connect(sigc::mem_fun(this, &Target::build_done)); + + building=true; + } + + return action; +} + /** Returns the number of targets that need to be rebuilt in order to get this target up-to-date. @@ -144,17 +166,6 @@ void Target::check_rebuild() mark_rebuild("Package options changed"); } -/** -Hooks the target up with the given action, then returns it. This should be -called from the public build() function of buildable targets. -*/ -Action *Target::build(Action *action) -{ - building=true; - action->signal_done.connect(sigc::mem_fun(this, &Target::build_done)); - return action; -} - /** Handles for the build_done signal of Action. */ diff --git a/source/target.h b/source/target.h index cf1d186..04a360d 100644 --- a/source/target.h +++ b/source/target.h @@ -49,7 +49,7 @@ public: /** Creates and returns an Action suitable for building this target. */ - virtual Action *build()=0; + Action *build(); void reset_count() { counted=false; } virtual unsigned count_rebuild(); @@ -76,7 +76,7 @@ protected: Target(Builder &, const Package *, const std::string &); void mark_rebuild(const std::string &); virtual void check_rebuild(); - Action *build(Action *); + virtual Action *create_action() =0; virtual void build_done(); }; diff --git a/source/virtualtarget.h b/source/virtualtarget.h index aec3080..67c3014 100644 --- a/source/virtualtarget.h +++ b/source/virtualtarget.h @@ -18,10 +18,10 @@ class VirtualTarget: public Target public: VirtualTarget(Builder &b, const std::string &n): Target(b, 0, n) { } const char *get_type() const { return "VirtualTarget"; } - Action *build() { rebuild=false; return 0; } unsigned count_rebuild(); private: void check_rebuild(); + virtual Action *create_action() { return 0; } }; #endif