]> git.tdb.fi Git - builder.git/commitdiff
Have Architecture provide pattern lists for library and executable filenames
authorMikko Rasa <tdb@tdb.fi>
Fri, 4 May 2012 18:10:47 +0000 (21:10 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sun, 8 Jul 2012 21:08:50 +0000 (00:08 +0300)
source/architecture.cpp
source/architecture.h
source/pattern.cpp [new file with mode: 0644]
source/pattern.h [new file with mode: 0644]
source/virtualfilesystem.cpp
source/virtualfilesystem.h

index e0b69667952c64c1ad2e70229e5c4e951a128d7f..8e618deb4ae9de2c78e3d1ec8e169f829652c8c3 100644 (file)
@@ -105,6 +105,21 @@ Architecture::Architecture(Builder &b, const string &spec):
        if(!cpu.empty())
                name += format("-%s", cpu);
        name += format("-%d-%s", bits, system);
+
+       if(system=="windows")
+       {
+               sharedlib_patterns.push_back(Pattern("%.dll"));
+               sharedlib_patterns.push_back(Pattern("lib%.dll"));
+               staticlib_patterns.push_back(Pattern("lib%.a"));
+               staticlib_patterns.push_back(Pattern("lib%.dll.a"));
+               executable_patterns.push_back(Pattern("%.exe"));
+       }
+       else
+       {
+               sharedlib_patterns.push_back(Pattern("lib%.so"));
+               staticlib_patterns.push_back(Pattern("lib%.a"));
+               executable_patterns.push_back(Pattern("%"));
+       }
 }
 
 void Architecture::set_tool(const string &t, const string &p)
index 1f643dc325b4a1512170d95b50b22871b84de5bd..3ea13a06b0a67d2806140c48276590ecb8f04ad9 100644 (file)
@@ -4,6 +4,7 @@
 #include <msp/datafile/loader.h>
 #include "buildinfo.h"
 #include "misc.h"
+#include "pattern.h"
 
 class Builder;
 
@@ -23,6 +24,8 @@ public:
                void tool(const std::string &t, const std::string &p);
        };
 
+       typedef std::list<Pattern> PatternList;
+
 private:
        Builder &builder;
        std::string type;
@@ -33,6 +36,9 @@ private:
        bool native;
        std::string cross_prefix;
        StringMap tools;
+       PatternList sharedlib_patterns;
+       PatternList staticlib_patterns;
+       PatternList executable_patterns;
 
 public:
        Architecture(Builder &b, const std::string &spec);
@@ -49,6 +55,10 @@ public:
        std::string get_tool(const std::string &t) const;
        const std::string &get_cross_prefix() const { return cross_prefix; }
 
+       const PatternList &get_shared_library_patterns() const { return sharedlib_patterns; }
+       const PatternList &get_static_library_patterns() const { return staticlib_patterns; }
+       const PatternList &get_executable_patterns() const { return executable_patterns; }
+
 private:
        std::string resolve_alias(const std::string &) const;
        void parse_specification(const std::string &);
diff --git a/source/pattern.cpp b/source/pattern.cpp
new file mode 100644 (file)
index 0000000..e87981f
--- /dev/null
@@ -0,0 +1,18 @@
+#include <stdexcept>
+#include "pattern.h"
+
+using namespace std;
+
+Pattern::Pattern(const string &pat)
+{
+       string::size_type percent = pat.find('%');
+       if(percent==string::npos)
+               throw invalid_argument("No percent sign in pattern");
+       prefix = pat.substr(0, percent);
+       suffix = pat.substr(percent+1);
+}
+
+string Pattern::apply(const string &body) const
+{
+       return prefix+body+suffix;
+}
diff --git a/source/pattern.h b/source/pattern.h
new file mode 100644 (file)
index 0000000..de8e7b2
--- /dev/null
@@ -0,0 +1,18 @@
+#ifndef PATTERN_H_
+#define PATTERN_H_
+
+#include <string>
+
+class Pattern
+{
+private:
+       std::string prefix;
+       std::string suffix;
+
+public:
+       Pattern(const std::string &);
+
+       std::string apply(const std::string &) const;
+};
+
+#endif
index be646cdbb9c494afab313bd46ef56fb5add140d3..ef7605b14b929fc8cbb4eea0f87a66ab48f89201 100644 (file)
@@ -163,22 +163,11 @@ FileTarget *VirtualFileSystem::get_library(const string &lib, const FS::Path &pa
 
        const Architecture &arch = builder.get_current_arch();
        if(mode!=ALL_STATIC)
-       {
-               // XXX Should probably let the Architecture populate the list
-               if(arch.get_system()=="windows")
-               {
-                       candidates.push_back("lib"+lib+".dll");
-                       candidates.push_back(lib+".dll");
-               }
-               else
-                       candidates.push_back("lib"+lib+".so");
-       }
+               fill_candidates(candidates, arch.get_shared_library_patterns(), lib);
 
        /* Static libraries are always considered, since sometimes shared versions
        may not be available */
-       candidates.push_back("lib"+lib+".a");
-       if(arch.get_system()=="windows")
-               candidates.push_back("lib"+lib+".dll.a");
+       fill_candidates(candidates, arch.get_static_library_patterns(), lib);
 
        for(StringList::iterator i=candidates.begin(); i!=candidates.end(); ++i)
        {
@@ -205,3 +194,9 @@ FileTarget *VirtualFileSystem::get_library(const string &lib, const FS::Path &pa
 
        return 0;
 }
+
+void VirtualFileSystem::fill_candidates(StringList &candidates, const list<Pattern> &patterns, const string &base)
+{
+       for(list<Pattern>::const_iterator i=patterns.begin(); i!=patterns.end(); ++i)
+               candidates.push_back(i->apply(base));
+}
index 16f8c6d9e7e2a3e0bfafd3fb5a7f9a01c0828d62..5ecc04b414f04f15ea059c48af19470312dfc4a8 100644 (file)
@@ -7,6 +7,7 @@
 
 class Builder;
 class FileTarget;
+class Pattern;
 
 class VirtualFileSystem
 {
@@ -50,6 +51,8 @@ private:
        FileTarget *get_header(const Msp::FS::Path &);
 
        FileTarget *get_library(const std::string &, const Msp::FS::Path &, LibMode);
+
+       void fill_candidates(std::list<std::string> &, const std::list<Pattern> &, const std::string &);
 };
 
 #endif