From: Mikko Rasa Date: Wed, 13 Aug 2008 05:02:01 +0000 (+0000) Subject: Improve automatic package finding to detect directories with version number X-Git-Tag: 0.9 X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=52586d9f4aa721e924d17c7e9a16cb0b98ddc05d;p=builder.git Improve automatic package finding to detect directories with version number Make bootstrap.sh recognize libs as extracted from tarballs --- diff --git a/bootstrap.sh b/bootstrap.sh index f0f51a7..362343a 100755 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -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 diff --git a/source/builder.cpp b/source/builder.cpp index 257c931..58288ff 100644 --- a/source/builder.cpp +++ b/source/builder.cpp @@ -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 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 argv; - argv.push_back("pkg-config"); - argv.push_back("--variable=source"); - argv.push_back(name); - if(verbose>=4) - cout<<"Running "<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<=1) + cout<=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 argv; + argv.push_back("pkg-config"); + argv.push_back("--variable=source"); + argv.push_back(name); + if(verbose>=4) + cout<<"Running "<::const_iterator i=pkg_path.begin(); i!=pkg_path.end(); ++i) + { + list files=list_files(*i); + for(list::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::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 "<=1) + cout<<"Will build "< actions; diff --git a/source/builder.h b/source/builder.h index 2bfa32a..19885c5 100644 --- a/source/builder.h +++ b/source/builder.h @@ -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 &);