]> git.tdb.fi Git - builder.git/commitdiff
Hide the main package from the outside
authorMikko Rasa <tdb@tdb.fi>
Tue, 17 Jul 2012 10:37:56 +0000 (13:37 +0300)
committerMikko Rasa <tdb@tdb.fi>
Tue, 17 Jul 2012 10:37:56 +0000 (13:37 +0300)
source/builder.cpp
source/builder.h
source/component.cpp

index 7b222df4997c1f05e31febfef670a10d46fc80dd..6c508026c6e7a67e6b32198609e3a5c112d21d9b 100644 (file)
@@ -331,6 +331,14 @@ void Builder::add_target(Target *t)
        targets.insert(TargetMap::value_type(t->get_name(), t));
 }
 
+void Builder::add_primary_target(Target &t)
+{
+       get_target("world")->add_dependency(t);
+
+       if(t.get_package()==main_pkg && t.get_component() && t.get_component()->is_default())
+               get_target("default")->add_dependency(t);
+}
+
 void Builder::usage(const char *reason, const char *argv0, bool brief)
 {
        if(reason)
index 933fbb05599dd66a01de8d8a147411a9a3c94e0f..4359d4563f7214849b89ed6e4f3495e1565f36dc 100644 (file)
@@ -96,7 +96,6 @@ public:
        bool get_dry_run() const { return dry_run; }
 
        PackageManager &get_package_manager() { return package_manager; }
-       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;
@@ -117,6 +116,12 @@ public:
        from Target constructor. */
        void add_target(Target *);
 
+       /** Adds a target that is a primary build goal.  Such targets will be added
+       as dependencies of the "world" virtual target.  If the target belongs to a
+       default component of the main package, it's also added to the "default"
+       virtual target. */
+       void add_primary_target(Target &);
+
        void problem(const std::string &, const std::string &);
 
        static void usage(const char *, const char *, bool);
index 23bd37417142235a7d13878f76f03a58a704d210..e9d9a700d202d0fcebab400c01df24ca6e5484e5 100644 (file)
@@ -81,8 +81,6 @@ void Component::create_targets() const
 {
        Builder &builder = package.get_builder();
        const Toolchain &toolchain = builder.get_toolchain();
-       Target *world = builder.get_target("world");
-       Target *def_tgt = builder.get_target("default");
 
        PathList source_filenames = collect_source_files();
        list<Target *> inst_list;
@@ -149,10 +147,7 @@ void Component::create_targets() const
                        source = new File(builder, package, source_filenames.front());
                Target *result = dcomp.create_target(*source);
 
-               if(&package==builder.get_main_package() && deflt)
-                       def_tgt->add_dependency(*result);
-               else
-                       world->add_dependency(*result);
+               builder.add_primary_target(*result);
                if(install)
                        inst_list.push_back(result);
        }
@@ -194,10 +189,7 @@ void Component::create_targets() const
 
                for(list<Target *>::const_iterator i=results.begin(); i!=results.end(); ++i)
                {
-                       if(&package==builder.get_main_package() && deflt)
-                               def_tgt->add_dependency(**i);
-                       else
-                               world->add_dependency(**i);
+                       builder.add_primary_target(**i);
                        if(install)
                                inst_list.push_back(*i);
                }