]> git.tdb.fi Git - builder.git/commitdiff
Refactor code to get rid of class PackageRef
authorMikko Rasa <tdb@tdb.fi>
Mon, 10 Sep 2007 15:15:49 +0000 (15:15 +0000)
committerMikko Rasa <tdb@tdb.fi>
Mon, 10 Sep 2007 15:15:49 +0000 (15:15 +0000)
13 files changed:
source/builder.cpp
source/builder.h
source/component.cpp
source/component.h
source/condition.cpp
source/condition.h
source/package.cpp
source/package.h
source/packageref.cpp [deleted file]
source/packageref.h [deleted file]
source/pkgconfigaction.cpp
source/sourcepackage.cpp
source/sourcepackage.h

index f10f0eb9cb331eb41f32b2b053786366fdb19b2f..6ee210177f32a077935223d17203d924da9d45dd 100644 (file)
@@ -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<<i->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));
 }
 
 
index 879781df1cb7d989fa2f248b168c4a54f3644a80..6da42a1a90e94c55ca080157c3ae6fcdba1a31d2 100644 (file)
@@ -83,7 +83,6 @@ private:
        Msp::Path::Path cwd;
 
        PackageMap   packages;
-       PackageList  new_pkgs;
        SourcePackage *default_pkg;
 
        TargetMap    targets;
index 6272321b56b702b3b730c9ccca53618efab08078..e33867680fb420e927d7abe20f5b524fe737defd 100644 (file)
@@ -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()
index 387de4c5814e7bcd907ba5f9ee6b228a9131f0d9..8dec23912f41d5ef8f6c067d932a11851bb5d2cd 100644 (file)
@@ -13,7 +13,7 @@ Distributed under the LGPL
 #include <msp/path/path.h>
 #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;
index c4c01b21fbdf692fc92cb4fe147a4ad58b969a86..4b45dca51f2eeaf06a13880d2c214b3fe557d594 100644 (file)
@@ -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()
index 433c0c8ee431dd8f4d81e8d25d4233a1f6bd2b48..2f3a5ef9888a67a0f978f0944eb956d5261620b9 100644 (file)
@@ -11,7 +11,6 @@ Distributed under the LGPL
 #include <msp/datafile/loader.h>
 #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<Condition> ConditionList;
index 23a8d9c8e6c73a0b592d0d0de5849419d1df0b0b..20fec32acfb84d64665ff2c05372482761de3eb2 100644 (file)
@@ -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);
 }
index f8ef7451d6c59fed1bd6ac316cd407b86c5d3161..a2563bf3004d36027a6e5c37611a75dad545bb13 100644 (file)
@@ -12,7 +12,6 @@ Distributed under the LGPL
 #include <string>
 #include <msp/datafile/loader.h>
 #include "buildinfo.h"
-#include "packageref.h"
 
 class Builder;
 class Package;
@@ -20,9 +19,9 @@ class Package;
 typedef std::list<Package *> 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 (file)
index bfd0010..0000000
+++ /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 (file)
index 7d2f547..0000000
+++ /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 <list>
-#include <string>
-
-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<PackageRef> PkgRefList;
-
-#endif
index c390fbd0e0a47dd45ee1e72995513411914e4866..dfa4cba113eae4a0dae492a8c1bdf8c038778699 100644 (file)
@@ -33,10 +33,10 @@ PkgConfigAction::PkgConfigAction(Builder &b, const PkgConfig &p):
                out<<"Version: "<<spkg.get_version()<<'\n';
 
                out<<"Requires:";
-               const PkgRefList &reqs=spkg.get_requires();
-               for(PkgRefList::const_iterator i=reqs.begin(); i!=reqs.end(); ++i)
-                       if(i->get_package()->get_use_pkgconfig())
-                               out<<' '<<i->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();
index 5d1d6837ed5e903a07dc6423d28154ad442a7cc4..aaea4e68c3002428bfd937778a7e694f601bcaf9 100644 (file)
@@ -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<BinaryPackage *>(*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<BinaryPackage *>(*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());
index f4a8e242adb69bb1f63b2caec1b736d822a8fdb3..3e30790c5f7192e63039eae1464ab29f63f739be 100644 (file)
@@ -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;