Adopt info from other metadata sources

:warning: Deprecated: This document has been superseded by Using external metadata

Some of the values required by the snapcraft.yaml file
might be already provided by other metadata sources available in the upstream
project.

Instead of duplicating this information, you can declare that a snapcraft part
must parse the metadata file from the source, and adopt that parsed
information. For example, the following snapcraft.yaml will parse the file
called metadata-file and try to extract from it the version, summary and
description for the snap.

name: my-snap-name
adopt-info: part-with-metadata

parts:
  part-with-metadata:
    plugin: dump
    parse-info: [metadata-file]

Metadata sources

Currently, the only supported source of metadata is appstream.

Appstream

Appstream is a standard
for metadata of software components. It can provide the summary,
description and icon for the snap, and the desktop files for the
apps.

Let’s say we have an upstream project with the following appstream file in
sampleapp.metainfo.xml:

<?xml version="1.0" encoding="UTF-8"?>
<component type="desktop-application">
  <id>com.example.sampleapp</id>
  <summary>Single-line elevator pitch for your amazing application</summary>
  <description>
    This is applications's description. A paragraph or two to tell the
    most important story about it.
  </description>
  <icon type="local">assets/icon.png</icon>
  <launchable type="desktop-id">
    com.example.sampleapp.desktop
  </launchable>
</component>

Then you can adopt this info into your snapcraft.yaml like this:

name: sampleapp-name
adopt-info: sampleapp

apps:
  sampleapp:
    command: sampleapp
    common-id: com.example.sampleapp

parts:
  sampleapp:
    plugin: dump
    source: http://github.com/example/sampleapp.git
    parse-info: [sampleapp.metainfo.xml]

The resulting snap will take the summary and description from the appstream
file and it will use the referred icon and desktop files.

Note that appstream doesn’t use a path to declare the desktop file. It uses
a Desktop File ID.
To know which appstream desktop-id corresponds to your app, you must declare
the common-id of the app in the snapcraft.yaml. snapcraft will search for a
parsed appstream file with the same component id and extract the desktop-id.
Then it will search for the desktop file in the directories usr/local/share
and usr/share relative to the part source, following the Desktop File ID
rules.

2 Likes

Can you add information about:

  • what version of snapcraft introduces this feature
  • turn this into a wiki
  • maybe consider splitting the intoduction topic and link it to a more specific appstream one to later be able to add e.g.; setup.py` without adding too much length to the document.
  • add the header as in the other documents that are candidates to be posted on our future docs site

Thanks for working on this!

This should probably also mention that the parse-info contains paths. From the given examples it looked to me that the files were being searched in the well-defined appstream paths of the stage, which isn’t actually the case.

So [usr/share/appdata/org.kde.foo.appinfo.xml] is needed rather than [org.kde.foo.appinfo.xml] when working with a file installed into the well-defined location.

Also, the first link is broken https://forum.snapcraft.io/build-snaps/syntax

1 Like

Is it possible to append additional info like security confinement information and unofficial package declaration etc?

Note: more up-to-date documentation is available at Using external metadata