]> git.tdb.fi Git - builder.git/commitdiff
Set PKG_CONFIG_PATH to include prefix
authorMikko Rasa <tdb@tdb.fi>
Mon, 11 May 2009 20:43:21 +0000 (20:43 +0000)
committerMikko Rasa <tdb@tdb.fi>
Mon, 11 May 2009 20:43:21 +0000 (20:43 +0000)
More intelligent checking for pkg-config errors

Build
source/binarypackage.cpp
source/builder.cpp
source/builder.h
source/misc.cpp
source/misc.h

diff --git a/Build b/Build
index 2754b9ef5aa7ba257a45ecb848a3a3503c5f09bd..c2d976f6c66891c4dacc74261a506d995726a401 100644 (file)
--- a/Build
+++ b/Build
@@ -17,10 +17,10 @@ package "builder"
                install true;
        };
 
-       tarball "@src"
+       /*tarball "@src"
        {
                source "bootstrap.sh";
                source "Readme.txt";
                source "License.txt";
-       };
+       };*/
 };
index 4589e2440337e7a5095bea223f5b1004be7a8abc..8cfc87404343cf4704e5dad4c4734e99f70a1a6e 100644 (file)
@@ -38,19 +38,7 @@ void BinaryPackage::create_build_info()
 
 BinaryPackage *BinaryPackage::from_pkgconfig(Builder &builder, const string &name)
 {
-       list<string> argv;
-       argv.push_back("pkg-config");
-       argv.push_back("--silence-errors");
-       argv.push_back("--cflags");
-       argv.push_back("--libs");
-       argv.push_back(name);
-       if(builder.get_verbose()>=4)
-               IO::print("Running %s\n", join(argv.begin(), argv.end()));
-       string info=run_command(argv);
-
-       if(info.empty())
-               return 0;
-
+       string info=builder.run_pkgconfig(name, "flags");
 
        BinaryPackage *pkg=new BinaryPackage(builder, name);
        pkg->use_pkgconfig=true;
index b06b8ffb2fd0b1de4c7b288989cd8704ce295919..9db904a8d805af19a323f6d68ffe319b7343d819 100644 (file)
@@ -6,6 +6,7 @@ Distributed under the LGPL
 */
 
 #include <set>
+#include <cstdlib>
 #include <sys/utsname.h>
 #include <msp/core/except.h>
 #include <msp/core/getopt.h>
@@ -194,6 +195,25 @@ Builder::~Builder()
 
 int Builder::main()
 {
+       if(prefix.str()!="/usr")
+       {
+               FS::Path pcdir=prefix/"lib"/"pkgconfig";
+               if(const char *pcp=getenv("PKG_CONFIG_PATH"))
+               {
+                       vector<string> path=split(pcp, ':');
+                       bool found=false;
+                       for(vector<string>::const_iterator i=path.begin(); (!found && i!=path.end()); ++i)
+                               found=(*i==pcdir.str());
+                       if(!found)
+                       {
+                               path.push_back(pcdir.str());
+                               setenv("PKG_CONFIG_PATH", join(path.begin(), path.end(), ":").c_str(), true);
+                       }
+               }
+               else
+                       setenv("PKG_CONFIG_PATH", pcdir.str().c_str(), true);
+       }
+
        if(load_build_file(cwd/build_file))
        {
                if(help)
@@ -269,8 +289,6 @@ int Builder::main()
                return 1;
        }
 
-       //if(create_makefile
-
        if(clean)
                exit_code=do_clean();
        else if(build)
@@ -279,6 +297,32 @@ int Builder::main()
        return exit_code;
 }
 
+string Builder::run_pkgconfig(const string &pkg, const string &what)
+{
+       list<string> argv;
+       argv.push_back("pkg-config");
+       if(what=="cflags" || what=="libs")
+               argv.push_back("--"+what);
+       else if(what=="flags")
+       {
+               argv.push_back("--cflags");
+               argv.push_back("--libs");
+       }
+       else
+               argv.push_back("--variable="+what);
+       argv.push_back(pkg);
+
+       if(verbose>=4)
+               IO::print("Running %s\n", join(argv.begin(), argv.end()));
+
+       int status;
+       string res=run_command(argv, &status);
+       if(status)
+               throw Exception(format("pkg-config for package %s failed", pkg));
+
+       return res;
+}
+
 Package *Builder::get_package(const string &name)
 {
        PackageMap::iterator i=packages.find(format("%s/%s", name, current_arch->get_name()));
@@ -295,14 +339,19 @@ Package *Builder::get_package(const string &name)
                        return i->second;
        }
 
-       // Package source not found - create a binary package
-       Package *pkg=BinaryPackage::from_pkgconfig(*this, name);
+       Package *pkg=0;
+       try
+       {
+               // Package source not found - create a binary package
+               pkg=BinaryPackage::from_pkgconfig(*this, name);
+       }
+       catch(...)
+       {
+               problem(name, "not found");
+       }
 
        packages.insert(PackageMap::value_type(name, pkg));
 
-       if(!pkg)
-               problem(name, "not found");
-
        return pkg;
 }
 
