]> git.tdb.fi Git - builder.git/blobdiff - source/androidtools.cpp
Track Android API levels with a bitmask
[builder.git] / source / androidtools.cpp
index 5ef2bec5f23b40ec3ff31a58be99d3d1189ece0e..1633b8b6465dd575acd0676536969a7b9d027af1 100644 (file)
@@ -1,3 +1,4 @@
+#include <msp/core/algorithm.h>
 #include <msp/core/environ.h>
 #include <msp/fs/dir.h>
 #include <msp/fs/stat.h>
@@ -53,13 +54,20 @@ AndroidDevKit::AndroidDevKit(Builder &b, const string &type, const FS::Path &def
                return;
 
        builder.get_logger().log("files", format("Traversing %s", platforms_dir.str()));
+       supported_api_levels = 0;
        for(const string &p: list_filtered(platforms_dir, "^android-[1-9][0-9]*$"))
-               supported_api_levels.insert(lexical_cast<unsigned>(p.substr(8)));
+       {
+               unsigned api = lexical_cast<unsigned>(p.substr(8));
+               if(api>63)
+                       builder.get_logger().log("problems", format("API level %d is too high", api));
+               else
+                       supported_api_levels |= 1<<api;
+       }
 }
 
 void AndroidDevKit::select_api_level(unsigned api)
 {
-       if(!supported_api_levels.count(api))
+       if(!(supported_api_levels&(1<<api)))
                throw invalid_argument("AndroidDevKit::select_api_level");
 
        init_api_level(api);
@@ -219,17 +227,14 @@ AndroidTools::AndroidTools(Builder &builder, const Architecture &arch):
        sdk(builder),
        ndk(builder, arch, sdk)
 {
-       const set<unsigned> &sdk_api_levels = sdk.get_supported_api_levels();
-       const set<unsigned> &ndk_api_levels = ndk.get_supported_api_levels();
-       unsigned highest_common = 0;
-       for(auto i=sdk_api_levels.rbegin(); (!highest_common && i!=sdk_api_levels.rend()); ++i)
-               if(ndk_api_levels.count(*i))
-                       highest_common = *i;
-
-       if(highest_common)
+       if(uint64_t common_api_levels = sdk.get_supported_api_levels()&ndk.get_supported_api_levels())
        {
-               sdk.select_api_level(highest_common);
-               ndk.select_api_level(highest_common);
+               unsigned api = 0;
+               for(unsigned i=32; i>0; i>>=1)
+                       api += i*!!(common_api_levels>>(api+i));
+               builder.get_logger().log("tools", format("Using Android API level %d", api));
+               sdk.select_api_level(api);
+               ndk.select_api_level(api);
        }
        else
                builder.get_logger().log("problems", "No usable Android platforms found");