]> git.tdb.fi Git - builder.git/blobdiff - source/androidcompiler.cpp
Make AndroidCompiler more robust about detecting the cxx-stl location
[builder.git] / source / androidcompiler.cpp
index 490c198196c9764af402a91235b782d258eb12af..3616cf450686ec5c1c10ad74592883d33f2ccb00 100644 (file)
@@ -1,9 +1,13 @@
 #include <msp/fs/dir.h>
 #include <msp/fs/stat.h>
+#include <msp/fs/utils.h>
 #include <msp/strings/format.h>
+#include <msp/strings/utils.h>
 #include "androidcompiler.h"
 #include "androidtools.h"
 #include "builder.h"
+#include "externaltask.h"
+#include "filetarget.h"
 
 using namespace std;
 using namespace Msp;
@@ -23,7 +27,37 @@ void AndroidCompiler::do_prepare()
        GnuCompiler::do_prepare();
        if(executable && tag=="CXX")
        {
-               FS::Path libstdcxx_path = ndk.get_root_dir()/"sources"/"cxx-stl"/"gnu-libstdc++"/version;
+               ExternalTask::Arguments argv;
+               argv.push_back(executable->get_path().str());
+               argv.push_back("-dumpversion");
+
+               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 &)
+               { }
+
+               FS::Path libstdcxx_dir = ndk.get_root_dir()/"sources"/"cxx-stl"/"gnu-libstdc++";
+               FS::Path libstdcxx_path;
+               while(1)
+               {
+                       libstdcxx_path = libstdcxx_dir/version;
+                       if(FS::exists(libstdcxx_path))
+                               break;
+
+                       string::size_type dot = version.rfind('.');
+                       if(dot==string::npos)
+                       {
+                               problems.push_back("C++ standard library not found");
+                               return;
+                       }
+
+                       version = version.substr(0, dot);
+               }
 
                FS::Path public_dir = libstdcxx_path/"include";
                system_path.push_back(public_dir);