feat: support multiarch system classifiers
Signed-off-by: Sefa Eyeoglu <contact@scrumplex.net>
This commit is contained in:
@ -112,9 +112,9 @@ QList<NetAction::Ptr> Library::getDownloads(
|
||||
{
|
||||
if(isNative())
|
||||
{
|
||||
if(m_nativeClassifiers.contains(runtimeContext.currentSystem()))
|
||||
auto nativeClassifier = getCompatibleNative(runtimeContext);
|
||||
if(!nativeClassifier.isNull())
|
||||
{
|
||||
auto nativeClassifier = m_nativeClassifiers[runtimeContext.currentSystem()];
|
||||
if(nativeClassifier.contains("${arch}"))
|
||||
{
|
||||
auto nat32Classifier = nativeClassifier;
|
||||
@ -215,7 +215,7 @@ bool Library::isActive(const RuntimeContext & runtimeContext) const
|
||||
RuleAction ruleResult = Disallow;
|
||||
for (auto rule : m_rules)
|
||||
{
|
||||
RuleAction temp = rule->apply(this);
|
||||
RuleAction temp = rule->apply(this, runtimeContext);
|
||||
if (temp != Defer)
|
||||
ruleResult = temp;
|
||||
}
|
||||
@ -223,7 +223,7 @@ bool Library::isActive(const RuntimeContext & runtimeContext) const
|
||||
}
|
||||
if (isNative())
|
||||
{
|
||||
result = result && m_nativeClassifiers.contains(runtimeContext.currentSystem());
|
||||
result = result && !getCompatibleNative(runtimeContext).isNull();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@ -238,6 +238,19 @@ bool Library::isAlwaysStale() const
|
||||
return m_hint == "always-stale";
|
||||
}
|
||||
|
||||
QString Library::getCompatibleNative(const RuntimeContext & runtimeContext) const {
|
||||
// try to match precise classifier "[os]-[arch]"
|
||||
auto entry = m_nativeClassifiers.constFind(runtimeContext.getClassifier());
|
||||
// try to match imprecise classifier on legacy architectures "[os]"
|
||||
if (entry == m_nativeClassifiers.constEnd() && runtimeContext.isLegacyArch())
|
||||
entry = m_nativeClassifiers.constFind(runtimeContext.system);
|
||||
|
||||
if (entry == m_nativeClassifiers.constEnd())
|
||||
return QString();
|
||||
|
||||
return entry.value();
|
||||
}
|
||||
|
||||
void Library::setStoragePrefix(QString prefix)
|
||||
{
|
||||
m_storagePrefix = prefix;
|
||||
@ -271,9 +284,10 @@ QString Library::filename(const RuntimeContext & runtimeContext) const
|
||||
|
||||
// otherwise native, override classifiers. Mojang HACK!
|
||||
GradleSpecifier nativeSpec = m_name;
|
||||
if (m_nativeClassifiers.contains(runtimeContext.currentSystem()))
|
||||
QString nativeClassifier = getCompatibleNative(runtimeContext);
|
||||
if (!nativeClassifier.isNull())
|
||||
{
|
||||
nativeSpec.setClassifier(m_nativeClassifiers[runtimeContext.currentSystem()]);
|
||||
nativeSpec.setClassifier(nativeClassifier);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -299,9 +313,10 @@ QString Library::storageSuffix(const RuntimeContext & runtimeContext) const
|
||||
|
||||
// otherwise native, override classifiers. Mojang HACK!
|
||||
GradleSpecifier nativeSpec = m_name;
|
||||
if (m_nativeClassifiers.contains(runtimeContext.currentSystem()))
|
||||
QString nativeClassifier = getCompatibleNative(runtimeContext);
|
||||
if (!nativeClassifier.isNull())
|
||||
{
|
||||
nativeSpec.setClassifier(m_nativeClassifiers[runtimeContext.currentSystem()]);
|
||||
nativeSpec.setClassifier(nativeClassifier);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -3,6 +3,7 @@
|
||||
#include <net/NetAction.h>
|
||||
#include <QPair>
|
||||
#include <QList>
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
#include <QMap>
|
||||
#include <QDir>
|
||||
@ -155,6 +156,8 @@ public: /* methods */
|
||||
QList<NetAction::Ptr> getDownloads(const RuntimeContext & runtimeContext, class HttpMetaCache * cache,
|
||||
QStringList & failedLocalFiles, const QString & overridePath) const;
|
||||
|
||||
QString getCompatibleNative(const RuntimeContext & runtimeContext) const;
|
||||
|
||||
private: /* methods */
|
||||
/// the default storage prefix used by PolyMC
|
||||
static QString defaultStoragePrefix();
|
||||
|
@ -37,7 +37,7 @@ class Rule
|
||||
{
|
||||
protected:
|
||||
RuleAction m_result;
|
||||
virtual bool applies(const Library *parent) = 0;
|
||||
virtual bool applies(const Library *parent, const RuntimeContext & runtimeContext) = 0;
|
||||
|
||||
public:
|
||||
Rule(RuleAction result) : m_result(result)
|
||||
@ -45,9 +45,9 @@ public:
|
||||
}
|
||||
virtual ~Rule() {};
|
||||
virtual QJsonObject toJson() = 0;
|
||||
RuleAction apply(const Library *parent)
|
||||
RuleAction apply(const Library *parent, const RuntimeContext & runtimeContext)
|
||||
{
|
||||
if (applies(parent))
|
||||
if (applies(parent, runtimeContext))
|
||||
return m_result;
|
||||
else
|
||||
return Defer;
|
||||
@ -63,9 +63,9 @@ private:
|
||||
QString m_version_regexp;
|
||||
|
||||
protected:
|
||||
virtual bool applies(const Library *)
|
||||
virtual bool applies(const Library *, const RuntimeContext & runtimeContext)
|
||||
{
|
||||
return (m_system == RuntimeContext::currentSystem());
|
||||
return runtimeContext.classifierMatches(m_system);
|
||||
}
|
||||
OsRule(RuleAction result, QString system, QString version_regexp)
|
||||
: Rule(result), m_system(system), m_version_regexp(version_regexp)
|
||||
@ -84,7 +84,7 @@ public:
|
||||
class ImplicitRule : public Rule
|
||||
{
|
||||
protected:
|
||||
virtual bool applies(const Library *)
|
||||
virtual bool applies(const Library *, const RuntimeContext & runtimeContext)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
Reference in New Issue
Block a user