]> git.tdb.fi Git - builder.git/commitdiff
Load binary packages from separate files
authorMikko Rasa <tdb@tdb.fi>
Sun, 22 Jul 2012 17:07:09 +0000 (20:07 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sun, 22 Jul 2012 17:10:06 +0000 (20:10 +0300)
source/builder.cpp
source/packagemanager.cpp
source/packagemanager.h

index b8b035066b5f286eedeb84c8e904fdd88930ed8f..92f639c9c594e184f617dce0b204677bb7225ea5 100644 (file)
@@ -160,6 +160,7 @@ Builder::Builder(int argc, char **argv):
 
        package_manager.append_package_path(cwd);
        package_manager.append_package_path(cwd/"..");
+       package_manager.append_binary_package_path(FS::get_sys_data_dir(argv[0], "builder"));
 
        package_manager.set_no_externals(no_externals);
 
index 55498467d636a694f957e58a3dd475fd3b185b87..7f186382a3e76cf4b8a490095ec9c91f1e416ba4 100644 (file)
@@ -33,6 +33,11 @@ void PackageManager::append_package_path(const FS::Path &p)
        pkg_path.push_back(p);
 }
 
+void PackageManager::append_binary_package_path(const FS::Path &p)
+{
+       binpkg_path.push_back(p);
+}
+
 void PackageManager::set_no_externals(bool x)
 {
        no_externals = x;
@@ -72,6 +77,15 @@ Package *PackageManager::find_package(const string &name)
                }
        }
 
+       FS::Path path = get_binary_package_file(name);
+       if(!path.empty())
+       {
+               builder.load_build_file(path);
+               i = packages.find(name);
+               if(i!=packages.end())
+                       return i->second;
+       }
+
        Package *pkg = 0;
        try
        {
@@ -184,3 +198,31 @@ FS::Path PackageManager::get_package_location(const string &name)
 
        return FS::Path();
 }
+
+FS::Path PackageManager::get_binary_package_file(const string &name)
+{
+       builder.get_logger().log("packagemgr", format("Looking for binary package %s", name));
+
+       if(binpkg_files.empty())
+       {
+               for(list<FS::Path>::const_iterator i=binpkg_path.begin(); i!=binpkg_path.end(); ++i)
+               {
+                       builder.get_logger().log("files", format("Traversing %s", *i));
+                       list<string> files = list_filtered(*i, "\\.bpk$");
+                       for(list<string>::const_iterator j=files.begin(); j!=files.end(); ++j)
+                               binpkg_files.push_back(*i / *j);
+                       builder.get_logger().log("packagemgr", format("%d binary packages found in %s", files.size(), *i));
+               }
+
+               builder.get_logger().log("packagemgr", format("%d binary packages found", binpkg_files.size()));
+       }
+
+       for(SearchPath::const_iterator i=binpkg_files.begin(); i!=binpkg_files.end(); ++i)
+       {
+               string base = FS::basepart(FS::basename(*i));
+               if(base==name)
+                       return *i;
+       }
+
+       return FS::Path();
+}
index 9ae93c9829b9ade57911e1f514a0c9c2fe25893b..05f5ebe317e6b3c5f49452868b108b995a4cea9f 100644 (file)
@@ -24,6 +24,8 @@ private:
        Builder &builder;
        SearchPath pkg_path;
        SearchPath pkg_dirs;
+       SearchPath binpkg_path;
+       SearchPath binpkg_files;
        bool no_externals;
        PackageMap packages;
        bool env_set;
@@ -35,6 +37,9 @@ public:
        /// Adds a location to look for source packages from.
        void append_package_path(const Msp::FS::Path &);
 
+       /// Adds a location to look for binary packages from.
+       void append_binary_package_path(const Msp::FS::Path &);
+
        /** Prevent creation of source packages. */
        void set_no_externals(bool);
 
@@ -55,6 +60,10 @@ private:
        /** Determines the source directory of a package.  Pkg-config is consulted
        first, and if it fails, the package path is searched for matches. */
        Msp::FS::Path get_package_location(const std::string &);
+
+       /** Determines the file containing a binary package.  The file is expected
+       to be named after the package. */
+       Msp::FS::Path get_binary_package_file(const std::string &);
 };
 
 #endif