]> git.tdb.fi Git - builder.git/commitdiff
Improve automatic package finding to detect directories with version number 0.9
authorMikko Rasa <tdb@tdb.fi>
Wed, 13 Aug 2008 05:02:01 +0000 (05:02 +0000)
committerMikko Rasa <tdb@tdb.fi>
Wed, 13 Aug 2008 05:02:01 +0000 (05:02 +0000)
Make bootstrap.sh recognize libs as extracted from tarballs

bootstrap.sh
source/builder.cpp
source/builder.h

index f0f51a7ea069c8e6b7a13dd4269626711bd4ce8d..362343a65598b20649956753cf2363d70f90fde7 100755 (executable)
@@ -17,13 +17,13 @@ mkdir -p include/msp
 sources=source/*.cpp
 
 for i in $REQUIRED; do
-       path=$LIBPATH/$i
-       if [ ! -e $path ]; then
-               echo $i missing
+       path=`ls -1d $LIBPATH/*$i* 2>/dev/null | head -1`
+       if [ ! -d $path ]; then
+               echo msp$i missing
                exit 1
        fi
        if [ $i = "core" ]; then
-               ln -sfT $path/source/* -t include/msp
+               ln -sf $path/source/* -t include/msp
        else
                ln -sfT $path/source include/msp/$i
        fi
index 257c931732b556cde8e5b17078dcb91d57f13cd7..58288ffbfa096a71e4dfbe82fe360c207824f7b7 100644 (file)
@@ -143,7 +143,7 @@ Builder::Builder(int argc, char **argv):
                        prefix=(FS::get_home_dir()/"local"/current_arch).str();
        }
        else
-               prefix=prfx;
+               prefix=FS::getcwd()/prfx;
 
        warnings.push_back("all");
        warnings.push_back("extra");
@@ -155,6 +155,9 @@ Builder::Builder(int argc, char **argv):
                vector<string> warns=split(*i, ',');
                warnings.insert(warnings.end(), warns.begin(), warns.end());
        }
+
+       pkg_path.push_back(cwd/".");
+       pkg_path.push_back(cwd/"..");
 }
 
 /**
@@ -172,38 +175,14 @@ Package *Builder::get_package(const string &name)
        if(i!=packages.end())
                return i->second;
 
-       // Try to get source directory with pkgconfig
-       list<string> argv;
-       argv.push_back("pkg-config");
-       argv.push_back("--variable=source");
-       argv.push_back(name);
-       if(verbose>=4)
-               cout<<"Running "<<join(argv.begin(), argv.end())<<'\n';
-       string srcdir=strip(run_command(argv));
-
-       PathList dirs;
-       if(!srcdir.empty())
-               dirs.push_back(srcdir);
-
-       // Make some other guesses about the source directory
-       dirs.push_back(cwd/name);
-       dirs.push_back(cwd/".."/name);
-       if(!name.compare(0, 3, "msp"))
+       FS::Path path=get_package_location(name);
+       if(!path.empty() && !load_build_file(path/"Build"))
        {
-               dirs.push_back(cwd/name.substr(3));
-               dirs.push_back(cwd/".."/name.substr(3));
+               i=packages.find(name);
+               if(i!=packages.end())
+                       return i->second;
        }
 
-       // Go through the candidate directories and look for a Build file
-       for(PathList::iterator j=dirs.begin(); j!=dirs.end(); ++j)
-               if(!load_build_file(*j/"Build"))
-               {
-                       i=packages.find(name);
-                       if(i!=packages.end())
-                               return i->second;
-                       break;
-               }
-
        // Package source not found - create a binary package
        Package *pkg=BinaryPackage::from_pkgconfig(*this, name);
 
@@ -400,7 +379,8 @@ int Builder::main()
        if(conf_only)
                return 0;
 
-       cout<<all_reqs.size()<<" active packages, "<<targets.size()<<" targets\n";
+       if(verbose>=1)
+               cout<<all_reqs.size()<<" active packages, "<<targets.size()<<" targets\n";
        if(verbose>=2)
        {
                for(PackageList::const_iterator i=all_reqs.begin(); i!=all_reqs.end(); ++i)
@@ -495,6 +475,52 @@ void Builder::usage(const char *reason, const char *argv0, bool brief)
        }
 }
 
+/**
+Determines the source directory of a package.  pkg-config is consulted first,
+and if it fails, the package path is searched for matches.
+*/
+FS::Path Builder::get_package_location(const string &name)
+{
+       // Try to get source directory with pkgconfig
+       list<string> argv;
+       argv.push_back("pkg-config");
+       argv.push_back("--variable=source");
+       argv.push_back(name);
+       if(verbose>=4)
+               cout<<"Running "<<join(argv.begin(), argv.end())<<'\n';
+       string srcdir=strip(run_command(argv));
+       if(!srcdir.empty())
+               return srcdir;
+
+       if(pkg_dirs.empty())
+       {
+               for(list<FS::Path>::const_iterator i=pkg_path.begin(); i!=pkg_path.end(); ++i)
+               {
+                       list<string> files=list_files(*i);
+                       for(list<string>::const_iterator j=files.begin(); j!=files.end(); ++j)
+                       {
+                               FS::Path full=*i / *j;
+                               if(FS::exists(full/"Build"))
+                                       pkg_dirs.push_back(full);
+                       }
+               }
+       }
+
+       bool msp=!name.compare(0, 3, "msp");
+       for(list<FS::Path>::const_iterator i=pkg_dirs.begin(); i!=pkg_dirs.end(); ++i)
+       {
+               string base=basename(*i);
+               unsigned dash=base.rfind('-');
+
+               if(!base.compare(0, dash, name))
+                       return *i;
+               else if(msp && !base.compare(0, dash-3, name, 3, string::npos))
+                       return *i;
+       }
+
+       return FS::Path();
+}
+
 /**
 Loads the given build file.
 
@@ -711,7 +737,8 @@ int Builder::do_build()
                cout<<"Already up to date\n";
                return 0;
        }
-       cout<<"Will build "<<total<<" target(s)\n";
+       if(verbose>=1)
+               cout<<"Will build "<<total<<" target(s)\n";
 
        vector<Action *> actions;
 
index 2bfa32a429c7c9c137c19312616cd0f42972c643..19885c56291729d971776ec57a3295c546073edb 100644 (file)
@@ -88,6 +88,8 @@ private:
 
        PackageMap   packages;
        SourcePackage *main_pkg;
+       PathList     pkg_path;
+       PathList     pkg_dirs;
 
        TargetMap    targets;
        TargetList   new_tgts;
@@ -116,6 +118,7 @@ private:
        Msp::FS::Path   prefix;
        StringList      warnings;
 
+       Msp::FS::Path get_package_location(const std::string &);
        int    load_build_file(const Msp::FS::Path &);
        int    create_targets();
        Target *get_header(const Msp::FS::Path &);