Skip to content

Commit

Permalink
FS|libcore: Compiling a full list of packages including dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Jul 16, 2016
1 parent 6e92a40 commit c850ccf
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 15 deletions.
13 changes: 12 additions & 1 deletion doomsday/sdk/libcore/include/de/filesys/packageloader.h
Expand Up @@ -75,6 +75,8 @@ class DENG2_PUBLIC PackageLoader
IdentifierList(String const &spaceSeparatedIds);
};

static PackageLoader &get();

public:
PackageLoader();

Expand Down Expand Up @@ -156,7 +158,16 @@ class DENG2_PUBLIC PackageLoader
*/
StringList findAllPackages() const;

static PackageLoader &get();
/**
* Takes a list of package identifiers and checks if they have any dependent packages
* (required, recommended, or extra). Those are then expanded using the same logic as
* when loading packages (everything precedes the main package).
*
* @param packageIdentifiers Package identifiers.
*
* @return Expanded list of identifiers.
*/
StringList expandDependencies(StringList const &packageIdentifiers) const;

private:
DENG2_PRIVATE(d)
Expand Down
10 changes: 1 addition & 9 deletions doomsday/sdk/libcore/src/filesys/package.cpp
Expand Up @@ -356,15 +356,7 @@ QStringList Package::tags(String const &tagsString)

StringList Package::requires(File const &packageFile)
{
StringList ids;
if (packageFile.objectNamespace().has(PACKAGE_REQUIRES))
{
for (auto const *value : packageFile.objectNamespace().geta(PACKAGE_REQUIRES).elements())
{
ids << value->asText();
}
}
return ids;
return packageFile.objectNamespace().getStringList(PACKAGE_REQUIRES);
}

void Package::addRequiredPackage(File &packageFile, String const &id)
Expand Down
44 changes: 39 additions & 5 deletions doomsday/sdk/libcore/src/filesys/packageloader.cpp
Expand Up @@ -222,6 +222,7 @@ DENG2_PIMPL(PackageLoader)
loaded.insert(packageId, pkg);
pkg->setOrder(loadCounter++);
pkg->didLoad();

return *pkg;
}

Expand Down Expand Up @@ -298,7 +299,8 @@ DENG2_PIMPL(PackageLoader)
}
}

void loadOptionalContent(File const &packageFile)
void forOptionalContent(File const &packageFile,
std::function<void (String const &)> callback) const
{
// Packages enabled/disabled for use.
DictionaryValue const &selPkgs = Config::get()["fs.selectedPackages"]
Expand All @@ -323,9 +325,9 @@ DENG2_PIMPL(PackageLoader)
for (auto const *id : meta.geta("recommends").elements())
{
String const pkgId = id->asText();
if (isPackageSelected(pkgId, true) && !self.isLoaded(pkgId))
if (isPackageSelected(pkgId, true))
{
self.load(pkgId);
callback(pkgId);
}
}
}
Expand All @@ -334,14 +336,25 @@ DENG2_PIMPL(PackageLoader)
for (auto const *id : meta.geta("extras").elements())
{
String const pkgId = id->asText();
if (isPackageSelected(pkgId, false) && !self.isLoaded(pkgId))
if (isPackageSelected(pkgId, false))
{
self.load(pkgId);
callback(pkgId);
}
}
}
}

void loadOptionalContent(File const &packageFile)
{
forOptionalContent(packageFile, [this] (String const &pkgId)
{
if (!self.isLoaded(pkgId))
{
self.load(pkgId);
}
});
}

QList<Package *> loadedInOrder() const
{
QList<Package *> pkgs = loaded.values();
Expand Down Expand Up @@ -562,6 +575,27 @@ StringList PackageLoader::findAllPackages() const
return all;
}

StringList PackageLoader::expandDependencies(StringList const &packageIdentifiers) const
{
StringList expanded;
for (String pkgId : packageIdentifiers)
{
if (File const *file = select(pkgId))
{
for (String reqId : Package::requires(*file))
{
expanded << reqId;
}
d->forOptionalContent(*file, [&expanded] (String const &pkgId)
{
expanded << pkgId;
});
}
expanded << pkgId;
}
return expanded;
}

PackageLoader &PackageLoader::get()
{
return App::packageLoader();
Expand Down

0 comments on commit c850ccf

Please sign in to comment.