From: Mikko Rasa Date: Wed, 21 Dec 2022 09:52:11 +0000 (+0200) Subject: Track Android API levels with a bitmask X-Git-Url: http://git.tdb.fi/?p=builder.git;a=commitdiff_plain;h=82c7d6187fdaeaa1b9cfbd6637d9b047a78f17ec Track Android API levels with a bitmask --- diff --git a/source/androidtools.cpp b/source/androidtools.cpp index 5ef2bec..1633b8b 100644 --- a/source/androidtools.cpp +++ b/source/androidtools.cpp @@ -1,3 +1,4 @@ +#include #include #include #include @@ -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(p.substr(8))); + { + unsigned api = lexical_cast(p.substr(8)); + if(api>63) + builder.get_logger().log("problems", format("API level %d is too high", api)); + else + supported_api_levels |= 1< &sdk_api_levels = sdk.get_supported_api_levels(); - const set &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"); diff --git a/source/androidtools.h b/source/androidtools.h index bef95f8..b08691c 100644 --- a/source/androidtools.h +++ b/source/androidtools.h @@ -1,7 +1,7 @@ #ifndef ANDROIDTOOLS_H_ #define ANDROIDTOOLS_H_ -#include +#include #include #include "toolchain.h" @@ -13,14 +13,16 @@ class AndroidDevKit protected: Builder &builder; Msp::FS::Path root; - std::set supported_api_levels; + /* Needs refactoring if API levels go over 63. At present rate this will + take decades to occur. */ + uint64_t supported_api_levels; AndroidDevKit(Builder &, const std::string &, const Msp::FS::Path & = Msp::FS::Path()); ~AndroidDevKit() { } public: const Msp::FS::Path &get_root_dir() const { return root; } - const std::set &get_supported_api_levels() const { return supported_api_levels; } + uint64_t get_supported_api_levels() const { return supported_api_levels; } void select_api_level(unsigned); protected: virtual void init_api_level(unsigned) = 0;