Staging a .desktop and icon from a part repo into meta/gui

One of the parts of my snap contains a .desktop and icon which I want to re-use inside the snap instead of duplicating it. Currently I have a part like this:

pulseview:
source-type: git
source: https://git.launchpad.net/~a-j-buxton/sigrok-snap-test/+git/pulseview
plugin: cmake
after: [libsigrokdecode, desktop-qt5]

How should I copy the files I need into the snap? I also need to run the .desktop through sed to fix paths.

The problem is that the files only exist in the source directory. Not the build directory, and not the install directory.

Last we discussed the plan was to have snapcraft copying such content automatically out of snap/.

@sergiusens How’s that going?

Copying the content out of snap/ (used to be setup/) works fine. The problem is that the content isn’t in snap/, and I don’t want to duplicate it there.

Ah, sorry… my memory probably fails me. I think we already have entries in snapcraft.yaml which allow pointing to an existing source path. Sergio will know the details for sure.

I tried this but it did not work. The files were not put into the final snap:

  pulseview:
    source-type: git
    source: https://git.launchpad.net/~a-j-buxton/sigrok-snap-test/+git/pulseview
    plugin: cmake
    after: [libsigrokdecode, desktop-qt5]
    install: |
        mkdir -p $SNAPCRAFT_PART_INSTALL/meta/gui/
        sed -e 's|^Exec=pulseview$|^Exec=$SNAP.pulseview$|g' -e 's|^Icon=sigrok-logo-notext$|^Icon=${SNAP}/meta/gui/sigrok-logo-notext.svg$|g' ../src/contrib/pulseview.desktop > $SNAPCRAFT_PART_INSTALL/meta/gui/pulseview.desktop
        cp ../src/icons/sigrok-logo-notext.svg $SNAPCRAFT_PART_INSTALL/meta/gui/

I tried this, and now the svg file gets copied into the snap but the .desktop does not:

  pulseview:
    source-type: git
    source: https://git.launchpad.net/~a-j-buxton/sigrok-snap-test/+git/pulseview
    plugin: cmake
    after: [libsigrokdecode, desktop-qt5]
    install: |
        mkdir -p $SNAPCRAFT_PART_INSTALL/meta/gui/
        sed -e 's|^Exec=pulseview$|^Exec=$SNAP.pulseview$|g' -e 's|^Icon=sigrok-logo-notext$|^Icon=${SNAP}/meta/gui/sigrok-logo-notext.svg$|g' ../src/contrib/pulseview.desktop > $SNAPCRAFT_PART_INSTALL/meta/gui/pulseview.desktop
        cp ../src/icons/sigrok-logo-notext.svg $SNAPCRAFT_PART_INSTALL/meta/gui/
    stage:
        - meta

I also tried using “prime” keyword instead of “stage” and it did the same thing. In both cases both files end up in stage/ but not prime/

The interesting thing about this is that snapcraft seems to think that my syntax should result in pulseview.desktop existing in the prime directory, because if I try to clean the prime step I get this error:

al@al-desktop:~/Source/sigrok-snap-test$ snapcraft clean pulseview -s prime
"grade" property not specified: defaulting to "stable"
Cleaning priming area for pulseview 
[Errno 2] No such file or directory: '/home/al/Source/sigrok-snap-test/prime/meta/gui/pulseview.desktop'

ie snapcraft thinks the file should exist according to snapcraft.yaml, and then crashes because it does not. I have reported this bug here: https://bugs.launchpad.net/ubuntu/+source/snapcraft/+bug/1690139

Correct, there is a desktop entry, was added in 2.25 as described here https://github.com/snapcore/snapcraft/releases/tag/2.25

I’ll need to take an action to figure out if this made it to the docs and if not post something here (if someone else doesn’t beat me to it :wink:)

you can now declare a desktop file from your app within an apps entry using a path relative to the prime directory pointing to a desktop file

In this case the .desktop file only exists in the source directory.

Then you can do something like:

parts:
  partX:
    ...
    install:
      cp <rel-path-to-desktop-file.desktop> $SNAPCRAFT_PART_INSTALL/desktop.desktop
...
...
apps:
  appX:
    ...
    desktop: desktop.desktop
2 Likes