D21305: Add the FreeBSD default-path for os-release.

Adriaan de Groot noreply at phabricator.kde.org
Mon May 20 14:11:21 BST 2019


adridg created this revision.
adridg added a reviewer: sitter.
Herald added a project: Frameworks.
Herald added a subscriber: kde-frameworks-devel.
adridg requested review of this revision.

REVISION SUMMARY
  - After much hemming and hawing we ended up with /usr/local/etc/os-release, which isn't one of the standard paths (according to freedesktop.org) so in spite of us **having** the file, not all software that looks for it will find it. Patch in the correct path.
  - Patching in the correct path in the original code inserted #ifdefs that interact really badly with the existing code-layout.
  - Switch to iterating over a constant list; with Clang and -O3 this yields slightly smaller code compared to the original. This code is also much easier to #ifdef for specific needs (e.g. for NetBSD and OpenBSD).

TEST PLAN
  - Included in downstream packaging.
  - Test for functionality: ```
  
  #include <kosrelease.h>
  #include <QDebug>
  
  static void derp(const QString& s)
  {
  
    qDebug() << s;
    
    KOSRelease r(s);
    qDebug() << "  name" << r.name() 
        << "\n  version" << r.version();
  
  }
  
  int main(int argc, char **argv)
  {
  
    derp(QString());
    derp("/usr/local/etc/os-release");
    
    return 0;
  
  }
  
    - Test for code size:
      
  
  #include <QtCore/QFile>
  #include <QtCore/QString>
  
  QString defaultFilePath()
  {
  #ifdef ONE
  
    if (QFile::exists(QStringLiteral("/etc/os-release"))) {
        return QStringLiteral("/etc/os-release");
    } else if (QFile::exists(QStringLiteral("/usr/lib/os-release"))) {
        return QStringLiteral("/usr/lib/os-release");
    } else {
        return QString();
    }
  
  #endif
  #ifdef TWO
  
    for (const auto& path : { 
        QStringLiteral("/etc/os-release"),
        QStringLiteral("/usr/lib/os-release")
        }) {
        if (QFile::exists(path)) {
            return path;
        }
    }
    return QString();
  
  #endif
  }

REPOSITORY
  R244 KCoreAddons

BRANCH
  master

REVISION DETAIL
  https://phabricator.kde.org/D21305

AFFECTED FILES
  src/lib/util/kosrelease.cpp

To: adridg, sitter
Cc: kde-frameworks-devel, michaelh, ngraham, bruns
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/kde-frameworks-devel/attachments/20190520/9f7c41cc/attachment.html>


More information about the Kde-frameworks-devel mailing list