From: Mikko Rasa Date: Mon, 16 Jul 2012 18:24:58 +0000 (+0300) Subject: Trim down the package preparation code X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=bd61d7f;p=builder.git Trim down the package preparation code --- diff --git a/source/builder.cpp b/source/builder.cpp index c08c305..c86c5da 100644 --- a/source/builder.cpp +++ b/source/builder.cpp @@ -263,8 +263,6 @@ int Builder::main() } } - main_pkg->configure(cmdline_options, conf_all?2:1); - if(help) { usage(0, "builder", false); @@ -293,7 +291,7 @@ int Builder::main() list package_details; for(PackageManager::PackageMap::const_iterator i=packages.begin(); i!=packages.end(); ++i) { - if(!i->second || !i->second->is_configured()) + if(!i->second || !i->second->is_prepared()) continue; string line = i->second->get_name(); @@ -410,10 +408,7 @@ int Builder::create_targets() Target *tarballs = new VirtualTarget(*this, "tarballs"); world->add_depend(*tarballs); - const PackageManager::PackageMap &packages = package_manager.get_packages(); - for(PackageManager::PackageMap::const_iterator i=packages.begin(); i!=packages.end(); ++i) - if(i->second && i->second->is_configured()) - i->second->create_targets(); + main_pkg->prepare(); // Make the cmdline target depend on all targets mentioned on the command line Target *cmdline = new VirtualTarget(*this, "cmdline"); @@ -456,6 +451,7 @@ int Builder::create_targets() if(!dry_run) { + const PackageManager::PackageMap &packages = package_manager.get_packages(); for(PackageManager::PackageMap::const_iterator i=packages.begin(); i!=packages.end(); ++i) i->second->save_caches(); } diff --git a/source/component.cpp b/source/component.cpp index 3ce6b14..3f8b004 100644 --- a/source/component.cpp +++ b/source/component.cpp @@ -30,10 +30,10 @@ Component::Component(SourcePackage &p, Type t, const string &n): deflt(true) { } -void Component::configure(const StringMap &opts, unsigned flag) +void Component::prepare() { for(PackageList::const_iterator i=requires.begin(); i!=requires.end(); ++i) - (*i)->configure(opts, flag&2); + (*i)->prepare(); } void Component::create_build_info() diff --git a/source/component.h b/source/component.h index 140cca1..561a250 100644 --- a/source/component.h +++ b/source/component.h @@ -64,7 +64,7 @@ public: bool is_default() const { return deflt; } const InstallMap &get_install_map() const { return install_map; } - void configure(const StringMap &, unsigned); + void prepare(); /** Prepares the build information for building. Pulls build info from the parent and dependency packages, and adds any component-specific flags. */ diff --git a/source/config.cpp b/source/config.cpp index c6dcb70..8cabb56 100644 --- a/source/config.cpp +++ b/source/config.cpp @@ -34,24 +34,6 @@ bool Config::is_option(const string &name) const return options.count(name); } -bool Config::update(const StringMap &opts) -{ - bool changed_now = false; - for(StringMap::const_iterator i=opts.begin(); i!=opts.end(); ++i) - { - if(set_option(i->first, i->second) && i->first!="profile") - changed_now = true; - } - - if(changed_now) - { - mtime = Time::now(); - changed = true; - } - - return changed_now; -} - void Config::save() const { if(!changed) diff --git a/source/config.h b/source/config.h index 9043208..8372af9 100644 --- a/source/config.h +++ b/source/config.h @@ -61,12 +61,6 @@ public: /** Checks whether an option exists. */ bool is_option(const std::string &) const; - /** 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 &); - void save() const; bool set_option(const std::string &, const std::string &); void load(); diff --git a/source/package.cpp b/source/package.cpp index f74b4a0..7ec986e 100644 --- a/source/package.cpp +++ b/source/package.cpp @@ -11,30 +11,23 @@ using namespace Msp; Package::Package(Builder &b, const string &n): builder(b), name(n), - conf_done(false), + prepared(false), use_pkgconfig(true) { builder.get_package_manager().add_package(this); } -void Package::configure(const StringMap &opts, unsigned flag) +void Package::prepare() { - if(conf_done) + if(prepared) return; - builder.get_logger().log("configure", format("Configuring %s", name)); - - do_configure(opts, flag); - - requires.sort(); - requires.unique(); - - for(PackageList::iterator i=requires.begin(); i!=requires.end(); ++i) - (*i)->configure(opts, flag&2); + for(PackageList::const_iterator i=requires.begin(); i!=requires.end(); ++i) + (*i)->prepare(); create_build_info(); - - conf_done = true; + create_targets(); + prepared = true; } diff --git a/source/package.h b/source/package.h index 14b343d..e98f4e7 100644 --- a/source/package.h +++ b/source/package.h @@ -5,6 +5,7 @@ #include #include #include "buildinfo.h" +#include "config.h" class Builder; class Package; @@ -34,7 +35,7 @@ protected: PackageList requires; BuildInfo export_binfo; - bool conf_done; + bool prepared; bool use_pkgconfig; @@ -51,18 +52,17 @@ public: /// 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); + /** Prepares the package for building. Recursively prepares all required + packages, populates build info and creates targets. */ + void prepare(); - bool is_configured() const { return conf_done; } + bool is_prepared() const { return prepared; } protected: - virtual void do_configure(const StringMap &, unsigned) { } virtual void create_build_info() { } -public: virtual void create_targets() { } +public: virtual void save_caches() { } }; diff --git a/source/sourcepackage.cpp b/source/sourcepackage.cpp index ca49976..06ab5fe 100644 --- a/source/sourcepackage.cpp +++ b/source/sourcepackage.cpp @@ -63,25 +63,6 @@ FS::Path SourcePackage::get_out_dir() const return source/arch.get_name()/detail; } -void SourcePackage::do_configure(const StringMap &opts, unsigned flag) -{ - init_config(); - - config.load(); - - if(flag && config.update(opts)) - builder.get_logger().log("configure", format("Configuration of %s changed", name)); - - deps_cache.load(); - - for(ComponentList::iterator i=components.begin(); i!=components.end(); ++i) - i->configure(opts, flag); -} - -void SourcePackage::init_config() -{ -} - void SourcePackage::create_build_info() { if(build_type) @@ -110,6 +91,7 @@ void SourcePackage::create_build_info() for(list::iterator i=components.begin(); i!=components.end(); ++i) { + i->prepare(); i->create_build_info(); if(i->get_type()==Component::LIBRARY) export_binfo.libs.push_back(i->get_name()); @@ -118,6 +100,8 @@ void SourcePackage::create_build_info() void SourcePackage::create_targets() { + deps_cache.load(); + bool pc_needed = false; for(ComponentList::const_iterator i=components.begin(); i!=components.end(); ++i) { diff --git a/source/sourcepackage.h b/source/sourcepackage.h index 23e376e..d55d373 100644 --- a/source/sourcepackage.h +++ b/source/sourcepackage.h @@ -78,11 +78,6 @@ public: DependencyCache &get_deps_cache() const { return deps_cache; } private: - virtual void do_configure(const StringMap &, unsigned); - - /** 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();