From a5ea586a080ef6766a7d68b1c40633c6ae8b8ba4 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sun, 22 Jul 2012 20:07:09 +0300 Subject: [PATCH] Load binary packages from separate files --- source/builder.cpp | 1 + source/packagemanager.cpp | 42 +++++++++++++++++++++++++++++++++++++++ source/packagemanager.h | 9 +++++++++ 3 files changed, 52 insertions(+) diff --git a/source/builder.cpp b/source/builder.cpp index b8b0350..92f639c 100644 --- a/source/builder.cpp +++ b/source/builder.cpp @@ -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); diff --git a/source/packagemanager.cpp b/source/packagemanager.cpp index 5549846..7f18638 100644 --- a/source/packagemanager.cpp +++ b/source/packagemanager.cpp @@ -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::const_iterator i=binpkg_path.begin(); i!=binpkg_path.end(); ++i) + { + builder.get_logger().log("files", format("Traversing %s", *i)); + list files = list_filtered(*i, "\\.bpk$"); + for(list::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(); +} diff --git a/source/packagemanager.h b/source/packagemanager.h index 9ae93c9..05f5ebe 100644 --- a/source/packagemanager.h +++ b/source/packagemanager.h @@ -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 -- 2.43.0