]> git.tdb.fi Git - builder.git/commitdiff
Move architecture information from Builder to class Architecture
authorMikko Rasa <tdb@tdb.fi>
Tue, 11 Sep 2007 18:36:03 +0000 (18:36 +0000)
committerMikko Rasa <tdb@tdb.fi>
Tue, 11 Sep 2007 18:36:03 +0000 (18:36 +0000)
Add problem.h

builderrc
source/architecture.cpp [new file with mode: 0644]
source/architecture.h [new file with mode: 0644]
source/archive.cpp
source/builder.cpp
source/builder.h
source/compile.cpp
source/link.cpp
source/problem.h [new file with mode: 0644]

index 6170aecba737c150cfccde5f06710fe8959b4e47..a39a8777c32c44d302a51f099b687998143a2da7 100644 (file)
--- a/builderrc
+++ b/builderrc
@@ -1,3 +1,5 @@
+/* $Id$ */
+
 binary_package "opengl"
 {
        build_info
@@ -41,8 +43,15 @@ binary_package "xlib"
        };
 };
 
-architecture "arm" "arm-linux-gnu";
-architecture "win32" "i586-mingw32msvc";
+architecture "arm"
+{
+       prefix "arm-linux-gnu";
+};
+
+architecture "win32"
+{
+       prefix "i586-mingw32msvc";
+};
 
 profile "debug"
 {
diff --git a/source/architecture.cpp b/source/architecture.cpp
new file mode 100644 (file)
index 0000000..50013e8
--- /dev/null
@@ -0,0 +1,55 @@
+/* $Id$
+
+This file is part of builder
+Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions
+Distributed under the LGPL
+*/
+
+#include "architecture.h"
+#include "builder.h"
+
+using namespace std;
+using namespace Msp;
+
+Architecture::Architecture(Builder &b, const string &n):
+       builder(b),
+       name(n)
+{ }
+
+void Architecture::set_tool(const string &t, const string &p)
+{
+       tools[t]=p;
+}
+
+std::string Architecture::get_tool(const string &t) const
+{
+       StringMap::const_iterator i=tools.find(t);
+       if(i!=tools.end())
+       {
+               if(i->second[0]=='-')
+                       return prefix+i->second;
+               else
+                       return i->second;
+       }
+
+       if(name!="native")
+       {
+               const Architecture &native=builder.get_architecture("native");
+               return prefix+"-"+native.get_tool(t);
+       }
+       else
+               throw KeyError("Unknown tool");
+}
+
+
+Architecture::Loader::Loader(Architecture &a):
+       arch(a)
+{
+       add("prefix", &Architecture::prefix);
+       add("tool",   &Loader::tool);
+}
+
+void Architecture::Loader::tool(const string &t, const string &p)
+{
+       arch.tools[t]=p;
+}
diff --git a/source/architecture.h b/source/architecture.h
new file mode 100644 (file)
index 0000000..16ff505
--- /dev/null
@@ -0,0 +1,43 @@
+/* $Id$
+
+This file is part of builder
+Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions
+Distributed under the LGPL
+*/
+
+#ifndef ARCHITECTURE_H_
+#define ARCHITECTURE_H_
+
+#include <msp/datafile/loader.h>
+#include "misc.h"
+
+class Builder;
+
+class Architecture
+{
+public:
+       class Loader: public Msp::DataFile::Loader
+       {
+       public:
+               Loader(Architecture &);
+               Architecture &get_object() { return arch; }
+       private:
+               Architecture &arch;
+
+               void tool(const std::string &t, const std::string &p);
+       };
+
+       Architecture(Builder &b, const std::string &n);
+       void set_tool(const std::string &t, const std::string &p);
+       std::string get_tool(const std::string &t) const;
+       const std::string &get_prefix() const { return prefix; }
+private:
+       Builder     &builder;
+       std::string name;
+       std::string prefix;
+       StringMap   tools;
+};
+
+typedef std::map<std::string, Architecture> ArchMap;
+
+#endif
index 4dee50899f123ad580b5f3f66997527446442fec..a7b86c7cc4b945769fc82f404ea0f8de61ee799a 100644 (file)
@@ -21,7 +21,8 @@ Archive::Archive(Builder &b, const StaticLibrary &lib):
 {
        const Component &comp=lib.get_component();
 
-       argv.push_back(builder.get_tool("AR", comp.get_package().get_arch()));
+       std::string tool="AR";
+       argv.push_back(builder.get_architecture(comp.get_package().get_arch()).get_tool(tool));
        argv.push_back("rc");
 
        argv.push_back(lib.get_name());
@@ -34,7 +35,7 @@ Archive::Archive(Builder &b, const StaticLibrary &lib):
        if(!builder.get_dry_run())
                Path::mkpath(lpath.subpath(0, lpath.size()-1), 0755);
 
-       announce(comp.get_package().get_name(), "AR  ", relative(lpath, comp.get_package().get_source()).str());
+       announce(comp.get_package().get_name(), tool, relative(lpath, comp.get_package().get_source()).str());
 
        launch();
 }
index d4669520abd93fd7aabaf4b9b1ba7cf2bfc690ac..ee7eabfd1c9e93ff3913f510fb8e0ee09563cc7d 100644 (file)
@@ -115,14 +115,12 @@ Builder::Builder(int argc, char **argv):
 
        cwd=Path::getcwd();
 
-       archs.insert(StringMap::value_type("native", ""));
-
-       StringMap &native_tools=tools.insert(ToolMap::value_type("native", StringMap())).first->second;
-       native_tools.insert(StringMap::value_type("CC",   "gcc"));
-       native_tools.insert(StringMap::value_type("CXX",  "g++"));
-       native_tools.insert(StringMap::value_type("LD",   "gcc"));
-       native_tools.insert(StringMap::value_type("LDXX", "g++"));
-       native_tools.insert(StringMap::value_type("AR",   "ar"));
+       Architecture &native_arch=archs.insert(ArchMap::value_type("native", Architecture(*this, "native"))).first->second;
+       native_arch.set_tool("CC",  "gcc");
+       native_arch.set_tool("CXX", "g++");
+       native_arch.set_tool("LD",  "gcc");
+       native_arch.set_tool("LXX", "g++");
+       native_arch.set_tool("AR",  "ar");
 
        const char *home=getenv("HOME");
        if(home)
@@ -260,7 +258,7 @@ Target *Builder::get_library(const string &lib, const string &arch, const list<s
                syspath.push_back("/usr/lib");
        }
        else
-               syspath.push_back("/usr/"+get_arch_prefix(arch)+"/lib");
+               syspath.push_back("/usr/"+get_architecture(arch).get_prefix()+"/lib");
 
        Target *tgt=0;
        for(StringList::iterator j=syspath.begin(); (!tgt && j!=syspath.end()); ++j)
@@ -273,34 +271,15 @@ Target *Builder::get_library(const string &lib, const string &arch, const list<s
        return tgt;
 }
 
-const string &Builder::get_arch_prefix(const string &arch) const
+const Architecture &Builder::get_architecture(const string &arch) const
 {
-       StringMap::const_iterator i=archs.find(arch);
+       ArchMap::const_iterator i=archs.find(arch);
        if(i==archs.end())
                throw InvalidParameterValue("Unknown architecture");
 
        return i->second;
 }
 
-string Builder::get_tool(const std::string &tool, const std::string &arch)
-{
-       ToolMap::iterator i=tools.find(arch);
-       if(i!=tools.end())
-       {
-               StringMap::iterator j=i->second.find(tool);
-               if(j!=i->second.end())
-                       return j->second;
-       }
-
-       // Either the arch, or the tool within the arch was not found
-       i=tools.find("native");
-       StringMap::iterator j=i->second.find(tool);
-       if(j==i->second.end())
-               throw InvalidParameterValue("Unknown tool");
-
-       return get_arch_prefix(arch)+"-"+j->second;
-}
-
 void Builder::apply_profile_template(Config &config, const string &pt) const
 {
        vector<string> parts=split(pt, '-');
@@ -800,9 +779,11 @@ Builder::Loader::Loader(Builder &b, const Path::Path &s):
        add("package", &Loader::package);
 }
 
-void Builder::Loader::architecture(const string &a, const string &p)
+void Builder::Loader::architecture(const string &n)
 {
-       bld.archs.insert(StringMap::value_type(a, p));
+       Architecture arch(bld, n);
+       load_sub(arch);
+       bld.archs.insert(ArchMap::value_type(n, arch));
 }
 
 void Builder::Loader::binpkg(const string &n)
index 4811493e005e649dcaeba5f24c89f976a880454d..270f8162d7af543acf1b6b694d0ba968f034963b 100644 (file)
@@ -14,6 +14,7 @@ Distributed under the LGPL
 #include <msp/core/application.h>
 #include <msp/datafile/loader.h>
 #include <msp/path/path.h>
+#include "architecture.h"
 #include "config.h"
 #include "misc.h"
 #include "problem.h"
@@ -41,8 +42,7 @@ public:
        Target   *get_header(const std::string &, const std::string &, const std::string &, const StringList &);
        Target   *get_library(const std::string &, const std::string &, const StringList &, LibMode);
        const Msp::Path::Path &get_cwd() const { return cwd; }
-       const std::string &get_arch_prefix(const std::string &) const;
-       std::string get_tool(const std::string &, const std::string &);
+       const Architecture &get_architecture(const std::string &) const;
        void     apply_profile_template(Config &, const std::string &) const;
        void     add_target(Target *);
        void     problem(const std::string &, const std::string &);
@@ -59,7 +59,7 @@ private:
                Builder         &bld;
                Msp::Path::Path src;
 
-               void architecture(const std::string &, const std::string &);
+               void architecture(const std::string &);
                void binpkg(const std::string &);
                void profile(const std::string &);
                void package(const std::string &);
@@ -77,7 +77,6 @@ private:
 
        typedef std::list<Package *>               PackageList;
        typedef std::map<std::string, Package *>   PackageMap;
-       typedef std::map<std::string, StringMap>   ToolMap;
        typedef std::map<std::string, StringMap>   ProfileTemplateMap;
 
        StringList   cmdline_targets;
@@ -92,8 +91,7 @@ private:
        TargetMap    includes;
        TargetMap    libraries;
 
-       ToolMap      tools;    //< arch, tool name -> program name
-       StringMap    archs;    //< arch -> prefix
+       ArchMap      archs;
        ProfileTemplateMap profile_tmpl;
 
        ProblemList     problems;
index d07f3ef4ee3255cbef1d1299a72c13dffad8db00..61b17ad90807c65b0c85c649fbabe7c31a5cc6cc 100644 (file)
@@ -31,9 +31,9 @@ Compile::Compile(Builder &b, const ObjectFile &obj):
        else
                tool="CC";
 
-       argv.push_back(builder.get_tool(tool, comp.get_package().get_arch()));
+       argv.push_back(builder.get_architecture(comp.get_package().get_arch()).get_tool(tool));
        argv.push_back("-c");
-       
+
        const BuildInfo &binfo=comp.get_build_info();
        for(list<string>::const_iterator i=binfo.cflags.begin(); i!=binfo.cflags.end(); ++i)
                argv.push_back(*i);
@@ -41,7 +41,7 @@ Compile::Compile(Builder &b, const ObjectFile &obj):
                argv.push_back("-I"+*i);
        for(list<string>::const_iterator i=binfo.defines.begin(); i!=binfo.defines.end(); ++i)
                argv.push_back("-D"+*i);
-       
+
        Path::Path opath=obj.get_name();
        argv.push_back("-o");
        argv.push_back(opath.str());
index a7ea2c55df4374fc1149fedc0b4eaf4dc922785b..88ee97a8595e1c5668f2e712b150ae6c895271ac 100644 (file)
@@ -26,8 +26,9 @@ Link::Link(Builder &b, const Executable &exe):
        const Component &comp=exe.get_component();
 
        //XXX Determine whether to use g++ or gcc
-       argv.push_back(builder.get_tool("LDXX", comp.get_package().get_arch()));
-       
+       string tool="LXX";
+       argv.push_back(builder.get_architecture(comp.get_package().get_arch()).get_tool(tool));
+
        if(comp.get_type()==Component::LIBRARY || comp.get_type()==Component::MODULE)
                argv.push_back("-shared");
        else if(comp.get_package().get_library_mode()==ALL_STATIC)
@@ -38,7 +39,7 @@ Link::Link(Builder &b, const Executable &exe):
                argv.push_back(*i);
        for(list<string>::const_iterator i=binfo.libpath.begin(); i!=binfo.libpath.end(); ++i)
                argv.push_back("-L"+*i);
-       
+
        argv.push_back("-o");
        argv.push_back(exe.get_name());
        const TargetList &deps=exe.get_depends();
@@ -62,7 +63,7 @@ Link::Link(Builder &b, const Executable &exe):
        if(!builder.get_dry_run())
                Path::mkpath(epath.subpath(0, epath.size()-1), 0755);
 
-       announce(comp.get_package().get_name(), "LINK", relative(epath, comp.get_package().get_source()).str());
+       announce(comp.get_package().get_name(), tool, relative(epath, comp.get_package().get_source()).str());
 
        launch();
 }
diff --git a/source/problem.h b/source/problem.h
new file mode 100644 (file)
index 0000000..c2af878
--- /dev/null
@@ -0,0 +1,26 @@
+/* $Id$
+
+This file is part of builder
+Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions
+Distributed under the LGPL
+*/
+
+#ifndef PROBLEM_H_
+#define PROBLEM_H_
+
+#include <list>
+#include <string>
+
+class Package;
+
+struct Problem
+{
+       std::string package;
+       std::string descr;
+
+       Problem(const std::string &p, const std::string &d): package(p), descr(d) { }
+};
+
+typedef std::list<Problem> ProblemList;
+
+#endif