Skip to content

Commit

Permalink
libcore|PackageLoader: Load required packages automatically
Browse files Browse the repository at this point in the history
The "requires" array specifies all the packages that must be loaded
before a package can be successfully loaded.
  • Loading branch information
skyjake committed Apr 3, 2016
1 parent 2f4f4a8 commit 5ac44ce
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
4 changes: 4 additions & 0 deletions doomsday/sdk/libcore/include/de/filesys/package.h
Expand Up @@ -168,6 +168,10 @@ class DENG2_PUBLIC Package : public IObject

static QStringList tags(File const &packageFile);

static QStringList tags(String const& tagsString);

static StringList requires(File const &packageFile);

/**
* Splits a string containing a package identifier and version. The
* expected format of the string is `{packageId}_{version}`.
Expand Down
22 changes: 20 additions & 2 deletions doomsday/sdk/libcore/src/filesys/package.cpp
Expand Up @@ -31,6 +31,7 @@ String const Package::VAR_PACKAGE("package");

static String const PACKAGE_ORDER("package.__order__");
static String const PACKAGE_IMPORT_PATH("package.importPath");
static String const PACKAGE_REQUIRES("package.requires");

static String const VAR_ID("ID");
static String const VAR_PATH("path");
Expand Down Expand Up @@ -328,8 +329,25 @@ Record &Package::initializeMetadata(File &packageFile, String const &id)

QStringList Package::tags(File const &packageFile)
{
return packageFile.objectNamespace().gets("package.tags")
.split(' ', QString::SkipEmptyParts);
return tags(packageFile.objectNamespace().gets(QStringLiteral("package.tags")));
}

QStringList Package::tags(String const &tagsString)
{
return tagsString.split(' ', QString::SkipEmptyParts);
}

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;
}

static String stripAfterFirstUnderscore(String str)
Expand Down
15 changes: 15 additions & 0 deletions doomsday/sdk/libcore/src/filesys/packageloader.cpp
Expand Up @@ -201,6 +201,10 @@ DENG2_PIMPL(PackageLoader)
loaded[packageId]->objectNamespace().gets("path") + "\"");
}

// Loads all the packages listed as required for this package. Throws an
// exception is any are missing.
loadRequirements(source);

Package *pkg = new Package(source);
loaded.insert(packageId, pkg);
pkg->setOrder(loadCounter++);
Expand Down Expand Up @@ -265,6 +269,17 @@ DENG2_PIMPL(PackageLoader)
}
}

void loadRequirements(File const &packageFile)
{
for(String const &reqId : Package::requires(packageFile))
{
if(!self.isLoaded(reqId))
{
self.load(reqId);
}
}
}

DENG2_PIMPL_AUDIENCE(Activity)
DENG2_PIMPL_AUDIENCE(Load)
DENG2_PIMPL_AUDIENCE(Unload)
Expand Down

0 comments on commit 5ac44ce

Please sign in to comment.