]> git.tdb.fi Git - builder.git/commitdiff
Introduce a helper function in Architecture to pick the best matching name
authorMikko Rasa <tdb@tdb.fi>
Fri, 10 Oct 2014 09:59:58 +0000 (12:59 +0300)
committerMikko Rasa <tdb@tdb.fi>
Fri, 10 Oct 2014 10:03:31 +0000 (13:03 +0300)
source/androidtools.cpp
source/architecture.cpp
source/architecture.h

index c0fe6d1557e5f3b9beb92f510d60e7e9b86eaf28..1042595fd9423802006136791e0ab9cf0587f40a 100644 (file)
@@ -75,14 +75,8 @@ void AndroidNdk::find_toolchain_dir()
 
        const Architecture &native_arch = builder.get_native_arch();
 
-       list<string> tc_archs = list_files(toolchains_dir/use_toolchain/"prebuilt");
-       string use_arch;
-       for(list<string>::const_iterator i=tc_archs.begin(); i!=tc_archs.end(); ++i)
-               if(native_arch.match_name(*i))
-               {
-                       use_arch = *i;
-                       break;
-               }
+       FS::Path tc_archs_dir = toolchains_dir/use_toolchain/"prebuilt";
+       string use_arch = native_arch.best_match(list_files(tc_archs_dir));
 
        if(use_arch.empty())
                throw runtime_error("No matching toolchain found");
@@ -111,14 +105,10 @@ void AndroidNdk::find_platform_dir()
        if(use_platform.empty())
                throw runtime_error("No applicable platforms found");
 
-       list<string> platform_archs = list_files(platforms_dir/use_platform);
-       string use_arch;
-       for(list<string>::const_iterator i=platform_archs.begin(); i!=platform_archs.end(); ++i)
-               if(!i->compare(0, 5, "arch-") && architecture.match_name(i->substr(5)))
-               {
-                       use_arch = *i;
-                       break;
-               }
+       list<string> platform_archs = list_filtered(platforms_dir/use_platform, "^arch-");
+       for(list<string>::iterator i=platform_archs.begin(); i!=platform_archs.end(); ++i)
+               i->erase(0, 5);
+       string use_arch = architecture.best_match(platform_archs);
 
        if(use_arch.empty())
                throw runtime_error("No matching platform found");
index a9434986a91170a3de3ef4c7e6462b7b2ee1c911..ac31abdc30428307fd46278a44508b1222872dfb 100644 (file)
@@ -154,6 +154,30 @@ bool Architecture::match_name(const string &pattern) const
        return !negate;
 }
 
+string Architecture::best_match(const list<string> &names) const
+{
+       string best;
+       unsigned best_size = 0;
+       for(list<string>::const_iterator i=names.begin(); i!=names.end(); ++i)
+               if(match_name(*i))
+               {
+                       /* TODO Do full parse and alias resolution here?  Otherwise x86 and
+                       x86_64 are treated as equally good, even though the latter is more
+                       specific. */
+                       unsigned size = 1;
+                       for(string::const_iterator j=i->begin(); j!=i->end(); ++j)
+                               size += (*j=='-');
+
+                       if(size>best_size)
+                       {
+                               best = *i;
+                               best_size = size;
+                       }
+               }
+
+       return best;
+}
+
 void Architecture::resolve_aliases(vector<string> &parts)
 {
        for(unsigned i=0; i<parts.size(); ++i)
index d84173e67029f2bcd7a74a230dc6a7ee388dd090..69a6ec9d49d40dc0524c05e8e8afd23223b4a25b 100644 (file)
@@ -44,6 +44,7 @@ public:
        unsigned get_bits() const { return bits; }
        const std::string &get_cpu() const { return cpu; }
        bool match_name(const std::string &) const;
+       std::string best_match(const std::list<std::string> &) const;
        bool is_native() const { return native; }
        bool is_cross() const { return !cross_prefix.empty(); }