#include <cstdlib>
#include <msp/fs/dir.h>
+#include <msp/fs/stat.h>
#include <msp/strings/format.h>
#include <msp/strings/lexicalcast.h>
#include <msp/strings/utils.h>
if(const char *value = getenv(var.c_str()))
root = value;
else
- throw runtime_error(var+" must be set");
+ {
+ builder.get_logger().log("problems", format("Android %s not found", type));
+ return;
+ }
FS::Path platforms_dir = root/"platforms";
+ if(!FS::exists(platforms_dir))
+ return;
+
builder.get_logger().log("files", format("Traversing %s", platforms_dir.str()));
list<string> platforms = list_filtered(platforms_dir, "^android-[1-9][0-9]*$");
void AndroidSdk::find_build_tools_dir()
{
FS::Path bt_dir = root/"build-tools";
+ if(!FS::exists(bt_dir))
+ {
+ builder.get_logger().log("problems", "Android build-tools not found");
+ return;
+ }
+
builder.get_logger().log("files", format("Traversing %s", bt_dir.str()));
list<string> tool_versions = list_files(bt_dir);
}
if(use_tools.empty())
- throw runtime_error("No build tools found");
+ {
+ builder.get_logger().log("problems", "Android build-tools not found");
+ return;
+ }
build_tools_dir = bt_dir/use_tools;
- builder.get_logger().log("tools", format("Android build tools are in %s", build_tools_dir.str()));
+ builder.get_logger().log("tools", format("Android build-tools found in %s", build_tools_dir.str()));
}
void AndroidSdk::init_api_level(unsigned api)
{
- if(!supported_api_levels.count(api))
- throw invalid_argument("AndroidSdk::select_api_level");
-
platform_jar = root/"platforms"/format("android-%d", api)/"android.jar";
}
void AndroidNdk::find_toolchain_dir()
{
+ if(root.empty())
+ return;
+
FS::Path toolchains_dir = root/"toolchains";
+ if(!FS::exists(toolchains_dir))
+ {
+ builder.get_logger().log("problems", "Android NDK toolchains not found");
+ return;
+ }
+
builder.get_logger().log("files", format("Traversing %s", toolchains_dir.str()));
string prefix = architecture.get_cross_prefix()+"-";
list<string> toolchains = list_filtered(toolchains_dir, "^"+prefix);
}
if(use_toolchain.empty())
- throw runtime_error("No applicable toolchains found");
+ {
+ builder.get_logger().log("problems", "No applicable Android NDK toolchains found");
+ return;
+ }
const Architecture &native_arch = builder.get_native_arch();
string use_arch = native_arch.best_match(list_files(tc_archs_dir));
if(use_arch.empty())
- throw runtime_error("No matching toolchain found");
+ {
+ builder.get_logger().log("problems", "No applicable Android NDK toolchains found");
+ return;
+ }
bin_dir = toolchains_dir/use_toolchain/"prebuilt"/use_arch/"bin";
- builder.get_logger().log("tools", format("Android toolchain binaries are in %s", bin_dir.str()));
+ builder.get_logger().log("tools", format("Android NDK toolchain binaries found in %s", bin_dir.str()));
}
void AndroidNdk::init_api_level(unsigned api)
{
- if(!supported_api_levels.count(api))
- throw invalid_argument("AndroidSdk::select_api_level");
-
FS::Path platform_archs_dir = root/"platforms"/format("android-%d", api);
builder.get_logger().log("files", format("Traversing %s", platform_archs_dir.str()));
list<string> platform_archs = list_filtered(platform_archs_dir, "^arch-");
string use_arch = architecture.best_match(platform_archs);
if(use_arch.empty())
- throw runtime_error("No matching platform found");
+ {
+ builder.get_logger().log("problems", "No matching Android NDK platform found");
+ return;
+ }
platform_sysroot = platform_archs_dir/("arch-"+use_arch);
builder.get_logger().log("tools", format("Android NDK sysroot is %s", platform_sysroot.str()));
if(ndk_api_levels.count(*i))
highest_common = *i;
- if(!highest_common)
- throw runtime_error("No usable Android platforms found");
-
- sdk.select_api_level(highest_common);
- ndk.select_api_level(highest_common);
+ if(highest_common)
+ {
+ sdk.select_api_level(highest_common);
+ ndk.select_api_level(highest_common);
+ }
+ else
+ builder.get_logger().log("problems", "No usable Android platforms found");
add_tool(new AndroidCompiler(builder, arch, "CC", ndk));
add_tool(new AndroidCompiler(builder, arch, "CXX", ndk));