]> git.tdb.fi Git - builder.git/commitdiff
Improve problem reporting for the Android toolchain
authorMikko Rasa <tdb@tdb.fi>
Sat, 2 Dec 2017 21:31:24 +0000 (23:31 +0200)
committerMikko Rasa <tdb@tdb.fi>
Sat, 2 Dec 2017 21:31:24 +0000 (23:31 +0200)
Rather than throwing exceptions with cryptic messages, add the problems
to the tools' problem lists.

source/androidarchiver.cpp
source/androidassetpackagingtool.cpp
source/androidcompiler.cpp
source/androidtools.cpp

index 71bc5ffb120ffbab86191b884e6d60c2b518fef5..58cbefa9f9ea8abbf03195f3f951e074ead5ec71 100644 (file)
@@ -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());
 }
index cca30b806168f615124058e0d028d27530d826d7..9e0fef75a990f8252d226ceda12dd396fe84fe60 100644 (file)
@@ -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<Target *> &sources, const string &)
index 3616cf450686ec5c1c10ad74592883d33f2ccb00..01daa2a65c6ea2318bcf0a6f79366945e2309575 100644 (file)
@@ -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");
index 809da7dc9e3f45830cc3a18a233812a76961aa6e..22a893e7bdcf41aac5912aaa8f0b40a09145f138 100644 (file)
@@ -1,5 +1,6 @@
 #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>
@@ -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<string> 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<string> 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<string> 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<string> 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));