From: Mikko Rasa Date: Thu, 19 Feb 2009 16:43:37 +0000 (+0000) Subject: Reorder class members X-Git-Tag: 1.0~20 X-Git-Url: http://git.tdb.fi/?p=builder.git;a=commitdiff_plain;h=242c55b17e6608b29a77ca17a5b677e202a3ca90 Reorder class members Put all function documentation comments to headers Update copyright notices --- diff --git a/source/action.cpp b/source/action.cpp index ebd6b42..31b1390 100644 --- a/source/action.cpp +++ b/source/action.cpp @@ -1,7 +1,7 @@ /* $Id$ This file is part of builder -Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions +Copyright © 2006-2007, 2009 Mikko Rasa, Mikkosoft Productions Distributed under the LGPL */ @@ -12,9 +12,6 @@ Distributed under the LGPL using namespace std; -/** -Annouces the action by printing out the package name, tool and target name. -*/ void Action::announce(const string &pkg, const string &tool, const string &tgt) { ostringstream line; diff --git a/source/action.h b/source/action.h index a80c7db..4ae787a 100644 --- a/source/action.h +++ b/source/action.h @@ -1,7 +1,7 @@ /* $Id$ This file is part of builder -Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions +Copyright © 2006-2007, 2009 Mikko Rasa, Mikkosoft Productions Distributed under the LGPL */ @@ -22,19 +22,24 @@ public: /// Emitted when the action has finished sigc::signal signal_done; - /** - Checks whether the action is done and emits signal_done if it is. +protected: + Builder &builder; + + Action(Builder &b): builder(b) { } +public: + virtual ~Action() { } - @return 0 on successful completion, 1 on error, -1 if the action is still - executing + /** + Checks whether the action is done and emits signal_done if it is. Returns 0 + if the action has completed successfully, 1 if an error was encountered and + -1 if it is still executing. */ virtual int check()=0; - virtual ~Action() { } protected: - Builder &builder; - - Action(Builder &b): builder(b) { } + /** + Annouces the action by printing out the package name, tool and target name. + */ void announce(const std::string &, const std::string &, const std::string &); }; diff --git a/source/analyzer.cpp b/source/analyzer.cpp index a86a9a2..3481ec8 100644 --- a/source/analyzer.cpp +++ b/source/analyzer.cpp @@ -1,7 +1,7 @@ /* $Id$ This file is part of builder -Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions +Copyright © 2006-2009 Mikko Rasa, Mikkosoft Productions Distributed under the LGPL */ @@ -26,9 +26,6 @@ Analyzer::Analyzer(Builder &b): full_paths(false) { } -/** -Performs the analysis and prints out the resulting dependency tree. -*/ void Analyzer::analyze() { TableRow row; @@ -43,12 +40,6 @@ void Analyzer::analyze() print_table(); } -/** -Adds rows to the table for the given target and it' dependencies. - -@param tgt Target to be processed -@param depth Recursion level of the target (top level is 0) -*/ void Analyzer::build_depend_table(Target &tgt, unsigned depth) { if(mode!=REBUILD && mode!=ALLDEPS) @@ -61,7 +52,7 @@ void Analyzer::build_depend_table(Target &tgt, unsigned depth) } else if(mode==REBUILD && !tgt.get_rebuild()) /* All targets that depend on to-be-built targets will be rebuilt - themselves, so we cn stop here. */ + themselves, so we cn stop here. */ return; TableRow row; @@ -101,9 +92,6 @@ void Analyzer::build_depend_table(Target &tgt, unsigned depth) } } -/** -Prints out the table that resulted from the analysis. -*/ void Analyzer::print_table() const { vector col_width; diff --git a/source/analyzer.h b/source/analyzer.h index b4ffd8b..7dd4c13 100644 --- a/source/analyzer.h +++ b/source/analyzer.h @@ -1,7 +1,7 @@ /* $Id$ This file is part of builder -Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions +Copyright © 2006-2007, 2009 Mikko Rasa, Mikkosoft Productions Distributed under the LGPL */ @@ -23,28 +23,42 @@ class Analyzer public: enum Mode { - DEPS, /// Skip over "trivial" targets such as Install and Compile - ALLDEPS, /// Print out absolutely every target - REBUILD, /// Print targets that are going to be rebuilt - RDEPS /// Print targets that depend on the given targets (NYI) + DEPS, //< Skip over "trivial" targets such as Install and Compile + ALLDEPS, //< Print out absolutely every target + REBUILD, //< Print targets that are going to be rebuilt + RDEPS //< Print targets that depend on the given targets (NYI) }; - Analyzer(Builder &); - void set_mode(Mode m) { mode=m; } - void set_max_depth(unsigned m) { max_depth=m; } - void set_full_paths(bool f) { full_paths=f; } - void analyze(); private: typedef std::vector TableRow; typedef std::list Table; - Builder &builder; - Mode mode; - Table table; + Builder &builder; + Mode mode; + Table table; unsigned max_depth; - bool full_paths; + bool full_paths; +public: + Analyzer(Builder &); + void set_mode(Mode m) { mode=m; } + void set_max_depth(unsigned m) { max_depth=m; } + void set_full_paths(bool f) { full_paths=f; } + + /** + Performs the analysis and prints out the resulting dependency tree. + */ + void analyze(); + +private: + /** + Adds rows to the table for the given target and its dependencies. + */ void build_depend_table(Target &, unsigned); + + /** + Prints out the table that resulted from the analysis. + */ void print_table() const; static bool target_order(Target *, Target *); diff --git a/source/architecture.cpp b/source/architecture.cpp index 1f578af..c2e9162 100644 --- a/source/architecture.cpp +++ b/source/architecture.cpp @@ -1,7 +1,7 @@ /* $Id$ This file is part of builder -Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions +Copyright © 2007-2009 Mikko Rasa, Mikkosoft Productions Distributed under the LGPL */ diff --git a/source/architecture.h b/source/architecture.h index af58619..3a4d7ec 100644 --- a/source/architecture.h +++ b/source/architecture.h @@ -1,7 +1,7 @@ /* $Id$ This file is part of builder -Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions +Copyright © 2007-2009 Mikko Rasa, Mikkosoft Productions Distributed under the LGPL */ @@ -19,27 +19,30 @@ class Architecture public: class Loader: public Msp::DataFile::Loader { + private: + Architecture &arch; + public: Loader(Architecture &); Architecture &get_object() { return arch; } private: - Architecture &arch; - void tool(const std::string &t, const std::string &p); }; +private: + Builder &builder; + std::string name; + bool native; + std::string prefix; + StringMap tools; + +public: Architecture(Builder &b, const std::string &n, bool a=false); void set_tool(const std::string &t, const std::string &p); std::string get_tool(const std::string &t) const; const std::string &get_name() const { return name; } bool is_native() const { return native; } const std::string &get_prefix() const { return prefix; } -private: - Builder &builder; - std::string name; - bool native; - std::string prefix; - StringMap tools; }; typedef std::map ArchMap; diff --git a/source/archive.cpp b/source/archive.cpp index 175a0ae..204b202 100644 --- a/source/archive.cpp +++ b/source/archive.cpp @@ -1,7 +1,7 @@ /* $Id$ This file is part of builder -Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions +Copyright © 2006-2009 Mikko Rasa, Mikkosoft Productions Distributed under the LGPL */ diff --git a/source/binarypackage.cpp b/source/binarypackage.cpp index f63bff8..e1dc9df 100644 --- a/source/binarypackage.cpp +++ b/source/binarypackage.cpp @@ -1,7 +1,7 @@ /* $Id$ This file is part of builder -Copyright © 2007 Mikko Rasa, Mikkosoft Productions +Copyright © 2007-2009 Mikko Rasa, Mikkosoft Productions Distributed under the LGPL */ @@ -20,10 +20,6 @@ BinaryPackage::BinaryPackage(Builder &b, const string &n): use_pkgconfig=false; } -/** -Sets the path where the package files were installed. This is only useful if -the package doesn't use pkg-config. -*/ void BinaryPackage::set_path(const Msp::FS::Path &p) { path=builder.get_cwd()/p; diff --git a/source/binarypackage.h b/source/binarypackage.h index a0f20e8..a0b3d0a 100644 --- a/source/binarypackage.h +++ b/source/binarypackage.h @@ -1,7 +1,7 @@ /* $Id$ This file is part of builder -Copyright © 2007 Mikko Rasa, Mikkosoft Productions +Copyright © 2007-2009 Mikko Rasa, Mikkosoft Productions Distributed under the LGPL */ @@ -26,15 +26,23 @@ public: void build_info(); }; +private: + bool need_path; + Msp::FS::Path path; + +public: BinaryPackage(Builder &, const std::string &); + + /** + Sets the path where the package's files were installed. This is only useful + if the package doesn't use pkg-config. + */ void set_path(const Msp::FS::Path &); + bool get_need_path() const { return need_path; } static BinaryPackage *from_pkgconfig(Builder &, const std::string &); private: - bool need_path; - Msp::FS::Path path; - virtual void create_build_info(); }; diff --git a/source/builder.cpp b/source/builder.cpp index dda6c61..3838ae5 100644 --- a/source/builder.cpp +++ b/source/builder.cpp @@ -1,7 +1,7 @@ /* $Id$ This file is part of builder -Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions +Copyright © 2006-2009 Mikko Rasa, Mikkosoft Productions Distributed under the LGPL */ @@ -41,6 +41,17 @@ Distributed under the LGPL using namespace std; using namespace Msp; +namespace { + +void update_hash(string &hash, const string &value) +{ + for(unsigned i=0; isecond; + for(TargetMap::iterator i=targets.begin(); i!=targets.end(); ++i) + delete i->second; + delete analyzer; +} -@param name Package name +int Builder::main() +{ + if(load_build_file(cwd/build_file)) + { + cerr<<"No build info here.\n"; + return 1; + } + + main_pkg->configure(cmdline_options, conf_all?2:1); + + if(help) + { + usage(0, "builder", false); + cout<<'\n'; + package_help(); + return 0; + } + + if(!conf_only && create_targets()) + return 1; + + PackageList all_reqs=main_pkg->collect_requires(); + + if(conf_only) + return 0; + + if(verbose>=2) + cout<<"Building on "<get_name()<<", for "<get_name()<<'\n'; + if(verbose>=1) + cout<=2) + { + for(PackageList::const_iterator i=all_reqs.begin(); i!=all_reqs.end(); ++i) + { + cout<<' '<<(*i)->get_name(); + if(dynamic_cast(*i)) + cout<<'*'; + unsigned count=0; + unsigned ood_count=0; + for(TargetMap::iterator j=targets.begin(); j!=targets.end(); ++j) + if(j->second->get_package()==*i) + { + ++count; + if(j->second->get_rebuild()) + ++ood_count; + } + if(count) + { + cout<<" ("<analyze(); + + if(!problems.empty()) + { + cerr<<"The following problems were detected:\n"; + for(ProblemList::iterator i=problems.begin(); i!=problems.end(); ++i) + cerr<<" "<package<<": "<descr<<'\n'; + cerr<<"Please fix them and try again.\n"; + return 1; + } + + //if(create_makefile + + if(clean) + exit_code=do_clean(); + else if(build) + exit_code=do_build(); + + return exit_code; +} -@return Pointer to the package, or 0 if the package could not be located -*/ Package *Builder::get_package(const string &name) { PackageMap::iterator i=packages.find(format("%s/%s", name, current_arch->get_name())); @@ -206,9 +298,6 @@ Package *Builder::get_package(const string &name) return pkg; } -/** -Returns the target with the given name, or 0 if no such target exists. -*/ Target *Builder::get_target(const string &n) const { TargetMap::const_iterator i=targets.find(n); @@ -217,12 +306,6 @@ Target *Builder::get_target(const string &n) const return 0; } -/** -Tries to locate a header included from a given location and with a given include -path. Considers known targets as well as existing files. If a matching target -is not found but a file exists, a new SystemHeader target will be created and -returned. -*/ Target *Builder::get_header(const string &include, const string &from, const list &path) { string hash(8, 0); @@ -278,17 +361,6 @@ Target *Builder::get_header(const string &include, const string &from, const lis return tgt; } -/** -Tries to locate a library with the given library path. Considers known targets -as well as existing files. If a matching target is not found but a file exists, -a new SystemLibrary target will be created and returned. - -@param lib Name of the library to get (without "lib" prefix or extension) -@param path List of paths to search for the library -@param mode Shared / static mode - -@return Some kind of library target, if a match was found -*/ Target *Builder::get_library(const string &lib, const list &path, LibMode mode) { string hash(8, 0); @@ -351,104 +423,12 @@ void Builder::problem(const string &p, const string &d) problems.push_back(Problem(p, d)); } -/** -Adds a target to both the target map and the new target queue. Called from -Target constructor. -*/ void Builder::add_target(Target *t) { targets.insert(TargetMap::value_type(t->get_name(), t)); new_tgts.push_back(t); } -int Builder::main() -{ - if(load_build_file(cwd/build_file)) - { - cerr<<"No build info here.\n"; - return 1; - } - - main_pkg->configure(cmdline_options, conf_all?2:1); - - if(help) - { - usage(0, "builder", false); - cout<<'\n'; - package_help(); - return 0; - } - - if(!conf_only && create_targets()) - return 1; - - PackageList all_reqs=main_pkg->collect_requires(); - - if(conf_only) - return 0; - - if(verbose>=2) - cout<<"Building on "<get_name()<<", for "<get_name()<<'\n'; - if(verbose>=1) - cout<=2) - { - for(PackageList::const_iterator i=all_reqs.begin(); i!=all_reqs.end(); ++i) - { - cout<<' '<<(*i)->get_name(); - if(dynamic_cast(*i)) - cout<<'*'; - unsigned count=0; - unsigned ood_count=0; - for(TargetMap::iterator j=targets.begin(); j!=targets.end(); ++j) - if(j->second->get_package()==*i) - { - ++count; - if(j->second->get_rebuild()) - ++ood_count; - } - if(count) - { - cout<<" ("<analyze(); - - if(!problems.empty()) - { - cerr<<"The following problems were detected:\n"; - for(ProblemList::iterator i=problems.begin(); i!=problems.end(); ++i) - cerr<<" "<package<<": "<descr<<'\n'; - cerr<<"Please fix them and try again.\n"; - return 1; - } - - //if(create_makefile - - if(clean) - exit_code=do_clean(); - else if(build) - exit_code=do_build(); - - return exit_code; -} - -Builder::~Builder() -{ - for(PackageMap::iterator i=packages.begin(); i!=packages.end(); ++i) - delete i->second; - for(TargetMap::iterator i=targets.begin(); i!=targets.end(); ++i) - delete i->second; - delete analyzer; -} - void Builder::usage(const char *reason, const char *argv0, bool brief) { if(reason) @@ -485,10 +465,6 @@ void Builder::usage(const char *reason, const char *argv0, bool brief) } } -/** -Determines the source directory of a package. pkg-config is consulted first, -and if it fails, the package path is searched for matches. -*/ FS::Path Builder::get_package_location(const string &name) { if(verbose>=3) @@ -536,13 +512,6 @@ FS::Path Builder::get_package_location(const string &name) return FS::Path(); } -/** -Loads the given build file. - -@param fn Path to the file - -@return 0 on success, -1 if the file could not be opened -*/ int Builder::load_build_file(const FS::Path &fn) { try @@ -564,12 +533,6 @@ int Builder::load_build_file(const FS::Path &fn) return 0; } -/** -Creates targets for all packages and prepares them for building. - -@return 0 if everything went ok, -1 if something bad happened and a build - shouldn't be attempted -*/ int Builder::create_targets() { Target *world=new VirtualTarget(*this, "world"); @@ -644,8 +607,10 @@ int Builder::create_targets() } /* If world is to be built, prepare cmdline. If not, add cmdline to world - and prepare world. I don't really like this, but it keeps the graph - acyclic. */ + and prepare world. I don't really like this, but it keeps the graph + acyclic. + + XXX Could we skip preparing targets we are not interested in? */ if(build_world) cmdline->prepare(); else @@ -661,10 +626,6 @@ int Builder::create_targets() return 0; } -/** -Check if a header exists, either as a target or a file. Either an existing -target or a new SystemHeader target will be returned. -*/ Target *Builder::get_header(const Msp::FS::Path &fn) { Target *tgt=get_target(fn.str()); @@ -728,19 +689,6 @@ Target *Builder::get_library(const string &lib, const FS::Path &path, LibMode mo return 0; } -/** -Updates a hash with a string. This is used from get_header and get_library. -*/ -void Builder::update_hash(string &hash, const string &value) -{ - for(unsigned i=0; iget_config(); diff --git a/source/builder.h b/source/builder.h index 8eae216..90a8a7c 100644 --- a/source/builder.h +++ b/source/builder.h @@ -1,7 +1,7 @@ /* $Id$ This file is part of builder -Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions +Copyright © 2006-2009 Mikko Rasa, Mikkosoft Productions Distributed under the LGPL */ @@ -30,39 +30,16 @@ The main application class. Controls and owns everything. Rules the world. */ class Builder: public Msp::Application { -public: - Builder(int, char **); - unsigned get_verbose() const { return verbose; } - bool get_dry_run() const { return dry_run; } - bool get_build_all() const { return build_all; } - Package *get_package(const std::string &); - SourcePackage *get_main_package() const { return main_pkg; } - Target *get_target(const std::string &) const; - const TargetMap &get_targets() const { return targets; } - Target *get_header(const std::string &, const std::string &, const StringList &); - Target *get_library(const std::string &, const StringList &, LibMode); - const Msp::FS::Path &get_cwd() const { return cwd; } - const Architecture &get_architecture(const std::string &) const; - const Architecture &get_current_arch() const { return *current_arch; } - const Architecture &get_native_arch() const { return *native_arch; } - const Msp::FS::Path &get_prefix() const { return prefix; } - const StringList &get_warnings() const { return warnings; } - void apply_profile_template(Config &, const std::string &) const; - void add_target(Target *); - void problem(const std::string &, const std::string &); - int main(); - ~Builder(); - - static void usage(const char *, const char *, bool); private: class Loader: public Msp::DataFile::Loader { - public: - Loader(Builder &, const Msp::FS::Path &); private: - Builder &bld; + Builder &bld; Msp::FS::Path src; + public: + Loader(Builder &, const Msp::FS::Path &); + private: void architecture(const std::string &); void binpkg(const std::string &); void profile(const std::string &); @@ -71,67 +48,143 @@ private: class ProfileLoader: public Msp::DataFile::Loader { - public: - ProfileLoader(StringMap &); private: StringMap &profile; + public: + ProfileLoader(StringMap &); + private: void option(const std::string &, const std::string &); }; - typedef std::list PackageList; - typedef std::map PackageMap; - typedef std::map ProfileTemplateMap; + typedef std::list PackageList; + typedef std::map PackageMap; + typedef std::map ProfileTemplateMap; - StringList cmdline_targets; - StringMap cmdline_options; + StringList cmdline_targets; + StringMap cmdline_options; Msp::FS::Path cwd; - PackageMap packages; + PackageMap packages; SourcePackage *main_pkg; - PathList pkg_path; - PathList pkg_dirs; + PathList pkg_path; + PathList pkg_dirs; - TargetMap targets; - TargetList new_tgts; - TargetMap includes; - TargetMap libraries; + TargetMap targets; + TargetList new_tgts; + TargetMap includes; + TargetMap libraries; - ArchMap archs; + ArchMap archs; Architecture *native_arch; const Architecture *current_arch; ProfileTemplateMap profile_tmpl; - ProblemList problems; - Analyzer *analyzer; - bool build; - unsigned clean; - bool dry_run; - bool help; - unsigned verbose; - bool show_progress; - std::string build_file; - unsigned jobs; - StringList what_if; - bool conf_all; - bool conf_only; - bool build_all; - bool create_makefile; - Msp::FS::Path prefix; - StringList warnings; + ProblemList problems; + Analyzer *analyzer; + bool build; + unsigned clean; + bool dry_run; + bool help; + unsigned verbose; + bool show_progress; + std::string build_file; + unsigned jobs; + StringList what_if; + bool conf_all; + bool conf_only; + bool build_all; + bool create_makefile; + Msp::FS::Path prefix; + StringList warnings; + + static Msp::Application::RegApp reg; + +public: + Builder(int, char **); + ~Builder(); + + int main(); + unsigned get_verbose() const { return verbose; } + bool get_dry_run() const { return dry_run; } + bool get_build_all() const { return build_all; } + + /** Gets a package by name, possibly creating it. Returns 0 if the package + could not be located. */ + Package *get_package(const std::string &); + + SourcePackage *get_main_package() const { return main_pkg; } + + /** Looks up a target by name. Returns 0 if no such target exists. */ + Target *get_target(const std::string &) const; + + const TargetMap &get_targets() const { return targets; } + + /** Tries to locate a header based on location of including file and include + path. Considers known targets as well as existing files. If a matching + target is not found but a file exists, a new SystemHeader target will be + created and returned. */ + Target *get_header(const std::string &, const std::string &, const StringList &); + /** Tries to locate a library in a library path. The library name should be + the same as would be given to the linker with -l, i.e. without the "lib" + prefix or extension. Considers known targets as well as existing files. If + a matching target is not found but a file exists, a new SystemLibrary target + will be created and returned. */ + Target *get_library(const std::string &, const StringList &, LibMode); + + const Msp::FS::Path &get_cwd() const { return cwd; } + const Architecture &get_architecture(const std::string &) const; + const Architecture &get_current_arch() const { return *current_arch; } + const Architecture &get_native_arch() const { return *native_arch; } + const Msp::FS::Path &get_prefix() const { return prefix; } + const StringList &get_warnings() const { return warnings; } + void apply_profile_template(Config &, const std::string &) const; + + /** Adds a target to both the target map and the new target queue. Called + from Target constructor. */ + void add_target(Target *); + + void problem(const std::string &, const std::string &); + + static void usage(const char *, const char *, bool); + +private: + /** Determines the source directory of a package. Pkg-config is consulted + first, and if it fails, the package path is searched for matches. */ Msp::FS::Path get_package_location(const std::string &); - int load_build_file(const Msp::FS::Path &); - int create_targets(); + + /** Loads a build file. Returns 0 on success or -1 if the file could not be + opened. */ + int load_build_file(const Msp::FS::Path &); + + /** Creates targets for all packages and prepares them for building. + Returns 0 if everything went ok, -1 if something bad happened and a build + shouldn't be attempted. */ + int create_targets(); + + /** + Check if a header exists, either as a target or a file. Returns an existing + target of one was found, or a new SystemHeader target if there was no known + target but the file exists. + */ Target *get_header(const Msp::FS::Path &); + Target *get_library(const std::string &, const Msp::FS::Path &, LibMode); - void update_hash(std::string &, const std::string &); - int do_build(); - int do_clean(); - int do_create_makefile(); - void package_help(); - static Msp::Application::RegApp reg; + /** Supervises the build process, starting new actions when slots become + available. */ + int do_build(); + + /** Cleans buildable targets. If clean is 1, cleans only the default + package. If clean is 2 or greater, cleans all buildable packages. + */ + int do_clean(); + + int do_create_makefile(); + + /** Prints out information about the default package. */ + void package_help(); }; #endif diff --git a/source/buildinfo.cpp b/source/buildinfo.cpp index 36be492..9ad0a55 100644 --- a/source/buildinfo.cpp +++ b/source/buildinfo.cpp @@ -1,7 +1,7 @@ /* $Id$ This file is part of builder -Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions +Copyright © 2006-2009 Mikko Rasa, Mikkosoft Productions Distributed under the LGPL */ @@ -11,9 +11,25 @@ Distributed under the LGPL using namespace std; using namespace Msp; -/** -Adds another BuildInfo to the end of this one. -*/ +namespace { + +/** Removes any duplicate entries from a list, leaving only the first one. The +order of other elements is preserved. O(n²) efficiency. */ +void unique(StringList &l) +{ + for(StringList::iterator i=l.begin(); i!=l.end(); ++i) + for(StringList::iterator j=i; j!=l.end();) + { + if(j!=i && *j==*i) + j=l.erase(j); + else + ++j; + } +} + +} + + void BuildInfo::add(const BuildInfo &bi) { cflags.insert(cflags.end(), bi.cflags.begin(), bi.cflags.end()); @@ -25,17 +41,14 @@ void BuildInfo::add(const BuildInfo &bi) warnings.insert(warnings.end(), bi.warnings.begin(), bi.warnings.end()); } -/** -Makes sure there are no duplicate entries in the lists. -*/ void BuildInfo::unique() { - unique(cflags); - unique(defines); - unique(incpath); - unique(ldflags); - unique(libpath); - unique(libs); + ::unique(cflags); + ::unique(defines); + ::unique(incpath); + ::unique(ldflags); + ::unique(libpath); + ::unique(libs); for(StringList::iterator i=warnings.begin(); i!=warnings.end(); ++i) { @@ -59,21 +72,6 @@ void BuildInfo::unique() } } -/** -Removes any duplicate entries from a list, leaving only the first one. The -order of other elements is preserved. O(n²) efficiency. -*/ -void BuildInfo::unique(StringList &l) -{ - for(StringList::iterator i=l.begin(); i!=l.end(); ++i) - for(StringList::iterator j=i; j!=l.end();) - { - if(j!=i && *j==*i) - j=l.erase(j); - else - ++j; - } -} BuildInfo::Loader::Loader(BuildInfo &bi): binfo(bi) @@ -87,4 +85,37 @@ BuildInfo::Loader::Loader(BuildInfo &bi): add("warning", &Loader::warning); } +void BuildInfo::Loader::cflag(const std::string &s) +{ + binfo.cflags.push_back(s); +} + +void BuildInfo::Loader::incpath(const std::string &s) +{ + binfo.incpath.push_back(s); +} + +void BuildInfo::Loader::define(const std::string &s) +{ + binfo.defines.push_back(s); +} +void BuildInfo::Loader::ldflag(const std::string &s) +{ + binfo.ldflags.push_back(s); +} + +void BuildInfo::Loader::libpath(const std::string &s) +{ + binfo.libpath.push_back(s); +} + +void BuildInfo::Loader::library(const std::string &s) +{ + binfo.libs.push_back(s); +} + +void BuildInfo::Loader::warning(const std::string &s) +{ + binfo.warnings.push_back(s); +} diff --git a/source/buildinfo.h b/source/buildinfo.h index 9b208c1..a967bbd 100644 --- a/source/buildinfo.h +++ b/source/buildinfo.h @@ -1,7 +1,7 @@ /* $Id$ This file is part of builder -Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions +Copyright © 2006-2009 Mikko Rasa, Mikkosoft Productions Distributed under the LGPL */ @@ -22,18 +22,19 @@ class BuildInfo public: class Loader: public Msp::DataFile::Loader { - public: - Loader(BuildInfo &); private: BuildInfo &binfo; - void cflag(const std::string &s) { binfo.cflags.push_back(s); } - void incpath(const std::string &s) { binfo.incpath.push_back(s); } - void define(const std::string &s) { binfo.defines.push_back(s); } - void ldflag(const std::string &s) { binfo.ldflags.push_back(s); } - void libpath(const std::string &s) { binfo.libpath.push_back(s); } - void library(const std::string &s) { binfo.libs.push_back(s); } - void warning(const std::string &s) { binfo.warnings.push_back(s); } + public: + Loader(BuildInfo &); + private: + void cflag(const std::string &); + void incpath(const std::string &); + void define(const std::string &); + void ldflag(const std::string &); + void libpath(const std::string &); + void library(const std::string &); + void warning(const std::string &); }; StringList cflags; @@ -44,10 +45,12 @@ public: StringList libs; StringList warnings; + /** Adds another BuildInfo to the end of this one. */ void add(const BuildInfo &); + + /** Makes sure there are no duplicate entries in the lists. For warnings, + contradicting flags are eliminated and the last one stays in effect. */ void unique(); -private: - void unique(StringList &); }; #endif diff --git a/source/compile.cpp b/source/compile.cpp index 634ccd8..4157ccb 100644 --- a/source/compile.cpp +++ b/source/compile.cpp @@ -1,7 +1,7 @@ /* $Id$ This file is part of builder -Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions +Copyright © 2006-2009 Mikko Rasa, Mikkosoft Productions Distributed under the LGPL */ diff --git a/source/compile.h b/source/compile.h index d58b91b..05e57dc 100644 --- a/source/compile.h +++ b/source/compile.h @@ -1,7 +1,7 @@ /* $Id$ This file is part of builder -Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions +Copyright © 2006-2009 Mikko Rasa, Mikkosoft Productions Distributed under the LGPL */ diff --git a/source/component.cpp b/source/component.cpp index 26a0ab4..dcbaf37 100644 --- a/source/component.cpp +++ b/source/component.cpp @@ -1,7 +1,7 @@ /* $Id$ This file is part of builder -Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions +Copyright © 2006-2009 Mikko Rasa, Mikkosoft Productions Distributed under the LGPL */ @@ -33,9 +33,6 @@ Component::Component(SourcePackage &p, Type t, const string &n): deflt(true) { } -/** -Prepares the build information for building. -*/ void Component::create_build_info() { build_info.add(pkg.get_build_info()); @@ -81,9 +78,6 @@ void Component::create_build_info() build_info.unique(); } -/** -Creates all targets needed for building this component. -*/ void Component::create_targets() const { Builder &builder=pkg.get_builder(); @@ -121,7 +115,7 @@ void Component::create_targets() const if(build_exe) { - Executable *exe=0; + Executable *exe=0; StaticLibrary *slib=0; if(type==LIBRARY) { @@ -155,9 +149,6 @@ void Component::create_targets() const inst_tgt->add_depend(new Install(builder, pkg, **i)); } -/** -Collects all files belonging to the component. -*/ PathList Component::collect_source_files() const { PathList files; diff --git a/source/component.h b/source/component.h index 6fb231d..ce4a821 100644 --- a/source/component.h +++ b/source/component.h @@ -1,7 +1,7 @@ /* $Id$ This file is part of builder -Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions +Copyright © 2006-2009 Mikko Rasa, Mikkosoft Productions Distributed under the LGPL */ @@ -26,15 +26,15 @@ their own. class Component { public: - /// Loads a Component from file. Used from Package::Loader. class Loader: public Msp::DataFile::Loader { + private: + Component ∁ + public: Loader(Component &); Component &get_object() { return comp; } private: - Component ∁ - void source(const std::string &); void require(const std::string &); void modular(); @@ -50,34 +50,43 @@ public: HEADERS }; - Component(SourcePackage &, Type, const std::string &); - const SourcePackage &get_package() const { return pkg; } - Type get_type() const { return type; } - const std::string &get_name() const { return name; } - const PathList &get_sources() const { return sources; } - const BuildInfo &get_build_info() const { return build_info; } - bool get_install() const { return install; } - const std::string &get_install_headers() const { return install_headers; } - bool get_modular() const { return modular; } - const PackageList &get_requires() const { return requires; } - bool get_default() const { return deflt; } - void create_build_info(); - void create_targets() const; protected: SourcePackage &pkg; - Type type; + Type type; std::string name; - PathList sources; - bool install; + PathList sources; + bool install; std::string install_headers; const Component *module_host; - bool modular; - BuildInfo build_info; + bool modular; + BuildInfo build_info; PackageList requires; - bool deflt; + bool deflt; - PathList collect_source_files() const; +public: + Component(SourcePackage &, Type, const std::string &); + const SourcePackage &get_package() const { return pkg; } + Type get_type() const { return type; } + const std::string &get_name() const { return name; } + const PathList &get_sources() const { return sources; } + const BuildInfo &get_build_info() const { return build_info; } + bool get_install() const { return install; } + const std::string &get_install_headers() const { return install_headers; } + bool get_modular() const { return modular; } + const PackageList &get_requires() const { return requires; } + bool get_default() const { return deflt; } + + /** Prepares the build information for building. Pulls build info from the + parent and dependency packages, and adds any component-specific flags. */ + void create_build_info(); + + void create_targets() const; + +protected: + /** Returns a list of all source files for the component. */ + PathList collect_source_files() const; }; + typedef std::list ComponentList; #endif diff --git a/source/condition.cpp b/source/condition.cpp index 5cce444..e0068e0 100644 --- a/source/condition.cpp +++ b/source/condition.cpp @@ -1,7 +1,7 @@ /* $Id$ This file is part of builder -Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions +Copyright © 2007-2009 Mikko Rasa, Mikkosoft Productions Distributed under the LGPL */ diff --git a/source/condition.h b/source/condition.h index 2f3a5ef..12157f3 100644 --- a/source/condition.h +++ b/source/condition.h @@ -1,7 +1,7 @@ /* $Id$ This file is part of builder -Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions +Copyright © 2007, 2009 Mikko Rasa, Mikkosoft Productions Distributed under the LGPL */ @@ -20,24 +20,27 @@ class Condition public: class Loader: public Msp::DataFile::Loader { - public: - Loader(Condition &); private: Condition &cond; + public: + Loader(Condition &); + private: void require(const std::string &); void build_info(); }; - Condition(SourcePackage &, const std::string &); - const StringList &get_requires() const { return requires; } - const BuildInfo &get_build_info() const { return build_info; } - bool eval(); private: SourcePackage &pkg; - StringMap expression; + StringMap expression; StringList requires; - BuildInfo build_info; + BuildInfo build_info; + +public: + Condition(SourcePackage &, const std::string &); + const StringList &get_requires() const { return requires; } + const BuildInfo &get_build_info() const { return build_info; } + bool eval(); }; typedef std::list ConditionList; diff --git a/source/config.cpp b/source/config.cpp index da63cc9..d4f9384 100644 --- a/source/config.cpp +++ b/source/config.cpp @@ -1,7 +1,7 @@ /* $Id$ This file is part of builder -Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions +Copyright © 2006-2009 Mikko Rasa, Mikkosoft Productions Distributed under the LGPL */ @@ -25,22 +25,11 @@ Config::Config(SourcePackage &p): freeze_mtime(false) { } -/** -Adds a configuration option. - -@param n Option name -@param v Default value -@param d Description -*/ void Config::add_option(const string &n, const string &v, const string &d) { options.insert(OptionMap::value_type(n, Option(n, v, d))); } -/** -Gets the given option from the configuration. If the option doesn't exist, -an Exception is thrown. -*/ const Config::Option &Config::get_option(const string &name) const { OptionMap::const_iterator i=options.find(name); @@ -50,18 +39,11 @@ const Config::Option &Config::get_option(const string &name) const return i->second; } -/** -Checks whether an option with the given name exists. -*/ bool Config::is_option(const string &name) const { return options.count(name); } -/** -Selects the last profile used. If the profile cache file is not present, the -default profile is assumed. -*/ void Config::select_last_profile() { try @@ -81,10 +63,6 @@ void Config::select_last_profile() load(); } -/** -Selects the given profile. The profile cache file is updated as well, unless ---dry-run was given. -*/ void Config::select_profile(const string &profile) { set_option("profile", profile); @@ -102,15 +80,6 @@ void Config::select_profile(const string &profile) load(); } -/** -Processes options from the given raw option map. Nonexistent options are -ignored. If any options were changed, the mtime of the configuration is updated -to the current time. - -@param opts A map to process options from - -@return Whether any option values were changed -*/ bool Config::update(const StringMap &opts) { bool changed=false; @@ -126,9 +95,6 @@ bool Config::update(const StringMap &opts) return changed; } -/** -Expands any variable references in options. -*/ void Config::finish() { for(unsigned n=0; n<20; ++n) diff --git a/source/config.h b/source/config.h index 38ac5e4..16094e0 100644 --- a/source/config.h +++ b/source/config.h @@ -1,7 +1,7 @@ /* $Id$ This file is part of builder -Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions +Copyright © 2006-2009 Mikko Rasa, Mikkosoft Productions Distributed under the LGPL */ @@ -24,9 +24,7 @@ amount of options, as well as a modification time (mtime). class Config { public: - /** - A single configuration option. - */ + /** A single configuration option. */ struct Option { std::string name; @@ -36,35 +34,60 @@ public: Option(const std::string &, const std::string &, const std::string &); }; + typedef std::map OptionMap; - Config(SourcePackage &); - void add_option(const std::string &, const std::string &, const std::string &); - const Option &get_option(const std::string &) const; - const OptionMap &get_options() const { return options; } - const Msp::Time::TimeStamp &get_mtime() const { return mtime; } - bool is_option(const std::string &) const; - void select_last_profile(); - void select_profile(const std::string &); - bool update(const StringMap &); - void finish(); - void save() const; private: class Loader: public Msp::DataFile::Loader { - public: - Loader(Config &); private: Config &conf; + public: + Loader(Config &); + private: void option(const std::string &, const std::string &); }; - SourcePackage &package; - OptionMap options; + SourcePackage &package; + OptionMap options; Msp::Time::TimeStamp mtime; bool freeze_mtime; +public: + Config(SourcePackage &); + + /** Adds a configuration option with name, default value and description. */ + void add_option(const std::string &, const std::string &, const std::string &); + + /** Gets a configuration option by name. */ + const Option &get_option(const std::string &) const; + + const OptionMap &get_options() const { return options; } + const Msp::Time::TimeStamp &get_mtime() const { return mtime; } + + /** Checks whether an option exists. */ + bool is_option(const std::string &) const; + + /** Selects the last profile used. If the profile cache file is not + present, the default profile is assumed. */ + void select_last_profile(); + + /** Selects a profile. The profile cache file is updated, unless doing a + dry run. */ + void select_profile(const std::string &); + + /** Processes options from the given raw option map. Nonexistent options + are ignored. If any options were changed, the mtime of the configuration is + updated to the current time. Return value indicates whether any options + were changed. */ + bool update(const StringMap &); + + /** Expands any variable references in options. */ + void finish(); + + void save() const; +private: bool set_option(const std::string &, const std::string &); void load(); }; diff --git a/source/copy.cpp b/source/copy.cpp index a08085d..483b926 100644 --- a/source/copy.cpp +++ b/source/copy.cpp @@ -1,7 +1,7 @@ /* $Id$ This file is part of builder -Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions +Copyright © 2006-2009 Mikko Rasa, Mikkosoft Productions Distributed under the LGPL */ diff --git a/source/copy.h b/source/copy.h index 445de7b..0f30ecf 100644 --- a/source/copy.h +++ b/source/copy.h @@ -1,7 +1,7 @@ /* $Id$ This file is part of builder -Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions +Copyright © 2006-2009 Mikko Rasa, Mikkosoft Productions Distributed under the LGPL */ @@ -19,8 +19,6 @@ Copies a file to another place. Used by the Install target. */ class Copy: public InternalAction { -public: - Copy(Builder &, const Package &, const Msp::FS::Path &, const Msp::FS::Path &); private: /** A worker thread that actually does the data transfer. @@ -37,6 +35,9 @@ private: Msp::FS::Path src; Msp::FS::Path dest; + +public: + Copy(Builder &, const Package &, const Msp::FS::Path &, const Msp::FS::Path &); }; #endif diff --git a/source/dependencycache.cpp b/source/dependencycache.cpp index b2ba4e8..08d8af7 100644 --- a/source/dependencycache.cpp +++ b/source/dependencycache.cpp @@ -1,7 +1,7 @@ /* $Id$ This file is part of builder -Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions +Copyright © 2007-2009 Mikko Rasa, Mikkosoft Productions Distributed under the LGPL */ @@ -22,6 +22,12 @@ DependencyCache::DependencyCache(SourcePackage &p): changed(false) { } +void DependencyCache::set_deps(const string &tgt, const StringList &d) +{ + deps[tgt]=d; + changed=true; +} + const StringList &DependencyCache::get_deps(const string &tgt) const { DepsMap::const_iterator i=deps.find(tgt); @@ -31,16 +37,6 @@ const StringList &DependencyCache::get_deps(const string &tgt) const return i->second; } -void DependencyCache::set_deps(const string &tgt, const StringList &d) -{ - deps[tgt]=d; - changed=true; -} - -/** -Saves the depencency cache. If there are no cached dependencies or they -haven't been changed, does nothing. -*/ void DependencyCache::save() const { if(deps.empty() || !changed || package.get_builder().get_dry_run()) diff --git a/source/dependencycache.h b/source/dependencycache.h index f182f31..701c89e 100644 --- a/source/dependencycache.h +++ b/source/dependencycache.h @@ -1,7 +1,7 @@ /* $Id$ This file is part of builder -Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions +Copyright © 2007, 2009 Mikko Rasa, Mikkosoft Productions Distributed under the LGPL */ @@ -20,13 +20,6 @@ strings as value. The targets are free to store whatever they want here. */ class DependencyCache { -public: - DependencyCache(SourcePackage &p); - void set_deps(const std::string &tgt, const StringList &d); - const StringList &get_deps(const std::string &tgt) const; - const Msp::Time::TimeStamp &get_mtime() const { return mtime; } - void load(); - void save() const; private: typedef std::map DepsMap; @@ -34,6 +27,18 @@ private: DepsMap deps; Msp::Time::TimeStamp mtime; bool changed; + +public: + DependencyCache(SourcePackage &p); + void set_deps(const std::string &tgt, const StringList &d); + const StringList &get_deps(const std::string &tgt) const; + const Msp::Time::TimeStamp &get_mtime() const { return mtime; } + void load(); + + /** + Saves the depencency cache. Does nothing if the cache is empty or nothing + has changed. */ + void save() const; }; #endif diff --git a/source/executable.cpp b/source/executable.cpp index 25353cf..50ac3d3 100644 --- a/source/executable.cpp +++ b/source/executable.cpp @@ -1,7 +1,7 @@ /* $Id$ This file is part of builder -Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions +Copyright © 2006-2009 Mikko Rasa, Mikkosoft Productions Distributed under the LGPL */ @@ -29,9 +29,6 @@ Executable::Executable(Builder &b, const Component &c, const list add_depend(*i); } -/** -Finds and adds any required libraries to the dependencies. -*/ void Executable::find_depends() { LibMode libmode=comp.get_package().get_library_mode(); @@ -85,10 +82,6 @@ Action *Executable::create_action() return new Link(builder, *this); } -/** -Returns the name for the executable. We can't do this in the constructor since -we need to pass the value to the Target c'tor. -*/ string Executable::generate_target_name(const Component &c) { const SourcePackage &pkg=c.get_package(); diff --git a/source/executable.h b/source/executable.h index e415668..a6ebb97 100644 --- a/source/executable.h +++ b/source/executable.h @@ -1,7 +1,7 @@ /* $Id$ This file is part of builder -Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions +Copyright © 2006-2009 Mikko Rasa, Mikkosoft Productions Distributed under the LGPL */ @@ -19,16 +19,19 @@ library. */ class Executable: public Target { +private: + const Component ∁ + public: Executable(Builder &, const Component &, const std::list &); - const char *get_type() const { return "Executable"; } + virtual const char *get_type() const { return "Executable"; } const Component &get_component() const { return comp; } - void find_depends(); + virtual void find_depends(); private: - const Component ∁ - - virtual Action *create_action(); + virtual Action *create_action(); + /** Returns the name for the executable. We can't do this in the + constructor since we need to pass the value to the Target c'tor. */ static std::string generate_target_name(const Component &); }; diff --git a/source/externalaction.cpp b/source/externalaction.cpp index 5d01f4f..88c7e54 100644 --- a/source/externalaction.cpp +++ b/source/externalaction.cpp @@ -1,7 +1,7 @@ /* $Id$ This file is part of builder -Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions +Copyright © 2006-2009 Mikko Rasa, Mikkosoft Productions Distributed under the LGPL */ @@ -16,35 +16,6 @@ Distributed under the LGPL using namespace std; using namespace Msp; -int ExternalAction::check() -{ - if(builder.get_dry_run()) - { - signal_done.emit(); - return 0; - } - - if(!pid) - return exit_code; - - int status; - if(waitpid(pid, &status, WNOHANG)==pid) - { - signal_done.emit(); - if(WIFEXITED(status)) - exit_code=WEXITSTATUS(status); - else - exit_code=254; - pid=0; - return exit_code; - } - else - return -1; -} - -/** -Starts the external program. Fill in argv before calling this. -*/ void ExternalAction::launch() { if(builder.get_verbose()>=2) @@ -82,3 +53,29 @@ void ExternalAction::launch() pid=0; } } + +int ExternalAction::check() +{ + if(builder.get_dry_run()) + { + signal_done.emit(); + return 0; + } + + if(!pid) + return exit_code; + + int status; + if(waitpid(pid, &status, WNOHANG)==pid) + { + signal_done.emit(); + if(WIFEXITED(status)) + exit_code=WEXITSTATUS(status); + else + exit_code=254; + pid=0; + return exit_code; + } + else + return -1; +} diff --git a/source/externalaction.h b/source/externalaction.h index 26dbbfa..6df268f 100644 --- a/source/externalaction.h +++ b/source/externalaction.h @@ -1,7 +1,7 @@ /* $Id$ This file is part of builder -Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions +Copyright © 2006-2009 Mikko Rasa, Mikkosoft Productions Distributed under the LGPL */ @@ -18,16 +18,19 @@ Base class for Actions that want to execute an external program. */ class ExternalAction: public Action { -public: - int check(); protected: StringList argv; - Msp::FS::Path work_dir; - int pid; - int exit_code; + Msp::FS::Path work_dir; + int pid; + int exit_code; ExternalAction(Builder &b): Action(b), pid(0), exit_code(0) { } + + /** Starts the external program. Fill in argv before calling this. */ void launch(); + +public: + virtual int check(); }; #endif diff --git a/source/feature.h b/source/feature.h index 36d85bf..274f8e9 100644 --- a/source/feature.h +++ b/source/feature.h @@ -1,7 +1,7 @@ /* $Id$ This file is part of builder -Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions +Copyright © 2007, 2009 Mikko Rasa, Mikkosoft Productions Distributed under the LGPL */ @@ -15,6 +15,7 @@ struct Feature Feature(const std::string &n, const std::string &d): name(n), descr(d) { } }; + typedef std::list FeatureList; #endif diff --git a/source/file.h b/source/file.h index cd3eccf..bc71df8 100644 --- a/source/file.h +++ b/source/file.h @@ -1,7 +1,7 @@ /* $Id$ This file is part of builder -Copyright © 2007 Mikko Rasa, Mikkosoft Productions +Copyright © 2007-2009 Mikko Rasa, Mikkosoft Productions Distributed under the LGPL */ @@ -16,7 +16,7 @@ public: File(Builder &, const std::string &); virtual const char *get_type() const { return "File"; } private: - virtual Action *create_action() { return 0; } + virtual Action *create_action() { return 0; } }; #endif diff --git a/source/header.h b/source/header.h index ce1f625..a2b7c7d 100644 --- a/source/header.h +++ b/source/header.h @@ -1,7 +1,7 @@ /* $Id$ This file is part of builder -Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions +Copyright © 2006-2007, 2009 Mikko Rasa, Mikkosoft Productions Distributed under the LGPL */ @@ -16,8 +16,8 @@ Represents a header file. Mainly exists to give extra information to the user. class Header: public SourceFile { public: - Header(Builder &b, const Component *c, const std::string &f): SourceFile(b,c,f) { } - const char *get_type() const { return "Header"; } + Header(Builder &b, const Component *c, const std::string &f): SourceFile(b, c, f) { } + virtual const char *get_type() const { return "Header"; } }; /** @@ -26,9 +26,9 @@ A header file that doesn't belong to any known package. class SystemHeader: public Header { public: - SystemHeader(Builder &b, const std::string &f): Header(b,0,f) { } - const char *get_type() const { return "SystemHeader"; } - void find_depends() { deps_ready=true; } + SystemHeader(Builder &b, const std::string &f): Header(b, 0, f) { } + virtual const char *get_type() const { return "SystemHeader"; } + virtual void find_depends() { deps_ready=true; } }; #endif diff --git a/source/install.cpp b/source/install.cpp index dcc4677..d30eea0 100644 --- a/source/install.cpp +++ b/source/install.cpp @@ -1,7 +1,7 @@ /* $Id$ This file is part of builder -Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions +Copyright © 2006-2009 Mikko Rasa, Mikkosoft Productions Distributed under the LGPL */ diff --git a/source/install.h b/source/install.h index 84c2b23..41b4382 100644 --- a/source/install.h +++ b/source/install.h @@ -1,7 +1,7 @@ /* $Id$ This file is part of builder -Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions +Copyright © 2006-2009 Mikko Rasa, Mikkosoft Productions Distributed under the LGPL */ @@ -18,9 +18,9 @@ class Install: public Target { public: Install(Builder &, const SourcePackage &, Target &); - const char *get_type() const { return "Install"; } - void check_rebuild(); + virtual const char *get_type() const { return "Install"; } private: + virtual void check_rebuild(); virtual Action *create_action(); static std::string generate_target_name(const Target &); diff --git a/source/internalaction.cpp b/source/internalaction.cpp index 3063aff..8c85a4e 100644 --- a/source/internalaction.cpp +++ b/source/internalaction.cpp @@ -1,12 +1,17 @@ /* $Id$ This file is part of builder -Copyright © 2007 Mikko Rasa, Mikkosoft Productions +Copyright © 2007, 2009 Mikko Rasa, Mikkosoft Productions Distributed under the LGPL */ #include "internalaction.h" +InternalAction::InternalAction(Builder &b): + Action(b), + worker(0) +{ } + InternalAction::~InternalAction() { delete worker; @@ -30,11 +35,6 @@ int InternalAction::check() return -1; } -InternalAction::InternalAction(Builder &b): - Action(b), - worker(0) -{ } - InternalAction::Worker::Worker(): done(false), diff --git a/source/internalaction.h b/source/internalaction.h index 284db03..a35eae9 100644 --- a/source/internalaction.h +++ b/source/internalaction.h @@ -1,7 +1,7 @@ /* $Id$ This file is part of builder -Copyright © 2007 Mikko Rasa, Mikkosoft Productions +Copyright © 2007, 2009 Mikko Rasa, Mikkosoft Productions Distributed under the LGPL */ @@ -13,15 +13,11 @@ Distributed under the LGPL class InternalAction: public Action { -public: - virtual ~InternalAction(); - - virtual int check(); protected: class Worker: public Msp::Thread { public: - bool get_done() const { return done; } + bool get_done() const { return done; } bool get_error() const { return error; } protected: bool done; @@ -33,6 +29,10 @@ protected: Worker *worker; InternalAction(Builder &); +public: + virtual ~InternalAction(); + + virtual int check(); }; #endif diff --git a/source/link.cpp b/source/link.cpp index 95dfaa6..25713e1 100644 --- a/source/link.cpp +++ b/source/link.cpp @@ -1,7 +1,7 @@ /* $Id$ This file is part of builder -Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions +Copyright © 2006-2009 Mikko Rasa, Mikkosoft Productions Distributed under the LGPL */ diff --git a/source/misc.cpp b/source/misc.cpp index ab61d9f..4d2019a 100644 --- a/source/misc.cpp +++ b/source/misc.cpp @@ -1,7 +1,7 @@ /* $Id$ This file is part of builder -Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions +Copyright © 2006-2009 Mikko Rasa, Mikkosoft Productions Distributed under the LGPL */ @@ -15,10 +15,6 @@ Distributed under the LGPL using namespace std; using namespace Msp; -/** -Runs a command and returns its output as a string. The exit status of the -command is lost. -*/ string run_command(const StringList &argv) { int pfd[2]; diff --git a/source/misc.h b/source/misc.h index 6bbf7a0..508a9b0 100644 --- a/source/misc.h +++ b/source/misc.h @@ -1,7 +1,7 @@ /* $Id$ This file is part of builder -Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions +Copyright © 2006-2009 Mikko Rasa, Mikkosoft Productions Distributed under the LGPL */ @@ -20,10 +20,12 @@ enum LibMode DYNAMIC }; -typedef std::list StringList; +typedef std::list StringList; typedef std::list PathList; typedef std::map StringMap; +/** Runs a command and returns its output as a string. The exit status of the +command is lost. */ std::string run_command(const StringList &); #endif diff --git a/source/objectfile.cpp b/source/objectfile.cpp index 778f746..683c724 100644 --- a/source/objectfile.cpp +++ b/source/objectfile.cpp @@ -1,7 +1,7 @@ /* $Id$ This file is part of builder -Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions +Copyright © 2006-2009 Mikko Rasa, Mikkosoft Productions Distributed under the LGPL */ @@ -26,12 +26,6 @@ ObjectFile::ObjectFile(Builder &b, const Component &c, SourceFile &src): add_depend(&src); } -/** -Processes as many new dependences as possible. Some may be left unprocessed -if their own dependencies are not ready, requiring another call to this -function. Use the get_deps_ready() function to determine whether this is the -case. -*/ void ObjectFile::find_depends() { for(TargetList::iterator i=new_deps.begin(); i!=new_deps.end();) @@ -50,9 +44,6 @@ void ObjectFile::find_depends() } -/** -Recursively looks for header targets and adds them as dependencies. -*/ void ObjectFile::find_depends(Target *tgt) { const string &tname=tgt->get_name(); @@ -79,9 +70,6 @@ void ObjectFile::find_depends(Target *tgt) } } -/** -Adds a target to the dependency list as well as the new dependencies list. -*/ void ObjectFile::add_depend(Target *tgt) { Target::add_depend(tgt); diff --git a/source/objectfile.h b/source/objectfile.h index dbb49fe..4845a0f 100644 --- a/source/objectfile.h +++ b/source/objectfile.h @@ -1,7 +1,7 @@ /* $Id$ This file is part of builder -Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions +Copyright © 2006-2009 Mikko Rasa, Mikkosoft Productions Distributed under the LGPL */ @@ -18,18 +18,28 @@ Object files are compiled from source files. */ class ObjectFile: public Target { +private: + const Component ∁ + TargetList new_deps; + public: ObjectFile(Builder &, const Component &, SourceFile &); - const char *get_type() const { return "ObjectFile"; } + virtual const char *get_type() const { return "ObjectFile"; } const Component &get_component() const { return comp; } - void find_depends(); + + /** Processes as many new dependences as possible. Some may be created on + the fly and can't be processed until their own dependencies are ready. In + such cases this function needs to be called again. */ + virtual void find_depends(); + private: - const Component ∁ - TargetList new_deps; - + /** Recursively looks for header targets and adds them as dependencies. */ void find_depends(Target *); + + /** Adds a target to the dependency list as well as the new dependencies + list. */ void add_depend(Target *); - virtual Action *create_action(); + virtual Action *create_action(); static std::string generate_target_name(const Component &, const std::string &); }; diff --git a/source/package.cpp b/source/package.cpp index c905ee4..b35a0d8 100644 --- a/source/package.cpp +++ b/source/package.cpp @@ -1,7 +1,7 @@ /* $Id$ This file is part of builder -Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions +Copyright © 2006-2007, 2009 Mikko Rasa, Mikkosoft Productions Distributed under the LGPL */ @@ -16,9 +16,6 @@ using namespace Msp; #include -/** -Creates a buildable package. -*/ Package::Package(Builder &b, const string &n): builder(b), name(n), @@ -26,10 +23,6 @@ Package::Package(Builder &b, const string &n): use_pkgconfig(true) { } -/** -Collects all directly and indirectly required packages, including the package -itself. -*/ PackageList Package::collect_requires() { PackageList result; @@ -46,10 +39,6 @@ PackageList Package::collect_requires() return result; } -/** -Processes configuration options that were most likely obtained from the command -line. -*/ void Package::configure(const StringMap &opts, unsigned flag) { if(conf_done) @@ -71,7 +60,6 @@ void Package::configure(const StringMap &opts, unsigned flag) conf_done=true; } -/*** private ***/ Package::Loader::Loader(Package &p): pkg(p) diff --git a/source/package.h b/source/package.h index 4620cf4..2ee932b 100644 --- a/source/package.h +++ b/source/package.h @@ -1,7 +1,7 @@ /* $Id$ This file is part of builder -Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions +Copyright © 2006-2007, 2009 Mikko Rasa, Mikkosoft Productions Distributed under the LGPL */ @@ -37,29 +37,38 @@ public: void require(const std::string &); }; - const std::string &get_name() const { return name; } - Builder &get_builder() const { return builder; } - const PackageList &get_requires() const { return requires; } - PackageList collect_requires(); - const BuildInfo &get_exported_binfo() const { return export_binfo; } +protected: + Builder &builder; - /// Indicates whether or not this package supports pkg-config - bool get_use_pkgconfig() const { return use_pkgconfig; } + std::string name; + + PackageList requires; + BuildInfo export_binfo; + bool conf_done; - void configure(const StringMap &, unsigned); + bool use_pkgconfig; + + Package(Builder &, const std::string &); +public: virtual ~Package() { } -protected: - Builder &builder; - std::string name; + const std::string &get_name() const { return name; } + Builder &get_builder() const { return builder; } + const PackageList &get_requires() const { return requires; } - PackageList requires; - BuildInfo export_binfo; - bool conf_done; + /** Returns a list of all directly and indirectly required packages, + including the package itself. */ + PackageList collect_requires(); - bool use_pkgconfig; + const BuildInfo &get_exported_binfo() const { return export_binfo; } - Package(Builder &, const std::string &); + /// Indicates whether or not this package supports pkg-config + bool get_use_pkgconfig() const { return use_pkgconfig; } + + /** Processes configuration options that were most likely obtained from the + command line. */ + void configure(const StringMap &, unsigned); +protected: virtual void do_configure(const StringMap &, unsigned) { } virtual void create_build_info() { } }; diff --git a/source/pkgconfig.cpp b/source/pkgconfig.cpp index e8fca57..b38da6a 100644 --- a/source/pkgconfig.cpp +++ b/source/pkgconfig.cpp @@ -1,7 +1,7 @@ /* $Id$ This file is part of builder -Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions +Copyright © 2006-2009 Mikko Rasa, Mikkosoft Productions Distributed under the LGPL */ diff --git a/source/pkgconfig.h b/source/pkgconfig.h index 20e5fbf..b4d4d3b 100644 --- a/source/pkgconfig.h +++ b/source/pkgconfig.h @@ -1,7 +1,7 @@ /* $Id$ This file is part of builder -Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions +Copyright © 2006-2009 Mikko Rasa, Mikkosoft Productions Distributed under the LGPL */ @@ -16,12 +16,13 @@ Creates a .pc file to enable other packages fetch build options with pkg-config. */ class PkgConfig: public Target { -public: - PkgConfig(Builder &, const SourcePackage &); - const char *get_type() const { return "PkgConfig"; } private: const Package &pkg; +public: + PkgConfig(Builder &, const SourcePackage &); + virtual const char *get_type() const { return "PkgConfig"; } +private: virtual Action *create_action(); }; diff --git a/source/pkgconfigaction.cpp b/source/pkgconfigaction.cpp index 23684f6..ddc6742 100644 --- a/source/pkgconfigaction.cpp +++ b/source/pkgconfigaction.cpp @@ -1,7 +1,7 @@ /* $Id$ This file is part of builder -Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions +Copyright © 2006-2009 Mikko Rasa, Mikkosoft Productions Distributed under the LGPL */ diff --git a/source/pkgconfigaction.h b/source/pkgconfigaction.h index 83f574e..7c725bc 100644 --- a/source/pkgconfigaction.h +++ b/source/pkgconfigaction.h @@ -1,7 +1,7 @@ /* $Id$ This file is part of builder -Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions +Copyright © 2006-2007, 2009 Mikko Rasa, Mikkosoft Productions Distributed under the LGPL */ @@ -20,7 +20,7 @@ class PkgConfigAction: public Action { public: PkgConfigAction(Builder &, const PkgConfig &); - int check(); + virtual int check(); }; #endif diff --git a/source/problem.h b/source/problem.h index c2af878..53bb030 100644 --- a/source/problem.h +++ b/source/problem.h @@ -1,7 +1,7 @@ /* $Id$ This file is part of builder -Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions +Copyright © 2007, 2009 Mikko Rasa, Mikkosoft Productions Distributed under the LGPL */ diff --git a/source/sharedlibrary.h b/source/sharedlibrary.h index 92427d5..f86fa81 100644 --- a/source/sharedlibrary.h +++ b/source/sharedlibrary.h @@ -1,7 +1,7 @@ /* $Id$ This file is part of builder -Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions +Copyright © 2006-2007, 2009 Mikko Rasa, Mikkosoft Productions Distributed under the LGPL */ @@ -16,12 +16,13 @@ user. */ class SharedLibrary: public Executable { +private: + std::string libname; + public: SharedLibrary(Builder &, const Component &, const std::list &); - const char *get_type() const { return "SharedLibrary"; } + virtual const char *get_type() const { return "SharedLibrary"; } const std::string &get_libname() const { return libname; } -private: - std::string libname; }; #endif diff --git a/source/sourcefile.cpp b/source/sourcefile.cpp index cf74356..6c2cb76 100644 --- a/source/sourcefile.cpp +++ b/source/sourcefile.cpp @@ -1,7 +1,7 @@ /* $Id$ This file is part of builder -Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions +Copyright © 2006-2009 Mikko Rasa, Mikkosoft Productions Distributed under the LGPL */ @@ -22,10 +22,6 @@ SourceFile::SourceFile(Builder &b, const Component *c, const string &n): comp(c) { } -/** -Parses include directives from the file and looks up the appropriate targets -from Builder. -*/ void SourceFile::find_depends() { if(!comp) diff --git a/source/sourcefile.h b/source/sourcefile.h index ea6ed05..ec81d24 100644 --- a/source/sourcefile.h +++ b/source/sourcefile.h @@ -1,7 +1,7 @@ /* $Id$ This file is part of builder -Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions +Copyright © 2006-2009 Mikko Rasa, Mikkosoft Productions Distributed under the LGPL */ @@ -17,17 +17,18 @@ Represents a C or C++ source file. */ class SourceFile: public Target { +private: + const Component *comp; + StringList includes; + public: SourceFile(Builder &, const Component *, const std::string &); + virtual const char *get_type() const { return "SourceFile"; } const StringList &get_includes() const { return includes; } - const char *get_type() const { return "SourceFile"; } - const Component *get_component() const { return comp; } - void find_depends(); + const Component *get_component() const { return comp; } + virtual void find_depends(); private: - const Component *comp; - StringList includes; - - virtual Action *create_action() { return 0; } + virtual Action *create_action() { return 0; } }; #endif diff --git a/source/sourcepackage.cpp b/source/sourcepackage.cpp index 3fddfec..4edb702 100644 --- a/source/sourcepackage.cpp +++ b/source/sourcepackage.cpp @@ -1,7 +1,7 @@ /* $Id$ This file is part of builder -Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions +Copyright © 2007-2009 Mikko Rasa, Mikkosoft Productions Distributed under the LGPL */ @@ -16,9 +16,6 @@ Distributed under the LGPL using namespace std; using namespace Msp; -/** -Creates a buildable package. -*/ SourcePackage::SourcePackage(Builder &b, const string &n, const FS::Path &s): Package(b, n), source(s), @@ -42,11 +39,6 @@ Msp::FS::Path SourcePackage::get_out_dir() const return source/arch.get_name()/config.get_option("outdir").value; } -/** -Checks which kinds of things the components of this package install. - -@return A bitmask of installed things -*/ unsigned SourcePackage::get_install_flags() { unsigned flags=0; @@ -79,12 +71,6 @@ LibMode SourcePackage::get_library_mode() const throw Exception("Unknown library mode"); } -/*** private ***/ - -/** -Processes configuration options that were most likely obtained from the command -line. -*/ void SourcePackage::do_configure(const StringMap &opts, unsigned flag) { init_config(); @@ -135,9 +121,6 @@ void SourcePackage::do_configure(const StringMap &opts, unsigned flag) (*i)->configure(opts, flag&2);*/ } -/** -Initializes configuration options. -*/ void SourcePackage::init_config() { config.add_option("profile", "default", "Configuration profile"); @@ -160,10 +143,6 @@ void SourcePackage::init_config() } } -/** -Fills in build info based on configuration. All required packages must be -configured when this is called. -*/ void SourcePackage::create_build_info() { for(PackageList::iterator i=base_reqs.begin(); i!=base_reqs.end(); ++i) diff --git a/source/sourcepackage.h b/source/sourcepackage.h index 18d1395..b8750ee 100644 --- a/source/sourcepackage.h +++ b/source/sourcepackage.h @@ -1,7 +1,7 @@ /* $Id$ This file is part of builder -Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions +Copyright © 2007-2009 Mikko Rasa, Mikkosoft Productions Distributed under the LGPL */ @@ -33,7 +33,6 @@ public: DATA=8 }; - /// Loads a package from a file. class Loader: public Package::Loader { public: @@ -50,40 +49,50 @@ public: void tar_file(const std::string &); }; - SourcePackage(Builder &, const std::string &, const Msp::FS::Path &); - const std::string &get_name() const { return name; } - const std::string &get_version() const { return version; } - const std::string &get_description() const { return description; } - const Msp::FS::Path &get_source() const { return source; } - Msp::FS::Path get_temp_dir() const; - Msp::FS::Path get_out_dir() const; - const ComponentList &get_components() const { return components; } - const Config &get_config() const { return config; } - const BuildInfo &get_build_info() const { return build_info; } - const BuildInfo &get_exported_binfo() const { return export_binfo; } - Builder &get_builder() const { return builder; } - unsigned get_install_flags(); - LibMode get_library_mode() const; - const PathList &get_tar_files() const { return tar_files; } - DependencyCache &get_deps_cache() const { return deps_cache; } private: - std::string version; - std::string description; + std::string version; + std::string description; Msp::FS::Path source; - PackageList base_reqs; - FeatureList features; - BuildInfo build_info; + PackageList base_reqs; + FeatureList features; + BuildInfo build_info; ConditionList conditions; ComponentList components; - Config config; - bool conf_done; + Config config; + bool conf_done; mutable DependencyCache deps_cache; - PathList tar_files; + PathList tar_files; + +public: + SourcePackage(Builder &, const std::string &, const Msp::FS::Path &); + const std::string &get_name() const { return name; } + const std::string &get_version() const { return version; } + const std::string &get_description() const { return description; } + const Msp::FS::Path &get_source() const { return source; } + Msp::FS::Path get_temp_dir() const; + Msp::FS::Path get_out_dir() const; + const ComponentList &get_components() const { return components; } + const Config &get_config() const { return config; } + const BuildInfo &get_build_info() const { return build_info; } + const BuildInfo &get_exported_binfo() const { return export_binfo; } + Builder &get_builder() const { return builder; } - //Package(Builder &, const std::string &, const std::vector &); + /** Returns a bitmask indicating which kinds of things the components of + this package install. */ + unsigned get_install_flags(); + + LibMode get_library_mode() const; + const PathList &get_tar_files() const { return tar_files; } + DependencyCache &get_deps_cache() const { return deps_cache; } +private: virtual void do_configure(const StringMap &, unsigned); - void init_config(); + + /** Initializes configuration options. */ + void init_config(); + + /** Fills in build info based on configuration. All required packages must be + configured when this is called. */ virtual void create_build_info(); }; diff --git a/source/staticlibrary.cpp b/source/staticlibrary.cpp index 9a35677..a72f8e0 100644 --- a/source/staticlibrary.cpp +++ b/source/staticlibrary.cpp @@ -1,7 +1,7 @@ /* $Id$ This file is part of builder -Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions +Copyright © 2006-2009 Mikko Rasa, Mikkosoft Productions Distributed under the LGPL */ diff --git a/source/staticlibrary.h b/source/staticlibrary.h index cb27138..e3bd4e3 100644 --- a/source/staticlibrary.h +++ b/source/staticlibrary.h @@ -1,7 +1,7 @@ /* $Id$ This file is part of builder -Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions +Copyright © 2006-2009 Mikko Rasa, Mikkosoft Productions Distributed under the LGPL */ @@ -18,16 +18,17 @@ A static library target. */ class StaticLibrary: public Target { +private: + const Component ∁ + public: StaticLibrary(Builder &, const Component &, const std::list &); - const char *get_type() const { return "StaticLibrary"; } + virtual const char *get_type() const { return "StaticLibrary"; } const Component &get_component() const { return comp; } private: - const Component ∁ - - virtual Action *create_action(); + virtual Action *create_action(); - std::string generate_target_name(const Component &); + static std::string generate_target_name(const Component &); }; #endif diff --git a/source/systemlibrary.cpp b/source/systemlibrary.cpp index cbeab4a..2df0eb5 100644 --- a/source/systemlibrary.cpp +++ b/source/systemlibrary.cpp @@ -1,7 +1,7 @@ /* $Id$ This file is part of builder -Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions +Copyright © 2006-2009 Mikko Rasa, Mikkosoft Productions Distributed under the LGPL */ diff --git a/source/systemlibrary.h b/source/systemlibrary.h index 2b56f4c..c49c9e4 100644 --- a/source/systemlibrary.h +++ b/source/systemlibrary.h @@ -1,7 +1,7 @@ /* $Id$ This file is part of builder -Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions +Copyright © 2006-2009 Mikko Rasa, Mikkosoft Productions Distributed under the LGPL */ @@ -15,14 +15,15 @@ A library that doesn't belong to any known package. */ class SystemLibrary: public Target { +private: + std::string libname; + public: SystemLibrary(Builder &, const std::string &); - const char *get_type() const { return "SystemLibrary"; } + virtual const char *get_type() const { return "SystemLibrary"; } const std::string &get_libname() const { return libname; } private: - std::string libname; - - virtual Action *create_action() { return 0; } + virtual Action *create_action() { return 0; } }; #endif diff --git a/source/tar.cpp b/source/tar.cpp index 04beabf..797bf24 100644 --- a/source/tar.cpp +++ b/source/tar.cpp @@ -1,7 +1,7 @@ /* $Id$ This file is part of builder -Copyright © 2007 Mikko Rasa, Mikkosoft Productions +Copyright © 2007-2009 Mikko Rasa, Mikkosoft Productions Distributed under the LGPL */ diff --git a/source/tar.h b/source/tar.h index d81d31b..63652bb 100644 --- a/source/tar.h +++ b/source/tar.h @@ -1,7 +1,7 @@ /* $Id$ This file is part of builder -Copyright © 2007 Mikko Rasa, Mikkosoft Productions +Copyright © 2007, 2009 Mikko Rasa, Mikkosoft Productions Distributed under the LGPL */ @@ -16,8 +16,6 @@ class TarBall; class Tar: public InternalAction { -public: - Tar(Builder &, const TarBall &); private: class Worker: public InternalAction::Worker { @@ -32,6 +30,9 @@ private: const TarBall &tarball; StringList files; + +public: + Tar(Builder &, const TarBall &); }; #endif diff --git a/source/tarball.cpp b/source/tarball.cpp index 5782cec..a8d2ef8 100644 --- a/source/tarball.cpp +++ b/source/tarball.cpp @@ -1,7 +1,7 @@ /* $Id$ This file is part of builder -Copyright © 2007 Mikko Rasa, Mikkosoft Productions +Copyright © 2007-2009 Mikko Rasa, Mikkosoft Productions Distributed under the LGPL */ diff --git a/source/tarball.h b/source/tarball.h index cadd032..c2fa288 100644 --- a/source/tarball.h +++ b/source/tarball.h @@ -1,7 +1,7 @@ /* $Id$ This file is part of builder -Copyright © 2007 Mikko Rasa, Mikkosoft Productions +Copyright © 2007-2009 Mikko Rasa, Mikkosoft Productions Distributed under the LGPL */ @@ -12,14 +12,15 @@ Distributed under the LGPL class TarBall: public Target { +private: + std::string tarname; + public: TarBall(Builder &, const SourcePackage &, const std::string & =std::string()); virtual const char *get_type() const { return "TarBall"; } const SourcePackage *get_package() const; virtual void find_depends(); private: - std::string tarname; - virtual Action *create_action(); static std::string create_target_name(const SourcePackage &, const std::string &); diff --git a/source/target.cpp b/source/target.cpp index 0762050..b24013a 100644 --- a/source/target.cpp +++ b/source/target.cpp @@ -1,7 +1,7 @@ /* $Id$ This file is part of builder -Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions +Copyright © 2006-2009 Mikko Rasa, Mikkosoft Productions Distributed under the LGPL */ @@ -17,11 +17,24 @@ Distributed under the LGPL using namespace std; using namespace Msp; -/** -Tries to locate a target that will help getting this target built. If all -dependencies are up-to-date, returns this target. If there are no targets -ready to be built (maybe because they are being built right now), returns 0. -*/ +Target::Target(Builder &b, const Package *p, const string &n): + builder(b), + package(p), + name(n), + buildable(false), + building(false), + rebuild(false), + deps_ready(false), + prepared(false), + counted(false) +{ + builder.add_target(this); + + struct stat st; + if(!FS::stat(name, st)) + mtime=Time::TimeStamp::from_unixtime(st.st_mtime); +} + Target *Target::get_buildable_target() { if(!rebuild) @@ -51,11 +64,6 @@ void Target::add_depend(Target *dep) dep->rdepends.push_back(this); } -/** -Prepares the target by recursively preparing dependencies, then checking -whether rebuilding is needed. A flag is used to prevent unnecessary -executions. -*/ void Target::prepare() { if(prepared) @@ -91,10 +99,6 @@ Action *Target::build() return action; } -/** -Returns the number of targets that need to be rebuilt in order to get this -target up-to-date. -*/ unsigned Target::count_rebuild() { if(counted) @@ -107,41 +111,17 @@ unsigned Target::count_rebuild() return count; } -/** -Changes the mtime of the target to the current time. -*/ void Target::touch() { mtime=Time::now(); } -Target::Target(Builder &b, const Package *p, const string &n): - builder(b), - package(p), - name(n), - buildable(false), - building(false), - rebuild(false), - deps_ready(false), - prepared(false), - counted(false) -{ - builder.add_target(this); - - struct stat st; - if(!FS::stat(name, st)) - mtime=Time::TimeStamp::from_unixtime(st.st_mtime); -} - void Target::mark_rebuild(const std::string &reason) { rebuild=true; rebuild_reason=reason; } -/** -Checks if this target needs to be rebuilt and why. -*/ void Target::check_rebuild() { if(!buildable) @@ -167,9 +147,6 @@ void Target::check_rebuild() mark_rebuild("Package options changed"); } -/** -Handles for the build_done signal of Action. -*/ void Target::build_done() { building=false; diff --git a/source/target.h b/source/target.h index 04a360d..5deb234 100644 --- a/source/target.h +++ b/source/target.h @@ -1,7 +1,7 @@ /* $Id$ This file is part of builder -Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions +Copyright © 2006-2009 Mikko Rasa, Mikkosoft Productions Distributed under the LGPL */ @@ -26,57 +26,93 @@ handles many common tasks. Most targets are associated with a file. */ class Target { +protected: + Builder &builder; + const Package *package; + std::string name; + Msp::Time::TimeStamp mtime; + + bool buildable; + bool building; + bool rebuild; + std::string rebuild_reason; + + TargetList depends; + TargetList rdepends; + bool deps_ready; + + bool prepared; + bool counted; + + Target(Builder &, const Package *, const std::string &); public: - const std::string &get_name() const { return name; } - Target *get_buildable_target(); - bool get_buildable() const { return buildable; } - bool get_rebuild() const { return rebuild; } - const std::string &get_rebuild_reason() const { return rebuild_reason; } - const Msp::Time::TimeStamp &get_mtime() const { return mtime; } + virtual ~Target() { } + virtual const char *get_type() const=0; - const TargetList &get_depends() const { return depends; } - const Package *get_package() const { return package; } - bool get_depends_ready() const { return deps_ready; } - void add_depend(Target *); - virtual void prepare(); + const std::string &get_name() const { return name; } + const Package *get_package() const { return package; } + const Msp::Time::TimeStamp &get_mtime() const { return mtime; } + + /** + Tries to locate a target that will help getting this target built. If all + dependencies are up-to-date, returns this target. If there are no targets + ready to be built (maybe because they are being built right now), returns 0. + */ + Target *get_buildable_target(); + + bool get_buildable() const { return buildable; } + bool get_rebuild() const { return rebuild; } + const std::string &get_rebuild_reason() const { return rebuild_reason; } + void add_depend(Target *); + const TargetList &get_depends() const { return depends; } + bool get_depends_ready() const { return deps_ready; } /** Finds dependencies for the target. When all dependencies have been found, the function should set deps_ready to true. */ - virtual void find_depends() { deps_ready=true; } + virtual void find_depends() { deps_ready=true; } /** - Creates and returns an Action suitable for building this target. + Prepares the target by recursively preparing dependencies, then checking + whether rebuilding is needed. A flag is used to prevent unnecessary + executions. */ - Action *build(); + virtual void prepare(); - void reset_count() { counted=false; } - virtual unsigned count_rebuild(); - void touch(); - virtual ~Target() { } -protected: - Builder &builder; - const Package *package; - std::string name; - Msp::Time::TimeStamp mtime; + /** + Starts building the target. Returns the Action used for building. + */ + Action *build(); - bool buildable; - bool building; - bool rebuild; - std::string rebuild_reason; + void reset_count() { counted=false; } - TargetList depends; - TargetList rdepends; - bool deps_ready; + /** + Returns the number of targets that need to be rebuilt in order to get this + target up-to-date. + */ + virtual unsigned count_rebuild(); - bool prepared; - bool counted; + /** + Changes the mtime of the target to the current time. + */ + void touch(); +protected: + void mark_rebuild(const std::string &); - Target(Builder &, const Package *, const std::string &); - void mark_rebuild(const std::string &); + /** + Checks if the target needs to be rebuilt and why. + */ virtual void check_rebuild(); + + /** + Creates and returns an Action suitable for building this target. + */ virtual Action *create_action() =0; + + /** + Handles for the build_done signal of Action. + */ virtual void build_done(); }; diff --git a/source/unlink.cpp b/source/unlink.cpp index 90ccd4c..208fcf9 100644 --- a/source/unlink.cpp +++ b/source/unlink.cpp @@ -1,7 +1,7 @@ /* $Id$ This file is part of builder -Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions +Copyright © 2007-2009 Mikko Rasa, Mikkosoft Productions Distributed under the LGPL */ diff --git a/source/unlink.h b/source/unlink.h index d2df415..f26d163 100644 --- a/source/unlink.h +++ b/source/unlink.h @@ -1,7 +1,7 @@ /* $Id$ This file is part of builder -Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions +Copyright © 2007, 2009 Mikko Rasa, Mikkosoft Productions Distributed under the LGPL */ @@ -16,7 +16,7 @@ class Unlink: public Action { public: Unlink(Builder &, const Target &); - int check(); + virtual int check(); }; #endif diff --git a/source/virtualtarget.cpp b/source/virtualtarget.cpp index 9b41a80..b2a0d1c 100644 --- a/source/virtualtarget.cpp +++ b/source/virtualtarget.cpp @@ -1,7 +1,7 @@ /* $Id$ This file is part of builder -Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions +Copyright © 2006-2009 Mikko Rasa, Mikkosoft Productions Distributed under the LGPL */ @@ -12,20 +12,16 @@ Distributed under the LGPL using namespace std; using namespace Msp; -/** -Virtual targets are only rebuilt if their dependencies need rebuilding. -*/ void VirtualTarget::check_rebuild() { + // Virtual targets are only rebuilt if their dependencies need rebuilding. for(TargetList::iterator i=depends.begin(); (i!=depends.end() && !rebuild); ++i) if((*i)->get_rebuild()) mark_rebuild(FS::basename((*i)->get_name())+" needs rebuilding"); } -/** -Don't count virtual targets since "building" them causes no action. -*/ unsigned VirtualTarget::count_rebuild() { + // Don't count virtual targets since "building" them causes no action. return Target::count_rebuild()-rebuild; } diff --git a/source/virtualtarget.h b/source/virtualtarget.h index 67c3014..ecc237b 100644 --- a/source/virtualtarget.h +++ b/source/virtualtarget.h @@ -1,7 +1,7 @@ /* $Id$ This file is part of builder -Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions +Copyright © 2006-2009 Mikko Rasa, Mikkosoft Productions Distributed under the LGPL */ @@ -17,10 +17,10 @@ class VirtualTarget: public Target { public: VirtualTarget(Builder &b, const std::string &n): Target(b, 0, n) { } - const char *get_type() const { return "VirtualTarget"; } - unsigned count_rebuild(); + virtual const char *get_type() const { return "VirtualTarget"; } + virtual unsigned count_rebuild(); private: - void check_rebuild(); + virtual void check_rebuild(); virtual Action *create_action() { return 0; } };