]> git.tdb.fi Git - builder.git/blobdiff - source/androidcompiler.cpp
Initialize AndroidCompiler's build info in do_prepare
[builder.git] / source / androidcompiler.cpp
index 01daa2a65c6ea2318bcf0a6f79366945e2309575..2321f033c0844504d8005f087d42428ee8cb0c15 100644 (file)
@@ -13,9 +13,10 @@ using namespace std;
 using namespace Msp;
 
 AndroidCompiler::AndroidCompiler(Builder &b, const Architecture &a, const string &t, const AndroidNdk &n):
-       GnuCompiler(b, a, t, n.get_platform_sysroot()),
+       CustomizedTool(b, t, a),
        ndk(n)
 {
+       set_command((tag=="CXX" ? "g++" : "gcc"), true);
        if(ndk.get_root_dir().empty())
                problems.push_back("Android NDK not found");
        else if(ndk.get_bin_dir().empty())
@@ -25,60 +26,59 @@ AndroidCompiler::AndroidCompiler(Builder &b, const Architecture &a, const string
 
        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");
+       else if(!ndk.get_common_sysroot().empty())
+       {
+               build_info.sysroot = ndk.get_common_sysroot();
+               /* The common sysroot has asm headers in arch directories and the
+               compiler doesn't pick them up automatically */
+               build_info.incpath.push_back(ndk.get_common_sysroot()/"usr/include"/architecture->get_cross_prefix());
+       }
+       else
+               build_info.sysroot = ndk.get_platform_sysroot();
 }
 
-void AndroidCompiler::do_prepare()
+void AndroidCompiler::do_prepare(ToolData &tool) const
 {
-       GnuCompiler::do_prepare();
-       if(executable && tag=="CXX")
-       {
-               ExternalTask::Arguments argv;
-               argv.push_back(executable->get_path().str());
-               argv.push_back("-dumpversion");
+       const Architecture &arch = *static_cast<const Tool &>(tool).get_architecture();
 
-               builder.get_logger().log("auxcommands", format("Running %s", join(argv.begin(), argv.end())));
-               string version;
-               try
-               {
-                       version = strip(ExternalTask::run_and_capture_output(argv));
-                       builder.get_logger().log("tools", format("%s version is %s", FS::basename(executable->get_path()), version));
-               }
-               catch(const runtime_error &)
-               { }
+       CustomizedTool::do_prepare(tool);
+       if(tag=="CXX")
+       {
+               tool.build_info.libs.push_back("gnustl_static");
 
+               unsigned version = tool.extra_data;
+               string version_str = format("%d.%d.%d", version>>16, (version>>8)&0xFF, version&0xFF);
                FS::Path libstdcxx_dir = ndk.get_root_dir()/"sources"/"cxx-stl"/"gnu-libstdc++";
                FS::Path libstdcxx_path;
                while(1)
                {
-                       libstdcxx_path = libstdcxx_dir/version;
+                       libstdcxx_path = libstdcxx_dir/version_str;
                        if(FS::exists(libstdcxx_path))
                                break;
 
-                       string::size_type dot = version.rfind('.');
+                       string::size_type dot = version_str.rfind('.');
                        if(dot==string::npos)
                        {
-                               problems.push_back("C++ standard library not found");
+                               tool.problems.push_back("C++ standard library not found");
                                return;
                        }
 
-                       version = version.substr(0, dot);
+                       version_str = version_str.substr(0, dot);
                }
 
+               builder.get_logger().log("tools", "Found GNU libstdc++ in %s", libstdcxx_path);
+
                FS::Path public_dir = libstdcxx_path/"include";
-               system_path.push_back(public_dir);
-               build_info.incpath.push_back(public_dir);
+               tool.system_path.push_back(public_dir);
+               tool.build_info.incpath.push_back(public_dir);
 
                FS::Path arch_path = libstdcxx_path/"libs";
-               builder.get_logger().log("files", format("Traversing %s", arch_path.str()));
-               string arch_dir = architecture->best_match(list_files(arch_path));
+               builder.get_logger().log("files", "Traversing %s", arch_path.str());
+               string arch_dir = arch.best_match(list_files(arch_path));
                if(!arch_dir.empty())
                {
-                       build_info.incpath.push_back(libstdcxx_path/"libs"/arch_dir/"include");
-                       build_info.libpath.push_back(libstdcxx_path/"libs"/arch_dir);
+                       tool.build_info.incpath.push_back(libstdcxx_path/"libs"/arch_dir/"include");
+                       tool.build_info.libpath.push_back(libstdcxx_path/"libs"/arch_dir);
                }
        }
 }