From d861af0938a9043270245f6973d4ddbdc94e75b4 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Tue, 17 Jul 2012 13:37:56 +0300 Subject: [PATCH] Hide the main package from the outside --- source/builder.cpp | 8 ++++++++ source/builder.h | 7 ++++++- source/component.cpp | 12 ++---------- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/source/builder.cpp b/source/builder.cpp index 7b222df..6c50802 100644 --- a/source/builder.cpp +++ b/source/builder.cpp @@ -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) diff --git a/source/builder.h b/source/builder.h index 933fbb0..4359d45 100644 --- a/source/builder.h +++ b/source/builder.h @@ -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); diff --git a/source/component.cpp b/source/component.cpp index 23bd374..e9d9a70 100644 --- a/source/component.cpp +++ b/source/component.cpp @@ -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 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::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); } -- 2.43.0