]> git.tdb.fi Git - builder.git/commitdiff
Improve Builder::get_header
authorMikko Rasa <tdb@tdb.fi>
Sat, 22 Sep 2007 13:43:48 +0000 (13:43 +0000)
committerMikko Rasa <tdb@tdb.fi>
Sat, 22 Sep 2007 13:43:48 +0000 (13:43 +0000)
Move problem reporting later so --analyze can be used even if there are problems
Do not crash on missing requires in a condition
Make include and library paths in components absolute by using package source path

source/builder.cpp
source/component.cpp
source/sourcepackage.cpp

index 34c65af48be88df4d0be392b9735bad57472a3ea..d9444ce8a2c878d1eed9e4f9a80456460d43ccbc 100644 (file)
@@ -13,6 +13,7 @@ Distributed under the LGPL
 #include <msp/datafile/parser.h>
 #include <msp/path/utils.h>
 #include <msp/strings/formatter.h>
+#include <msp/strings/regex.h>
 #include <msp/strings/utils.h>
 #include <msp/time/units.h>
 #include <msp/time/utils.h>
@@ -198,7 +199,7 @@ path.  Considers known targets as well as existing files.  If a matching target
 is not found but a file exists, a new SystemHeader target will be created and
 returned.
 */
-Target *Builder::get_header(const string &include, const string &, const string &from, const list<string> &path)
+Target *Builder::get_header(const string &include, const string &arch, const string &from, const list<string> &path)
 {
        string hash(8, 0);
        update_hash(hash, from);
@@ -210,21 +211,43 @@ Target *Builder::get_header(const string &include, const string &, const string
        if(i!=includes.end())
                return i->second;
 
-       string fn=include.substr(1);
-       Target *tgt=0;
-       if(include[0]=='"' && (tgt=get_header(Path(from)/fn)))
-               ;
-       else if((tgt=get_header(Path("/usr/include")/fn)))
-               ;
-       //XXX Determine the C++ header location dynamically
-       else if((tgt=get_header(Path("/usr/include/c++/4.1.2")/fn)))
-               ;
-       else
+       static string cxx_ver;
+       if(cxx_ver.empty())
        {
-               for(list<string>::const_iterator j=path.begin(); (j!=path.end() && !tgt); ++j)
-                       tgt=get_header(cwd/ *j/fn);
+               StringList argv;
+               argv.push_back(get_architecture(arch).get_tool("CXX"));
+               argv.push_back("--version");
+               cxx_ver=Regex(" ([0-9.]+) ").match(run_command(argv))[1].str;
+               while(!cxx_ver.empty() && !exists(Path("/usr/include/c++")/cxx_ver))
+               {
+                       unsigned dot=cxx_ver.rfind('.');
+                       if(dot==string::npos)
+                               break;
+                       cxx_ver.erase(dot);
+               }
+               if(verbose>=5)
+                       cout<<"C++ version is "<<cxx_ver<<'\n';
        }
 
+       string fn=include.substr(1);
+       if(verbose>=5)
+               cout<<"Looking for include "<<fn<<" with path "<<join(path.begin(), path.end())<<'\n';
+
+       StringList syspath;
+       if(include[0]=='\"')
+               syspath.push_back(from);
+       if(arch=="native")
+               syspath.push_back("/usr/include");
+       else
+               syspath.push_back("/usr/"+get_architecture(arch).get_prefix()+"/lib");
+       syspath.push_back((Path("/usr/include/c++/")/cxx_ver/fn).str());
+
+       Target *tgt=0;
+       for(list<string>::const_iterator j=syspath.begin(); (!tgt && j!=syspath.end()); ++j)
+               tgt=get_header(Path(*j)/fn);
+       for(list<string>::const_iterator j=path.begin(); (!tgt && j!=path.end()); ++j)
+               tgt=get_header(cwd/ *j/fn);
+
        includes.insert(TargetMap::value_type(id, tgt));
 
        return tgt;
@@ -262,6 +285,9 @@ Target *Builder::get_library(const string &lib, const string &arch, const list<s
        else
                syspath.push_back("/usr/"+get_architecture(arch).get_prefix()+"/lib");
 
+       if(verbose>=5)
+               cout<<"Looking for library "<<lib<<" with path "<<join(path.begin(), path.end())<<'\n';
+
        Target *tgt=0;
        for(StringList::iterator j=syspath.begin(); (!tgt && j!=syspath.end()); ++j)
                tgt=get_library(lib, arch, *j, mode);
@@ -342,15 +368,6 @@ int Builder::main()
                        problem(spkg->get_name(), format("wrong architecture (%s)", spkg->get_arch()));
        }
 
-       if(!problems.empty())
-       {
-               cerr<<"The following problems were detected:\n";
-               for(ProblemList::iterator i=problems.begin(); i!=problems.end(); ++i)
-                       cerr<<"  "<<i->package<<": "<<i->descr<<'\n';
-               cerr<<"Please fix them and try again.\n";
-               return 1;
-       }
-
        if(conf_only)
                return 0;
 
@@ -385,6 +402,15 @@ int Builder::main()
        if(analyzer)
                analyzer->analyze();
 
+       if(!problems.empty())
+       {
+               cerr<<"The following problems were detected:\n";
+               for(ProblemList::iterator i=problems.begin(); i!=problems.end(); ++i)
+                       cerr<<"  "<<i->package<<": "<<i->descr<<'\n';
+               cerr<<"Please fix them and try again.\n";
+               return 1;
+       }
+
        //if(create_makefile
 
        if(clean)
index f4e8fc2ee734f11e3306b38a03a60e7309d8a027..29f58b48c7633c1396d3938f73d33a9bf6a2b70d 100644 (file)
@@ -41,6 +41,11 @@ void Component::create_build_info()
        for(PackageList::iterator i=requires.begin(); i!=requires.end(); ++i)
                build_info.add((*i)->get_exported_binfo());
 
+       for(StringList::iterator i=build_info.incpath.begin(); i!=build_info.incpath.end(); ++i)
+               *i=(pkg.get_source() / *i).str();
+       for(StringList::iterator i=build_info.libpath.begin(); i!=build_info.libpath.end(); ++i)
+               *i=(pkg.get_source() / *i).str();
+
        if(type==PROGRAM)
        {
                string strip=pkg.get_config().get_option("strip").value;
index cfe4be3f31a781ea1a5217eaaaf45ba6ec6d49f1..42118a16cd56056b80214bb17b5b854df7bb4f25 100644 (file)
@@ -106,7 +106,8 @@ void SourcePackage::do_configure(const StringMap &opts, unsigned flag)
                {
                        const StringList &reqs=i->get_requires();
                        for(StringList::const_iterator j=reqs.begin(); j!=reqs.end(); ++j)
-                               requires.push_back(builder.get_package(*j));
+                               if(Package *pkg=builder.get_package(*j))
+                                       requires.push_back(pkg);
                }
 
        base_reqs=requires;