]> git.tdb.fi Git - builder.git/commitdiff
Make tools capable of reporting a system-wide path used to locate input files
authorMikko Rasa <tdb@tdb.fi>
Fri, 8 Jun 2012 22:52:16 +0000 (01:52 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sun, 8 Jul 2012 21:08:53 +0000 (00:08 +0300)
source/builder.cpp
source/gnucompiler.cpp
source/gnucxxcompiler.cpp
source/gnulinker.cpp
source/tool.h
source/virtualfilesystem.cpp

index 0cbcb222039630b8f6e522da4496d4c3625fa292..e8f8927d580ea0e2739aadf1bd32b055f420e1a5 100644 (file)
@@ -125,14 +125,6 @@ Builder::Builder(int argc, char **argv):
 
        cwd = FS::getcwd();
 
-       toolchain.add_tool(new GnuCCompiler(*this));
-       toolchain.add_tool(new GnuCxxCompiler(*this));
-       toolchain.add_tool(new GnuLinker(*this));
-       toolchain.add_tool(new GnuArchiver(*this));
-       toolchain.add_tool(new Copy(*this));
-       toolchain.add_tool(new Tar(*this));
-       toolchain.add_tool(new PkgConfigGenerator(*this));
-
        load_build_file((FS::get_sys_data_dir(argv[0], "builder")/"builderrc").str());
        load_build_file((FS::get_user_data_dir("builder")/"rc").str());
 
@@ -151,6 +143,14 @@ Builder::Builder(int argc, char **argv):
                        }
        }
 
+       toolchain.add_tool(new GnuCCompiler(*this));
+       toolchain.add_tool(new GnuCxxCompiler(*this));
+       toolchain.add_tool(new GnuLinker(*this));
+       toolchain.add_tool(new GnuArchiver(*this));
+       toolchain.add_tool(new Copy(*this));
+       toolchain.add_tool(new Tar(*this));
+       toolchain.add_tool(new PkgConfigGenerator(*this));
+
        if(prfx.empty())
        {
                if(current_arch->is_native())
index 189e5148285c827015aaf203c2891a00ece39047..6989e2d3a40e3af4fdc7cffacb07c57bdbe0ec4d 100644 (file)
@@ -1,6 +1,7 @@
 #include <msp/fs/dir.h>
 #include <msp/fs/utils.h>
 #include <msp/strings/format.h>
+#include "architecture.h"
 #include "builder.h"
 #include "component.h"
 #include "externaltask.h"
@@ -15,7 +16,13 @@ using namespace Msp;
 GnuCompiler::GnuCompiler(Builder &b, const string &t, const string &n):
        Tool(b, t),
        name(n)
-{ }
+{
+       const Architecture &arch = builder.get_current_arch();
+       if(arch.is_native())
+               system_path.push_back("/usr/include");
+       else
+               system_path.push_back("/usr/"+arch.get_cross_prefix()+"/include");
+}
 
 Target *GnuCompiler::create_target(const list<Target *> &sources, const std::string &) const
 {
index fb7fbdce2cf37d0601f545e40c71d5c9528e0a5d..0601fc29c5f596fbf1a99d1956450ad13ca10abd 100644 (file)
@@ -1,6 +1,12 @@
+#include <msp/fs/stat.h>
+#include <msp/io/print.h>
+#include <msp/strings/regex.h>
+#include "builder.h"
 #include "csourcefile.h"
+#include "externaltask.h"
 #include "gnucxxcompiler.h"
 
+using namespace std;
 using namespace Msp;
 
 GnuCxxCompiler::GnuCxxCompiler(Builder &b):
@@ -9,6 +15,37 @@ GnuCxxCompiler::GnuCxxCompiler(Builder &b):
        input_suffixes.push_back(".cpp");
        input_suffixes.push_back(".cc");
        aux_suffixes.push_back(".hpp");
+
+       ExternalTask::Arguments argv;
+       argv.push_back(name);
+       argv.push_back("--version");
+       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()))
+               {
+                       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))
+                               {
+                                       if(builder.get_verbose()>=5)
+                                               IO::print("%s version is %s\n", name, 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);
+                       }
+               }
 }
 
 Target *GnuCxxCompiler::create_source(const Component &comp, const FS::Path &path) const
index 3693e2b0cc08386c6d9cb3bceecee05aa1d72455..ee4f02dd2fd520bd4e05402b596dbcd718601eae 100644 (file)
@@ -22,6 +22,19 @@ GnuLinker::GnuLinker(Builder &b):
 {
        input_suffixes.push_back(".o");
        input_suffixes.push_back(".a");
+
+       const Architecture &arch = builder.get_current_arch();
+       if(arch.is_native())
+       {
+               system_path.push_back("/lib");
+               system_path.push_back("/usr/lib");
+               if(arch.match_name("pc-32-linux"))
+                       system_path.push_back("/usr/lib/i386-linux-gnu");
+               else if(arch.match_name("pc-64-linux"))
+                       system_path.push_back("/usr/lib/x86_64-linux-gnu");
+       }
+       else
+               system_path.push_back("/usr/"+arch.get_cross_prefix()+"/lib");
 }
 
 Target *GnuLinker::create_target(const list<Target *> &sources, const std::string &arg) const
index 22fc3b28568293ea3a6b8bdb51faafc0d43da474..1905555e1818955515a25fe8b1fbca2e5149630a 100644 (file)
@@ -13,6 +13,7 @@ class Task;
 class Tool
 {
 public:
+       typedef std::list<Msp::FS::Path> SearchPath;
        typedef std::list<std::string> SuffixList;
 
 protected:
@@ -20,6 +21,7 @@ protected:
        std::string tag;
        SuffixList input_suffixes;
        SuffixList aux_suffixes;
+       SearchPath system_path;
 
        Tool(Builder &, const std::string &);
 public:
@@ -29,6 +31,7 @@ public:
        const SuffixList &get_input_suffixes() const { return input_suffixes; }
        const SuffixList &get_auxiliary_suffixes() const { return aux_suffixes; }
        bool accepts_suffix(const std::string &, bool = false) const;
+       const SearchPath &get_system_path() const { return system_path; }
 
        virtual Target *create_source(const Component &, const Msp::FS::Path &) const { return 0; }
        Target *create_target(Target &, const std::string & = std::string()) const;
index 75f935d505e4c4388c9d1073c1de0ec7a01786a6..d5cf909e5f7c284d6121917b4f82f51ab2cea273 100644 (file)
@@ -51,30 +51,6 @@ FileTarget *VirtualFileSystem::find_header(const string &name, const SearchPath
        if(i!=include_cache.end())
                return i->second;
 
-       static string cxx_ver;
-       if(cxx_ver.empty())
-       {
-               // XXX This needs to go elsewhere
-               /*StringList argv;
-               argv.push_back(current_arch->get_tool("CXX"));
-               argv.push_back("--version");
-               if(RegMatch m = Regex("[0-9]\\.[0-9.]+").match(run_command(argv)))
-               {
-                       cxx_ver = m[0].str;
-                       while(!cxx_ver.empty() && !FS::is_dir(FS::Path("/usr/include/c++")/cxx_ver))
-                       {
-                               string::size_type dot = cxx_ver.rfind('.');
-                               if(dot==string::npos)
-                                       break;
-                               cxx_ver.erase(dot);
-                       }
-                       if(verbose>=5)
-                               IO::print("C++ version is %s\n", cxx_ver);
-               }
-               else*/
-                       cxx_ver = "-";
-       }
-
        if(builder.get_verbose()>=5)
                IO::print("Looking for header %s with path %s\n", name, join(path.begin(), path.end()));