diff --git a/board-mappings.ini b/board-mappings.ini index 4365374..43040f5 100644 --- a/board-mappings.ini +++ b/board-mappings.ini @@ -24,14 +24,32 @@ # The found model (after resolving variants) will be used as category. The # following keys are valid there: # - family -- the device family, used for the family specific adaptation -# - adaptations -- list of additional adaptations, shared between families +# - adaptation-repos -- list of adaptation repositories for this family # -# The value of adaptations gets converted into a QStringList, which uses -# commas as separator. If one of the adaptation names contains a comma it -# needs to be quoted: -# adaptation=foo -# adaptation="foo, bar", baz -# adaptation=foo, bar, baz +# The value of adaptation-repos gets converted into a QStringList, which +# uses commas as separator. If one of the adaptation names contains a comma +# it needs to be quoted: +# adaptation-repos=foo +# adaptation-repos="foo, bar", baz +# adaptation-repos=foo, bar, baz +# +# The adaptation list is used to create repo files for adaptation repos. +# A repository named 'adaptation0' operates on the first list element, +# 'adaptation2' on the 3rd, etc. The matching item in the list will be +# exported as adaptation variable. +# +# Freeform variable sections start with 'var-'. A variable section for an +# adaptation named 'n9xx' would be 'var-n9xx'. A variable section may +# contain freeform variables, or the keyword 'variables' to include any +# other section. Currently only one section may be included, and you may +# not specify additional variables: +# +# [var-n9] +# foo=bar +# bar=baz +# +# [var-n950] +# variables=n9 # # The N9x mappings should be solved through sysinfo, but that's currently # broken on Mer/Nemo @@ -54,17 +72,17 @@ N950=N9 [N9] family=n950-n9 -adaptations=n9xx +adaptation-repos=n9xx-common,n950-n9 [N900] family=n900 -adaptations=n9xx +adaptation-repos=n9xx-common,n900 [SDK] [generic-x86] family=x86 -adaptations=x86 +adaptation-repos=x86 [UNKNOWN] family=UNKNOWN diff --git a/libssu/ssu.cpp b/libssu/ssu.cpp index c68e9f6..7a2dc8e 100644 --- a/libssu/ssu.cpp +++ b/libssu/ssu.cpp @@ -153,6 +153,7 @@ QString Ssu::repoUrl(QString repoName, bool rndRepo, QHash rep QString r; QStringList configSections; SsuVariables var; + SsuLog *ssuLog = SsuLog::instance(); errorFlag = false; @@ -181,19 +182,57 @@ QString Ssu::repoUrl(QString repoName, bool rndRepo, QHash rep if (!repoParameters.contains("arch")) repoParameters.insert("arch", settings->value("arch").toString()); - repoParameters.insert("adaptation", settings->value("adaptation").toString()); + // todo: allow override of deviceModel for cli url resolving + QStringList adaptationRepos = deviceInfo.adaptationRepos(); + + // read adaptation from settings, in case it can't be determined from + // board mappings. this is obsolete, and will be dropped soon + if (settings->contains("adaptation")) + repoParameters.insert("adaptation", settings->value("adaptation").toString()); + repoParameters.insert("deviceFamily", deviceInfo.deviceFamily()); repoParameters.insert("deviceModel", deviceInfo.deviceModel()); + // Those keys have now been obsoleted by generic variables, support for + // it will be removed soon QStringList keys; keys << "chip" << "adaptation" << "vendor"; - foreach(QString key, keys){ QString value; if (deviceInfo.getValue(key,value)) repoParameters.insert(key, value); } + // special handling for adaptation-repositories + // - check if repo is in right format (adaptation\d*) + // - check if the configuration has that many adaptation repos + // - export the entry in the adaptation list as %(adaptation) + // - look up variables for that adaptation, and export matching + // adaptation variable + QRegExp regex("adaptation\\\d*", Qt::CaseSensitive, QRegExp::RegExp2); + if (regex.exactMatch(repoName)){ + regex.setPattern("\\\d*"); + regex.lastIndexIn(repoName); + int n = regex.cap().toInt(); + + if (adaptationRepos.size() > n) { + QString adaptationRepo = adaptationRepos.at(n); + repoParameters.insert("adaptation", adaptationRepo); + ssuLog->print(LOG_DEBUG, "Found first adaptation " + repoName); + + QHash h = deviceInfo.variableSection(adaptationRepo); + + QHash::const_iterator i = h.constBegin(); + while (i != h.constEnd()){ + repoParameters.insert(i.key(), i.value()); + i++; + } + } else + ssuLog->print(LOG_INFO, "Note: adaptation repo for invalid repo requested " + repoName); + + repoName = "adaptation"; + } + // Domain variables // first read all variables from default-domain var.resolveSection(repoSettings, "default-domain", &repoParameters); diff --git a/libssu/ssudeviceinfo.cpp b/libssu/ssudeviceinfo.cpp index 21b5801..cb0fb4e 100644 --- a/libssu/ssudeviceinfo.cpp +++ b/libssu/ssudeviceinfo.cpp @@ -20,18 +20,28 @@ SsuDeviceInfo::SsuDeviceInfo(): QObject(){ boardMappings = new SsuSettings(SSU_BOARD_MAPPING_CONFIGURATION, SSU_BOARD_MAPPING_CONFIGURATION_DIR); } -QString SsuDeviceInfo::deviceFamily(){ - QString model = deviceModel(); +QStringList SsuDeviceInfo::adaptationRepos(){ + QStringList result; + + QString model = deviceVariant(); + if (model == "") + model = deviceModel(); + + if (boardMappings->contains(model + "/adaptation-repos")) + result = boardMappings->value(model + "/adaptation-repos").toStringList(); + return result; +} + +QString SsuDeviceInfo::deviceFamily(){ if (!cachedFamily.isEmpty()) return cachedFamily; - cachedFamily = "UNKNOWN"; + QString model = deviceVariant(); + if (model == "") + model = deviceModel(); - if (boardMappings->contains("variants/" + model)) { - model = boardMappings->value("variants/" + model).toString(); - cachedVariant = model; - } + cachedFamily = "UNKNOWN"; if (boardMappings->contains(model + "/family")) cachedFamily = boardMappings->value(model + "/family").toString(); @@ -143,6 +153,28 @@ QString SsuDeviceInfo::deviceUid(){ return IMEI; } +QHash SsuDeviceInfo::variableSection(QString section){ + QHash result; + + if (!section.startsWith("var-")) + section = "var-" + section; + + if (boardMappings->contains(section + "/variables")){ + return variableSection(boardMappings->value(section + "/variables").toString()); + } + + boardMappings->beginGroup(section); + if (boardMappings->group() != section) + return result; + + QStringList keys = boardMappings->allKeys(); + foreach (const QString &key, keys){ + result.insert(key, boardMappings->value(key).toString()); + } + + return result; +} + bool SsuDeviceInfo::getValue(const QString& key, QString& value){ if (boardMappings->contains(deviceVariant()+"/"+key)){ value = boardMappings->value(deviceVariant()+"/"+key).toString(); @@ -154,3 +186,13 @@ bool SsuDeviceInfo::getValue(const QString& key, QString& value){ } return false; } + +void SsuDeviceInfo::setDeviceModel(QString model){ + if (model == "") + cachedModel = ""; + else + cachedModel = model; + + cachedFamily = ""; + cachedVariant = ""; +} diff --git a/libssu/ssudeviceinfo.h b/libssu/ssudeviceinfo.h index 39cba5e..5e37cfd 100644 --- a/libssu/ssudeviceinfo.h +++ b/libssu/ssudeviceinfo.h @@ -18,6 +18,10 @@ class SsuDeviceInfo: public QObject { public: SsuDeviceInfo(); + /** + * Return the list of adaptations used for the set model + */ + QStringList adaptationRepos(); /** * Try to find the device family for the system this is running on */ @@ -35,7 +39,19 @@ class SsuDeviceInfo: public QObject { * @return QSystemDeviceInfo::imei(), if available, or QSystemDeviceInfo::uniqueDeviceID() */ Q_INVOKABLE QString deviceUid(); + /** + * Override device model autodetection + */ + Q_INVOKABLE void setDeviceModel(QString model=""); + /** + * Return the requested variable section. 'var-' is automatically + * prepended to the section name if not specified already. + */ + QHash variableSection(QString section); + /** + * Get a key from an adaptation section. Deprecated, don't use. + */ bool getValue(const QString& key, QString& value); private: diff --git a/rpm/ssu.changes b/rpm/ssu.changes index 1421054..b22a2e8 100644 --- a/rpm/ssu.changes +++ b/rpm/ssu.changes @@ -1,3 +1,6 @@ +* Wed Mar 27 2013 Bernd Wachter - 0.26 +- Take all adaptations from adaptation-repos list, allow freeform variables for adaptations + * Fri Mar 22 2013 Bernd Wachter - 0.25 - Add variable substitution diff --git a/rpm/ssu.spec b/rpm/ssu.spec index f59c7a3..d633925 100644 --- a/rpm/ssu.spec +++ b/rpm/ssu.spec @@ -1,5 +1,5 @@ Name: ssu -Version: 0.25 +Version: 0.26 Release: 1 Summary: SSU enabler for RND Group: System/Base