Snapcraft parts metadata


#1

The main building blocks of a snap are parts. They are used to declare pieces of code that will be pulled into your snap package. The parts keys and values in snapcraft.yaml detail how parts are configured and built by the snapcraft command.

See Snapcraft top-level metadata and Snapcraft apps and services metadata for details on how apps and parts are configured within snapcraft.yaml.

Name Description
parts
 
A set of independent building blocks.
Type: dict
These independent building blocks are known as parts, and consist of either code or pre-built packages.
parts.<part-name>
 
The name of the part building block.
Type: dict
<part-name> represents the specific name of a building block which can be then referenced by the command line tool (i.e. snapcraft).

The following are keys that can be used within parts.<part-name> (for example, parts.<part-name>.plugin):

Name Description
plugin
 
The plugin to drive the build process.
Type: string
Every part drives its build through a plugin, this entry declares the plugin that will drive the build process for <part-name>. Refer to snapcraft plugins for more information on the available plugins and the specific attributes they add to the parts.<part-name>. namespace.
source
 
A URL or path to a source tree to build.
Type: string
This can be a local path or remote, and can refer to a directory tree, a compressed archive or a revision control repository. This entry supports additional syntax, for more information refer to Advanced grammar
source-type
 
Used when the type-of source entry cannot be detected.
Type: enum
Can be one of the following: [git|bzr|hg|svn|tar|deb|rpm|zip|7z]
source-checksum
 
Used when source represents a file.
Type: string
Takes the syntax <algorithm>/<digest>, where <algorithm> can be any of: md5, sha1, sha224, sha256, sha384, sha512, sha3_256, sha3_384 or sha3_512. When set, the source is cached for multiple uses in different snapcraft projects.
source-depth
 
Depth of history for sources using version control.
Type: integer
Source repositories under version control are cloned or checked out with full history. Specifying a depth will truncate the history to the specified number of commits.
source-branch
 
Work on a specific branch for source repositories under version control.
Type: string
source-commit
 
Work on a specific commit for source repositories under version control.
Type: string
source-tag
 
Work on a specific tag for source repositories under version control.
Type: string
source-subdir
 
A path within the source to set as the working directory when building.
Type: string
after
 
Ensures that all the <part-name>s listed in after are staged before this part begins its lifecycle.
Type: list[string]
build-snaps
 
A list of snap names to install that are necessary to build <part-name>.
Type: list[string]
If a specific channel is required, the syntax is of the form <snap-name>/<channel>. This entry supports additional syntax, for more information refer to Advanced grammar
build-packages
 
A list of packages required to build a snap.
Type: list[string]
Packages are installed using the host’s package manager, such as apt or dnf, and are required for <part-name> to build correctly. This entry supports additional syntax, for more information refer to Advanced grammar.
Example: [ libssl-dev, libssh-dev, libncursesw5-dev]
stage-packages
 
A list of packages required at runtime by a snap.
Type: list[string]
Packages are installed using the host’s package manager, such as apt or dnf, and are required by <part-name> to run. This entry supports additional syntax, for more information refer to Advanced grammar.
Example: [python-zope.interface, python-bcrypt]
organize
 
A map of files to rename.
Type: dict
In the key/value pair, the key represents the path of a file inside the part and the value represents how the file is going to be staged.
Example: bin/snapcraftctl: bin/scriptlet-bin/snapcraftctl.
filesets
 
A key to represent a group of files, or a single file.
See Snapcraft filesets for further details.
stage
 
A list of files from <part-name> to stage.
Type: list[string]
Rules applying to the list here are the same as those of filesets. Referencing of fileset keys is done with a $ prefixing the fileset key, which will expand with the value of such key.
prime
 
A list of files from <part-name> to prime.
list[string]
Rules applying to the list here are the same as those of filesets. Referencing of fileset keys is done with a $ prefixing the fileset key, which will expand with the value of such key.
prepare
 
Runs a script before the plugin’s build step.
Type: multiline string
The script is run before the build step defined for parts.<part-name>.plugin starts. The working directory is the base build directory for the given part. The defined script is run with /bin/sh and set -e. A set of Environment Variables will be available to the script.
build
 
Replaces a plugin’s default build process with a script.
Type: multiline string
The shell script defined here replaces the build step of the plugin, defined in parts.<part-name>.plugin starts. The working directory is the base build directory for the given part. The defined script is run with /bin/sh and set -e. A set of Environment Variables will be available to the script.
install
 
Runs a script after the plugin’s build step.
Type: multiline string
The shell script defined here is run after the build step of the plugin defined in parts.<part-name>.plugin starts. The working directory is the base build directory for the given part. The defined script is run with /bin/sh and set -e. A set of Environment Variables will be available to the script.
build-attributes
 
A list of named attributes to modify the behaviour of plugins.
Type: enum
For more information, refer to Snapcraft plugins.

The scons plugin
The qmake plugin
The meson plugin
The make plugin
The cmake plugin
The autotools plugin
The rust plugin
The ruby plugin
Snapcraft filesets
The python plugin
The nodejs plugin
The gulp plugin
The jdk plugin
The ant plugin
The godeps plugin
The go plugin
The snapcraft format
The dotnet plugin
Snapcraft overview
The plainbox-provider plugin
The catkin plugin
The ament plugin
The kernel plugin
The waf plugin
#2

I would like to ask about more info of the build-attributes key, from snapcraft help plugins:

  - build-attributes: [attribute1, attribute2]

    A list of special attributes that affect the build of this specific part.
    Supported attributes:

      - no-system-libraries:
        Do not automatically copy required libraries from the system to satisfy
        the dependencies of this part. This might be useful if one knows these
        dependencies will be satisfied in other manner, e.g. via content
        sharing from other snaps.

      - no-install:
        Do not run the install target provided by the plugin's build system.

        Supported by: kbuild

      - debug:
        Plugins that support the concept of build types build in Release mode
        by default. Setting the 'debug' attribute requests that they instead
        build in Debug mode.