From: Mikko Rasa Date: Sat, 6 Apr 2013 21:22:53 +0000 (+0300) Subject: Move main package tracking to PackageManager X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=7606161ee4a6fd13c2f5ddca413ba3582df66f03;p=builder.git Move main package tracking to PackageManager --- diff --git a/source/builder.cpp b/source/builder.cpp index 6794842..813f8ed 100644 --- a/source/builder.cpp +++ b/source/builder.cpp @@ -35,7 +35,6 @@ using namespace Msp; Builder::Builder(int argc, char **argv): package_manager(*this), - main_pkg(0), native_arch(*this, string()), build_type(0), vfs(*this), @@ -392,7 +391,7 @@ bool Builder::prepare_build() Target *tarballs = new VirtualTarget(*this, "tarballs"); world->add_dependency(*tarballs); - main_pkg->prepare(); + package_manager.get_main_package().prepare(); // Make the cmdline target depend on all targets mentioned on the command line Target *cmdline = new VirtualTarget(*this, "cmdline"); @@ -558,7 +557,7 @@ int Builder::do_clean() Target *tgt = queue.front(); queue.erase(queue.begin()); - if(tgt->is_buildable() && (tgt->get_package()==main_pkg || clean>=2)) + if(tgt->is_buildable() && (tgt->get_package()==&package_manager.get_main_package() || clean>=2)) clean_tgts.insert(tgt); const Target::Dependencies &deps = tgt->get_dependencies(); @@ -579,11 +578,12 @@ int Builder::do_clean() void Builder::package_help() { - const Config &config = main_pkg->get_config(); + SourcePackage &main_pkg = dynamic_cast(package_manager.get_main_package()); + const Config &config = main_pkg.get_config(); const Config::OptionMap &options = config.get_options(); IO::print("Required packages:\n "); - const Package::Requirements &requires = main_pkg->get_required_packages(); + const Package::Requirements &requires = main_pkg.get_required_packages(); for(Package::Requirements::const_iterator i=requires.begin(); i!=requires.end(); ++i) { if(i!=requires.begin()) @@ -644,10 +644,8 @@ void Builder::Loader::profile(const string &) void Builder::Loader::package(const string &n) { SourcePackage *pkg = new SourcePackage(obj, n, get_source()); - if(!obj.main_pkg) - obj.main_pkg = pkg; - if(obj.conf_all || pkg==obj.main_pkg) + if(obj.conf_all || pkg==&obj.package_manager.get_main_package()) load_sub(*pkg, obj.cmdline_options); else load_sub(*pkg); diff --git a/source/builder.h b/source/builder.h index 67b3375..283b5fd 100644 --- a/source/builder.h +++ b/source/builder.h @@ -54,7 +54,6 @@ private: Msp::FS::Path cwd; PackageManager package_manager; - SourcePackage *main_pkg; TargetMap targets; diff --git a/source/packagemanager.cpp b/source/packagemanager.cpp index 240bf60..93fbbc9 100644 --- a/source/packagemanager.cpp +++ b/source/packagemanager.cpp @@ -19,6 +19,7 @@ using namespace Msp; PackageManager::PackageManager(Builder &b): builder(b), no_externals(false), + main_pkg(0), env_set(false) { } @@ -54,9 +55,19 @@ void PackageManager::add_package(Package *pkg) throw logic_error("Package is already managed"); } + if(packages.empty()) + main_pkg = pkg; + packages.insert(PackageMap::value_type(pkg->get_name(), pkg)); } +Package &PackageManager::get_main_package() const +{ + if(!main_pkg) + throw logic_error("No packages"); + return *main_pkg; +} + Package *PackageManager::find_package(const string &name) { if(not_found.count(name)) diff --git a/source/packagemanager.h b/source/packagemanager.h index 9fb373e..48c3c16 100644 --- a/source/packagemanager.h +++ b/source/packagemanager.h @@ -28,6 +28,7 @@ private: SearchPath binpkg_files; bool no_externals; PackageMap packages; + Package *main_pkg; std::set not_found; bool env_set; @@ -50,6 +51,10 @@ public: /** Returns a package from the cache. */ Package *get_package(const std::string &); + /** Returns the package that was added first. This should be considered + the primary build target. */ + Package &get_main_package() const; + const PackageMap &get_packages() const { return packages; } /** Locates a package and loads it if necessary. */