+#include <msp/core/algorithm.h>
#include <msp/core/environ.h>
#include <msp/fs/dir.h>
#include <msp/fs/stat.h>
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);
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");
#ifndef ANDROIDTOOLS_H_
#define ANDROIDTOOLS_H_
-#include <set>
+#include <cstdint>
#include <msp/fs/path.h>
#include "toolchain.h"
protected:
Builder &builder;
Msp::FS::Path root;
- std::set<unsigned> 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<unsigned> &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;