From 266697cea92aed098fff31c1ddd4a4bfab3a683f Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sat, 2 Dec 2017 23:31:24 +0200 Subject: [PATCH] Improve problem reporting for the Android toolchain Rather than throwing exceptions with cryptic messages, add the problems to the tools' problem lists. --- source/androidarchiver.cpp | 7 ++- source/androidassetpackagingtool.cpp | 10 ++++- source/androidcompiler.cpp | 11 ++++- source/androidtools.cpp | 66 ++++++++++++++++++++-------- 4 files changed, 73 insertions(+), 21 deletions(-) diff --git a/source/androidarchiver.cpp b/source/androidarchiver.cpp index 71bc5ff..58cbefa 100644 --- a/source/androidarchiver.cpp +++ b/source/androidarchiver.cpp @@ -4,5 +4,10 @@ AndroidArchiver::AndroidArchiver(Builder &b, const Architecture &a, const AndroidNdk &ndk): GnuArchiver(b, a) { - set_command((ndk.get_bin_dir()/command).str()); + if(ndk.get_root_dir().empty()) + problems.push_back("Android NDK not found"); + else if(ndk.get_bin_dir().empty()) + problems.push_back("Android NDK toolchain not found"); + else + set_command((ndk.get_bin_dir()/command).str()); } diff --git a/source/androidassetpackagingtool.cpp b/source/androidassetpackagingtool.cpp index cca30b8..9e0fef7 100644 --- a/source/androidassetpackagingtool.cpp +++ b/source/androidassetpackagingtool.cpp @@ -14,7 +14,15 @@ AndroidAssetPackagingTool::AndroidAssetPackagingTool(Builder &b, const AndroidSd Tool(b, "AAPT"), sdk(s) { - set_command((sdk.get_build_tools_dir()/"aapt").str()); + if(sdk.get_root_dir().empty()) + problems.push_back("Android SDK not found"); + else if(sdk.get_build_tools_dir().empty()) + problems.push_back("Android build-tools not found"); + else + set_command((sdk.get_build_tools_dir()/"aapt").str()); + + if(sdk.get_platform_jar().empty()) + problems.push_back("Android platform not found"); } Target *AndroidAssetPackagingTool::create_target(const list &sources, const string &) diff --git a/source/androidcompiler.cpp b/source/androidcompiler.cpp index 3616cf4..01daa2a 100644 --- a/source/androidcompiler.cpp +++ b/source/androidcompiler.cpp @@ -16,7 +16,16 @@ AndroidCompiler::AndroidCompiler(Builder &b, const Architecture &a, const string GnuCompiler(b, a, t, n.get_platform_sysroot()), ndk(n) { - set_command((ndk.get_bin_dir()/command).str()); + if(ndk.get_root_dir().empty()) + problems.push_back("Android NDK not found"); + else if(ndk.get_bin_dir().empty()) + problems.push_back("Android NDK toolchain not found"); + else + set_command((ndk.get_bin_dir()/command).str()); + + if(ndk.get_platform_sysroot().empty()) + problems.push_back("Android platform not found"); + build_info.incpath.insert(build_info.incpath.end(), system_path.begin(), system_path.end()); if(tag=="CXX") build_info.libs.push_back("gnustl_static"); diff --git a/source/androidtools.cpp b/source/androidtools.cpp index 809da7d..22a893e 100644 --- a/source/androidtools.cpp +++ b/source/androidtools.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include #include @@ -38,9 +39,15 @@ AndroidDevKit::AndroidDevKit(Builder &b, const string &type): 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 platforms = list_filtered(platforms_dir, "^android-[1-9][0-9]*$"); @@ -66,6 +73,12 @@ AndroidSdk::AndroidSdk(Builder &b): 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 tool_versions = list_files(bt_dir); @@ -82,17 +95,17 @@ void AndroidSdk::find_build_tools_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"; } @@ -106,7 +119,16 @@ AndroidNdk::AndroidNdk(Builder &b, const Architecture &a): 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 toolchains = list_filtered(toolchains_dir, "^"+prefix); @@ -137,7 +159,10 @@ void AndroidNdk::find_toolchain_dir() } 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(); @@ -146,17 +171,17 @@ void AndroidNdk::find_toolchain_dir() 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 platform_archs = list_filtered(platform_archs_dir, "^arch-"); @@ -165,7 +190,10 @@ void AndroidNdk::init_api_level(unsigned api) 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())); @@ -183,11 +211,13 @@ AndroidTools::AndroidTools(Builder &builder, const Architecture &arch): 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)); -- 2.45.2