Write a check for desktop file naming standards.
Open, Needs TriagePublic

Description

[05:54] <mgraesslin> sitter: you did such a nice test for symlinks in icon themes - I was wondering how difficult it would be to have a test that a desktop file name needs to be org.kde.<binaryname>
[05:59] <sitter> shouldn't be too difficult should it? for the most part I think it's just a matter of assuming Exec==binaryname. rolling a that out across all builds could be tricky though (as in: I have no clue how onw would do that xD)
[06:00] <mgraesslin> yeah I guess that's the tricky part
[06:00] <mgraesslin> maybe need to talk to alex merry about it
[06:00] <mgraesslin> ideally I would like to have that directly in ECM so that we can check in build system
[06:03] <sitter> I agree. alas, I think to get that done through ECM we'd either need a macro which then is easily bypassed by not using the macro. So perhaps doing this through Jenkins or the ci scripting would be better as that would make it unavoidable and cover everything we CI regardless of whether $thing even uses ECM (think kdelibs4 software that is in no rush to port)

scarlettclark updated the task description. (Show Details)
scarlettclark raised the priority of this task from to Needs Triage.
scarlettclark claimed this task.
scarlettclark added a project: build.kde.org.
scarlettclark moved this task to Backlog on the build.kde.org board.

Feel free to add thoughts and ideas.

If I am reading this correctly, you want a global test that checks desktop files and verifies the filename matches the Exec= line?
And I presume you want it to mark unstable if not?

Yes. Check if desktop file has a suitable name, if not mark build unstable.

Regarding the actual check logic I think it needs to look something like this:

foreach file in $PREFIX/share/applications/* (and subdirs):

  • get Exec field
  • run Exec field through a spec compliant parser [1] like KIO::DesktopExecParser to retrieve the command and get rid of command options. if not possible a shell cmdline parser would suffice. if also not possible splitting by whitespace may well be enough for most of our software (i.e. in theory that only fails if PREFIX or the binary name has a space)
  • get the filename of the command (i.e. remove a possible directory path: Exec=/usr/bin/kitten -> kitten)
  • assert that the filename prepended with org.kde and appended with .desktop is the name of the desktop file (e.g. kitten == org.kde.kitten.desktop)

[1] http://standards.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html#exec-variables

There's one more thing to consider: we have in KF 5.16 a new --desktopfile command line switch. If that one is used the file name is also valid even if the binary name doesn't match desktop file name.

Ah, so I guess space splitting the Exec won't be too reliable. Shell cmdline parser is at least required to correctly process the Exec in this case. Revised algorithm:

foreach file in $PREFIX/share/applications/* (and subdirs):

  • get Exec field
  • run Exec field through a spec compliant parser [1] like KIO::DesktopExecParser to retrieve the command and arguments. if not possible a shell cmdline parser would suffice.
  • if the arguments include a --desktopfile argument:
    • assert that there is a parameter for the argument (possibly enforce that it starts with org.kde.?)
  • else:
    • get the filename of the command (i.e. remove a possible directory path: Exec=/usr/bin/kitten -> kitten)
    • assert that the filename prepended with org.kde and appended with .desktop is the name of the desktop file (e.g. kitten == org.kde.kitten.desktop)

Is this something we still need to look into?
(Seems this ticket got forgotten about at the back of the CI task queue)

Restricted Application added a subscriber: sysadmin. · View Herald TranscriptMar 25 2018, 3:39 AM

Yes. I think anyway.

The detection got a bit more complicated meanwhile. Developers can now also set the name programmatically via KAboutData::setDesktopFileName, so I suppose https://phabricator.kde.org/T1051#12151 ought to be prefixed with a grep on setDesktopFileName and be skipped entirely if the the method appears to be called. Although now that I spelt that out, it seems a bit meh. Perhaps a better way to do it is a custom desktop entry X-KDE-CustomDesktopFileName=org.kde.myNameSoPeopleDontCopyTheFileWithThisMarkerAndAccidentlySkipTheCheck which a dev needs to set to silence the CI warning when using setDesktopFileName from c++. Food for thought I suppose.

@graesslin I do wonder if this should maybe be a tool installed by kaboutdata to validate desktop files and then simply be used by the CI.

At any rate, new algorithm as I see it:

foreach file in $PREFIX/share/applications/* (and subdirs):

  • if X-KDE-CustomDesktopFileName field is set:
    • assert its value is the basename of the desktop file
  • else:
    • get Exec field
    • run Exec field through a spec compliant parser [1] like KIO::DesktopExecParser to retrieve the command and arguments. if not possible a shell cmdline parser would suffice.
    • if the arguments include a --desktopfile argument:
      • assert that there is a parameter for the argument (possibly enforce that it starts with org.kde.?)
    • else:
      • get the filename of the command (i.e. remove a possible directory path: Exec=/usr/bin/kitten -> kitten)
      • assert that the filename prepended with org.kde and appended with .desktop is the name of the desktop file (e.g. kitten == org.kde.kitten.desktop)

Given that a spec compliant parser is required to do this validation (to the most reliable standard) I agree that a tool shipped alongside KAboutData/KIO might be the best way to go about handling this.

Of course, the Python shlex module might also work given that all we need to do is split it and check to see if one of the parameters is '--desktopfile', with the next one being our desktop file name.

Thoughts?

scarlettclark removed scarlettclark as the assignee of this task.Apr 26 2018, 12:35 PM

@sitter Any view on my response above?

Both approaches sound reasonable really. Seeing as the actual validation that needs to be carried out a dumb parser is probably just as fine as a spec compliant one.