]> git.tdb.fi Git - builder.git/blobdiff - source/gnucxxcompiler.cpp
Add and improve build signatures for some tools
[builder.git] / source / gnucxxcompiler.cpp
index 9045b6c3a369029a48efb39f386ce91a3f4dc978..55f7109e7b05470bb03ac690d98a970ce0323bf4 100644 (file)
@@ -1,7 +1,6 @@
 #include <msp/fs/stat.h>
 #include <msp/fs/utils.h>
 #include <msp/io/print.h>
-#include <msp/strings/regex.h>
 #include <msp/strings/utils.h>
 #include "builder.h"
 #include "csourcefile.h"
 using namespace std;
 using namespace Msp;
 
-GnuCxxCompiler::GnuCxxCompiler(Builder &b):
-       GnuCompiler(b, "CXX", "g++")
+GnuCxxCompiler::GnuCxxCompiler(Builder &b, const Architecture &a):
+       GnuCompiler(b, a, "CXX")
 {
+       set_command("g++", true);
        input_suffixes.push_back(".cpp");
        input_suffixes.push_back(".cc");
        aux_suffixes.push_back(".hpp");
+}
 
+void GnuCxxCompiler::query_version()
+{
        ExternalTask::Arguments argv;
        argv.push_back(executable->get_path().str());
-       argv.push_back("--version");
+       argv.push_back("-dumpversion");
        builder.get_logger().log("auxcommands", format("Running %s", join(argv.begin(), argv.end())));
-       ExternalTask task(argv);
-       task.set_stdout(ExternalTask::CAPTURE);
-       task.set_stderr(ExternalTask::IGNORE);
-       task.start();
-       Task::Status status;
-       while((status=task.check())==Task::RUNNING) ;
-       if(status==Task::SUCCESS)
-               if(RegMatch m = Regex("[0-9]\\.[0-9.]+").match(task.get_output()))
+       try
+       {
+               string cxx_ver = strip(ExternalTask::run_and_capture_output(argv));
+               FS::Path cxx_path = FS::Path("/usr/include/c++")/cxx_ver;
+               if(FS::is_dir(cxx_path))
                {
-                       string cxx_ver = m[0].str;
-                       while(!cxx_ver.empty())
-                       {
-                               FS::Path cxx_path = FS::Path("/usr/include/c++")/cxx_ver;
-                               if(FS::is_dir(cxx_path))
-                               {
-                                       builder.get_logger().log("tools", format("%s version is %s", FS::basename(executable->get_path()), cxx_ver));
-                                       system_path.push_back(cxx_path);
-                                       break;
-                               }
-
-                               string::size_type dot = cxx_ver.rfind('.');
-                               if(dot==string::npos)
-                                       break;
-                               cxx_ver.erase(dot);
-                       }
+                       builder.get_logger().log("tools", format("%s version is %s", FS::basename(executable->get_path()), cxx_ver));
+                       system_path.push_back(cxx_path);
                }
+       }
+       catch(const runtime_error &)
+       { }
 }
 
 Target *GnuCxxCompiler::create_source(const Component &comp, const FS::Path &path) const
@@ -59,3 +48,10 @@ Target *GnuCxxCompiler::create_source(const FS::Path &path) const
 {
        return new CSourceFile(builder, path);
 }
+
+void GnuCxxCompiler::do_prepare()
+{
+       GnuCompiler::do_prepare();
+       if(executable)
+               query_version();
+}