From c679a9dd1a97ae3b1ffa568143d42d02c2ca9e74 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Mon, 10 Sep 2007 15:15:49 +0000 Subject: [PATCH] Refactor code to get rid of class PackageRef --- source/builder.cpp | 22 ++++---------- source/builder.h | 1 - source/component.cpp | 22 ++++---------- source/component.h | 9 +++--- source/condition.cpp | 8 +----- source/condition.h | 6 ++-- source/package.cpp | 20 ++++++------- source/package.h | 12 ++++---- source/packageref.cpp | 30 ------------------- source/packageref.h | 34 ---------------------- source/pkgconfigaction.cpp | 8 +++--- source/sourcepackage.cpp | 59 +++++++++++--------------------------- source/sourcepackage.h | 4 +-- 13 files changed, 53 insertions(+), 182 deletions(-) delete mode 100644 source/packageref.cpp delete mode 100644 source/packageref.h diff --git a/source/builder.cpp b/source/builder.cpp index f10f0eb..6ee2101 100644 --- a/source/builder.cpp +++ b/source/builder.cpp @@ -173,8 +173,6 @@ Package *Builder::get_package(const string &n) Package *pkg=BinaryPackage::from_pkgconfig(*this, n); packages.insert(PackageMap::value_type(n, pkg)); - if(pkg) - new_pkgs.push_back(pkg); return pkg; } @@ -331,13 +329,6 @@ int Builder::main() return 1; } - while(!new_pkgs.empty()) - { - Package *pkg=new_pkgs.front(); - new_pkgs.erase(new_pkgs.begin()); - pkg->resolve_refs(); - } - default_pkg->configure(cmdline_options, conf_all?2:1); if(help) @@ -773,12 +764,12 @@ void Builder::package_help() const Config::OptionMap &options=config.get_options(); cout<<"Required packages:\n "; - const PkgRefList &requires=default_pkg->get_requires(); - for(PkgRefList::const_iterator i=requires.begin(); i!=requires.end(); ++i) + const PackageList &requires=default_pkg->get_requires(); + for(PackageList::const_iterator i=requires.begin(); i!=requires.end(); ++i) { if(i!=requires.begin()) cout<<", "; - cout<get_name(); + cout<<(*i)->get_name(); } cout<<"\n\n"; cout<<"Package configuration:\n"; @@ -812,7 +803,6 @@ void Builder::Loader::binpkg(const string &n) BinaryPackage *pkg=new BinaryPackage(bld, n); load_sub(*pkg); bld.packages.insert(PackageMap::value_type(n, pkg)); - bld.new_pkgs.push_back(pkg); } void Builder::Loader::profile(const string &n) @@ -825,11 +815,11 @@ void Builder::Loader::profile(const string &n) void Builder::Loader::package(const string &n) { SourcePackage *pkg=new SourcePackage(bld, n, src); - load_sub(*pkg); - bld.packages.insert(PackageMap::value_type(n, pkg)); - bld.new_pkgs.push_back(pkg); if(!bld.default_pkg) bld.default_pkg=pkg; + + load_sub(*pkg); + bld.packages.insert(PackageMap::value_type(n, pkg)); } diff --git a/source/builder.h b/source/builder.h index 879781d..6da42a1 100644 --- a/source/builder.h +++ b/source/builder.h @@ -83,7 +83,6 @@ private: Msp::Path::Path cwd; PackageMap packages; - PackageList new_pkgs; SourcePackage *default_pkg; TargetMap targets; diff --git a/source/component.cpp b/source/component.cpp index 6272321..e338676 100644 --- a/source/component.cpp +++ b/source/component.cpp @@ -31,15 +31,6 @@ Component::Component(SourcePackage &p, Type t, const string &n): deflt(true) { } -/** -Tries to resolve all references to packages. -*/ -void Component::resolve_refs() -{ - for(PkgRefList::iterator i=requires.begin(); i!=requires.end(); ++i) - i->resolve(); -} - /** Prepares the build information for building. */ @@ -47,13 +38,8 @@ void Component::create_build_info() { build_info.add(pkg.get_build_info()); - for(PkgRefList::iterator i=requires.begin(); i!=requires.end(); ++i) - { - if(!i->get_package()) - continue; - //i->get_package()->create_build_info(); - build_info.add(i->get_package()->get_exported_binfo()); - } + for(PackageList::iterator i=requires.begin(); i!=requires.end(); ++i) + build_info.add((*i)->get_exported_binfo()); if(type==PROGRAM) { @@ -196,7 +182,9 @@ void Component::Loader::source(const string &s) void Component::Loader::require(const string &n) { - comp.requires.push_back(PackageRef(comp.pkg.get_builder(), n)); + Package *req=comp.pkg.get_builder().get_package(n); + if(req) + comp.requires.push_back(req); } void Component::Loader::modular() diff --git a/source/component.h b/source/component.h index 387de4c..8dec239 100644 --- a/source/component.h +++ b/source/component.h @@ -13,7 +13,7 @@ Distributed under the LGPL #include #include "buildinfo.h" #include "misc.h" -#include "packageref.h" +#include "package.h" class SourcePackage; @@ -51,7 +51,7 @@ public: }; Component(SourcePackage &, Type, const std::string &); - const SourcePackage &get_package() const { return pkg; } + const SourcePackage &get_package() const { return pkg; } Type get_type() const { return type; } const std::string &get_name() const { return name; } const PathList &get_sources() const { return sources; } @@ -59,9 +59,8 @@ public: bool get_install() const { return install; } const std::string &get_install_headers() const { return install_headers; } bool get_modular() const { return modular; } - const PkgRefList &get_requires() const { return requires; } + const PackageList &get_requires() const { return requires; } bool get_default() const { return deflt; } - void resolve_refs(); void create_build_info(); void create_targets() const; protected: @@ -74,7 +73,7 @@ protected: const Component *module_host; bool modular; BuildInfo build_info; - PkgRefList requires; + PackageList requires; bool deflt; PathList collect_source_files() const; diff --git a/source/condition.cpp b/source/condition.cpp index c4c01b2..4b45dca 100644 --- a/source/condition.cpp +++ b/source/condition.cpp @@ -32,12 +32,6 @@ Condition::Condition(SourcePackage &p, const string &expr): } } -void Condition::resolve_refs() -{ - for(PkgRefList::iterator i=requires.begin(); i!=requires.end(); ++i) - i->resolve(); -} - bool Condition::eval() { const Config &conf=pkg.get_config(); @@ -67,7 +61,7 @@ Condition::Loader::Loader(Condition &c): void Condition::Loader::require(const string &pkg) { - cond.requires.push_back(PackageRef(cond.pkg.get_builder(), pkg)); + cond.requires.push_back(pkg); } void Condition::Loader::build_info() diff --git a/source/condition.h b/source/condition.h index 433c0c8..2f3a5ef 100644 --- a/source/condition.h +++ b/source/condition.h @@ -11,7 +11,6 @@ Distributed under the LGPL #include #include "buildinfo.h" #include "misc.h" -#include "packageref.h" class Config; class SourcePackage; @@ -31,14 +30,13 @@ public: }; Condition(SourcePackage &, const std::string &); - const PkgRefList &get_requires() const { return requires; } + const StringList &get_requires() const { return requires; } const BuildInfo &get_build_info() const { return build_info; } - void resolve_refs(); bool eval(); private: SourcePackage &pkg; StringMap expression; - PkgRefList requires; + StringList requires; BuildInfo build_info; }; typedef std::list ConditionList; diff --git a/source/package.cpp b/source/package.cpp index 23a8d9c..20fec32 100644 --- a/source/package.cpp +++ b/source/package.cpp @@ -26,15 +26,6 @@ Package::Package(Builder &b, const string &n): use_pkgconfig(true) { } -/** -Tries to resolve all references to dependency packages. -*/ -void Package::resolve_refs() -{ - for(PkgRefList::iterator i=requires.begin(); i!=requires.end(); ++i) - i->resolve(); -} - /** Processes configuration options that were most likely obtained from the command line. @@ -49,8 +40,11 @@ void Package::configure(const StringMap &opts, unsigned flag) do_configure(opts, flag); - for(PkgRefList::iterator i=requires.begin(); i!=requires.end(); ++i) - i->get_package()->configure(opts, flag&2); + requires.sort(); + requires.unique(); + + for(PackageList::iterator i=requires.begin(); i!=requires.end(); ++i) + (*i)->configure(opts, flag&2); create_build_info(); @@ -67,5 +61,7 @@ Package::Loader::Loader(Package &p): void Package::Loader::require(const string &n) { - pkg.requires.push_back(PackageRef(pkg.builder, n)); + Package *req=pkg.builder.get_package(n); + if(req) + pkg.requires.push_back(req); } diff --git a/source/package.h b/source/package.h index f8ef745..a2563bf 100644 --- a/source/package.h +++ b/source/package.h @@ -12,7 +12,6 @@ Distributed under the LGPL #include #include #include "buildinfo.h" -#include "packageref.h" class Builder; class Package; @@ -20,9 +19,9 @@ class Package; typedef std::list PackageList; /** -A package is a distributable piece of software. They consist of one or more -Components and may depend on other packages. Packages also have configuration -to determine where files are installed and which features to include. +A package is a distributable piece of software. Package information may be +obtained in several ways: Build files of source packages, pkg-config for binary +packages and the builderrc file for binary packages with no pkg-config support. */ class Package { @@ -40,13 +39,12 @@ public: const std::string &get_name() const { return name; } Builder &get_builder() const { return builder; } - const PkgRefList &get_requires() const { return requires; } + const PackageList &get_requires() const { return requires; } const BuildInfo &get_exported_binfo() const { return export_binfo; } /// Indicates whether or not this package supports pkg-config bool get_use_pkgconfig() const { return use_pkgconfig; } - virtual void resolve_refs(); void configure(const StringMap &, unsigned); virtual ~Package() { } protected: @@ -54,7 +52,7 @@ protected: std::string name; - PkgRefList requires; + PackageList requires; BuildInfo export_binfo; bool conf_done; diff --git a/source/packageref.cpp b/source/packageref.cpp deleted file mode 100644 index bfd0010..0000000 --- a/source/packageref.cpp +++ /dev/null @@ -1,30 +0,0 @@ -/* $Id$ - -This file is part of builder -Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions -Distributed under the LGPL -*/ - -#include "builder.h" -#include "package.h" -#include "packageref.h" - -using namespace std; - -PackageRef::PackageRef(Builder &b, const string &n): - builder(b), - name(n), - package(0) -{ } - -/** -Tries to get the package from Builder if we don't have it already. - -@return The package pointer (0 if the package was not found) -*/ -Package *PackageRef::resolve() -{ - if(!package) - package=builder.get_package(name); - return package; -} diff --git a/source/packageref.h b/source/packageref.h deleted file mode 100644 index 7d2f547..0000000 --- a/source/packageref.h +++ /dev/null @@ -1,34 +0,0 @@ -/* $Id$ - -This file is part of builder -Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions -Distributed under the LGPL -*/ - -#ifndef PACKAGEREF_H_ -#define PACKAGEREF_H_ - -#include -#include - -class Builder; -class Package; - -/** -A proxy class that stores a package name and possibly a pointer to the package. -*/ -class PackageRef -{ -public: - PackageRef(Builder &, const std::string &); - const std::string &get_name() const { return name; } - Package *get_package() const { return package; } - Package *resolve(); -private: - Builder &builder; - std::string name; - Package *package; -}; -typedef std::list PkgRefList; - -#endif diff --git a/source/pkgconfigaction.cpp b/source/pkgconfigaction.cpp index c390fbd..dfa4cba 100644 --- a/source/pkgconfigaction.cpp +++ b/source/pkgconfigaction.cpp @@ -33,10 +33,10 @@ PkgConfigAction::PkgConfigAction(Builder &b, const PkgConfig &p): out<<"Version: "<get_package()->get_use_pkgconfig()) - out<<' '<get_name(); + const PackageList &reqs=spkg.get_requires(); + for(PackageList::const_iterator i=reqs.begin(); i!=reqs.end(); ++i) + if((*i)->get_use_pkgconfig()) + out<<' '<<(*i)->get_name(); out<<'\n'; const BuildInfo &binfo=spkg.get_exported_binfo(); diff --git a/source/sourcepackage.cpp b/source/sourcepackage.cpp index 5d1d683..aaea4e6 100644 --- a/source/sourcepackage.cpp +++ b/source/sourcepackage.cpp @@ -75,36 +75,6 @@ LibMode SourcePackage::get_library_mode() const throw Exception("Unknown library mode"); } -/** -Tries to resolve all references to dependency packages. -*/ -void SourcePackage::resolve_refs() -{ - Package::resolve_refs(); - - for(PkgRefList::iterator i=requires.begin(); i!=requires.end(); ++i) - if(i->get_package()) - all_reqs.push_back(i->get_package()); - - for(ComponentList::iterator i=components.begin(); i!=components.end(); ++i) - { - i->resolve_refs(); - const PkgRefList &creqs=i->get_requires(); - for(PkgRefList::const_iterator j=creqs.begin(); j!=creqs.end(); ++j) - if(j->get_package()) - all_reqs.push_back(j->get_package()); - } - - for(ConditionList::iterator i=conditions.begin(); i!=conditions.end(); ++i) - { - i->resolve_refs(); - const PkgRefList &creqs=i->get_requires(); - for(PkgRefList::const_iterator j=creqs.begin(); j!=creqs.end(); ++j) - if(j->get_package()) - all_reqs.push_back(j->get_package()); - } -} - /*** private ***/ /** @@ -134,12 +104,20 @@ void SourcePackage::do_configure(const StringMap &opts, unsigned flag) for(ConditionList::iterator i=conditions.begin(); i!=conditions.end(); ++i) if(i->eval()) { - const PkgRefList &reqs=i->get_requires(); - requires.insert(requires.end(), reqs.begin(), reqs.end()); - build_info.add(i->get_build_info()); + const StringList &reqs=i->get_requires(); + for(StringList::const_iterator j=reqs.begin(); j!=reqs.end(); ++j) + requires.push_back(builder.get_package(*j)); } - for(PackageList::iterator i=all_reqs.begin(); i!=all_reqs.end(); ++i) + base_reqs=requires; + + for(ComponentList::iterator i=components.begin(); i!=components.end(); ++i) + { + const PackageList &reqs=i->get_requires(); + requires.insert(requires.end(), reqs.begin(), reqs.end()); + } + + for(PackageList::iterator i=requires.begin(); i!=requires.end(); ++i) { BinaryPackage *bpkg=dynamic_cast(*i); if(bpkg && bpkg->get_need_path()) @@ -148,8 +126,8 @@ void SourcePackage::do_configure(const StringMap &opts, unsigned flag) deps_cache.load(); - for(PackageList::iterator i=all_reqs.begin(); i!=all_reqs.end(); ++i) - (*i)->configure(opts, flag&2); + /*for(PackageList::iterator i=all_reqs.begin(); i!=all_reqs.end(); ++i) + (*i)->configure(opts, flag&2);*/ } /** @@ -182,7 +160,7 @@ void SourcePackage::init_config() for(FeatureList::iterator i=features.begin(); i!=features.end(); ++i) config.add_option("with_"+i->name, "0", i->descr); - for(PackageList::const_iterator i=all_reqs.begin(); i!=all_reqs.end(); ++i) + for(PackageList::const_iterator i=requires.begin(); i!=requires.end(); ++i) { BinaryPackage *bpkg=dynamic_cast(*i); if(bpkg && bpkg->get_need_path()) @@ -196,12 +174,9 @@ configured when this is called. */ void SourcePackage::create_build_info() { - for(PkgRefList::iterator i=requires.begin(); i!=requires.end(); ++i) + for(PackageList::iterator i=base_reqs.begin(); i!=base_reqs.end(); ++i) { - Package *pkg=i->get_package(); - if(!pkg) - continue; - const BuildInfo &ebi=pkg->get_exported_binfo(); + const BuildInfo &ebi=(*i)->get_exported_binfo(); build_info.add(ebi); export_binfo.cflags.insert(export_binfo.cflags.end(), ebi.cflags.begin(), ebi.cflags.end()); diff --git a/source/sourcepackage.h b/source/sourcepackage.h index f4a8e24..3e30790 100644 --- a/source/sourcepackage.h +++ b/source/sourcepackage.h @@ -16,7 +16,6 @@ Distributed under the LGPL #include "dependencycache.h" #include "feature.h" #include "package.h" -#include "packageref.h" class Builder; @@ -70,13 +69,12 @@ public: LibMode get_library_mode() const; const PathList &get_tar_files() const { return tar_files; } DependencyCache &get_deps_cache() const { return deps_cache; } - virtual void resolve_refs(); private: std::string version; std::string description; Msp::Path::Path source; - PackageList all_reqs; + PackageList base_reqs; FeatureList features; BuildInfo build_info; ConditionList conditions; -- 2.43.0