Builder::Builder(int argc, char **argv):
package_manager(*this),
- main_pkg(0),
native_arch(*this, string()),
build_type(0),
vfs(*this),
Target *tarballs = new VirtualTarget(*this, "tarballs");
world->add_dependency(*tarballs);
- main_pkg->prepare();
+ package_manager.get_main_package().prepare();
// Make the cmdline target depend on all targets mentioned on the command line
Target *cmdline = new VirtualTarget(*this, "cmdline");
Target *tgt = queue.front();
queue.erase(queue.begin());
- if(tgt->is_buildable() && (tgt->get_package()==main_pkg || clean>=2))
+ if(tgt->is_buildable() && (tgt->get_package()==&package_manager.get_main_package() || clean>=2))
clean_tgts.insert(tgt);
const Target::Dependencies &deps = tgt->get_dependencies();
void Builder::package_help()
{
- const Config &config = main_pkg->get_config();
+ SourcePackage &main_pkg = dynamic_cast<SourcePackage &>(package_manager.get_main_package());
+ const Config &config = main_pkg.get_config();
const Config::OptionMap &options = config.get_options();
IO::print("Required packages:\n ");
- const Package::Requirements &requires = main_pkg->get_required_packages();
+ const Package::Requirements &requires = main_pkg.get_required_packages();
for(Package::Requirements::const_iterator i=requires.begin(); i!=requires.end(); ++i)
{
if(i!=requires.begin())
void Builder::Loader::package(const string &n)
{
SourcePackage *pkg = new SourcePackage(obj, n, get_source());
- if(!obj.main_pkg)
- obj.main_pkg = pkg;
- if(obj.conf_all || pkg==obj.main_pkg)
+ if(obj.conf_all || pkg==&obj.package_manager.get_main_package())
load_sub(*pkg, obj.cmdline_options);
else
load_sub(*pkg);
PackageManager::PackageManager(Builder &b):
builder(b),
no_externals(false),
+ main_pkg(0),
env_set(false)
{ }
throw logic_error("Package is already managed");
}
+ if(packages.empty())
+ main_pkg = pkg;
+
packages.insert(PackageMap::value_type(pkg->get_name(), pkg));
}
+Package &PackageManager::get_main_package() const
+{
+ if(!main_pkg)
+ throw logic_error("No packages");
+ return *main_pkg;
+}
+
Package *PackageManager::find_package(const string &name)
{
if(not_found.count(name))
SearchPath binpkg_files;
bool no_externals;
PackageMap packages;
+ Package *main_pkg;
std::set<std::string> not_found;
bool env_set;
/** Returns a package from the cache. */
Package *get_package(const std::string &);
+ /** Returns the package that was added first. This should be considered
+ the primary build target. */
+ Package &get_main_package() const;
+
const PackageMap &get_packages() const { return packages; }
/** Locates a package and loads it if necessary. */