@@ -458,16 +507,15 @@ FS::Path Builder::get_package_location(const string &name)
        if(verbose>=3)
                IO::print("Looking for package %s\n", 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)
-               IO::print("Running %s\n", join(argv.begin(), argv.end()));
-       string srcdir=strip(run_command(argv));
-       if(!srcdir.empty())
-               return srcdir;
+       try
+       {
+               // Try to get source directory with pkgconfig
+               string srcdir=strip(run_pkgconfig(name, "source"));
+               if(!srcdir.empty())
+                       return srcdir;
+       }
+       catch(...)
+       { }
 
        if(pkg_dirs.empty())
        {
index 81f5f13678be09d432d46ae53d2bb785357285ac..977785c39b47a703b73d66957e3cf9f467dfb105 100644 (file)
@@ -117,6 +117,8 @@ public:
 
        SourcePackage *get_main_package() const { return main_pkg; }
 
+       std::string run_pkgconfig(const std::string &, const std::string &);
+
        /** Looks up a target by name.  Returns 0 if no such target exists. */
        Target *get_target(const std::string &) const;
 
index cf97c5506db3526535cfdbbfe3e3a9390224e8e6..2409e05a650a7fb5c67885d799f9359ad550037b 100644 (file)
@@ -15,7 +15,7 @@ Distributed under the LGPL
 using namespace std;
 using namespace Msp;
 
-string run_command(const StringList &argv)
+string run_command(const StringList &argv, int *status)
 {
        int pfd[2];
        pipe(pfd);
@@ -53,8 +53,18 @@ string run_command(const StringList &argv)
                        int len=read(pfd[0], buf, sizeof(buf));
                        if(len<=0)
                        {
-                               if(waitpid(pid, 0, WNOHANG))
+                               int s;
+                               if(waitpid(pid, &s, WNOHANG))
+                               {
+                                       if(status)
+                                       {
+                                               if(WIFEXITED(s))
+                                                       *status=WEXITSTATUS(s);
+                                               else
+                                                       *status=-1;
+                                       }
                                        break;
+                               }
                        }
                        else
                                result.append(buf, len);
index 508a9b0cf6a0fd0b48c876c91742df1695ac69b2..99e41f010be31f2d62e22328c3a601a7d93e869a 100644 (file)
@@ -25,7 +25,7 @@ typedef std::list<Msp::FS::Path> PathList;
 typedef std::map<std::string, std::string> StringMap;
 
 /** Runs a command and returns its output as a string.  The exit status of the
-command is lost. */
-std::string run_command(const StringList &);
+command is returned in the second parameter if it is not null. */
+std::string run_command(const StringList &, int * =0);
 
 #endif