]> git.tdb.fi Git - builder.git/commitdiff
Move main package tracking to PackageManager
authorMikko Rasa <tdb@tdb.fi>
Sat, 6 Apr 2013 21:22:53 +0000 (00:22 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sat, 6 Apr 2013 21:22:53 +0000 (00:22 +0300)
source/builder.cpp
source/builder.h
source/packagemanager.cpp
source/packagemanager.h

index 6794842c50d2c872e8ac36e560d2d2dc58fd624c..813f8ed788deff1c85f8eca5810134e85f8cfb63 100644 (file)
@@ -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<SourcePackage &>(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);
index 67b337553b2ebbfba0df6427b798cb876c7d465e..283b5fd3b949d4d454d29b451b23dc0a67f937ac 100644 (file)
@@ -54,7 +54,6 @@ private:
        Msp::FS::Path cwd;
 
        PackageManager package_manager;
-       SourcePackage *main_pkg;
 
        TargetMap targets;
 
index 240bf60caafd888ad9b56845331235c8849dce62..93fbbc9c0ed204b56b11fea1dde7a9f33dae9099 100644 (file)
@@ -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))
index 9fb373ec48152b70a16a5e56b93604c08176b38c..48c3c16fd4fcbdb486368fa2dfed5147af7f7b8b 100644 (file)
@@ -28,6 +28,7 @@ private:
        SearchPath binpkg_files;
        bool no_externals;
        PackageMap packages;
+       Package *main_pkg;
        std::set<std::string> 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. */