Skip to content

Commit

Permalink
feat(linux): add slots option for snap builds (#5047)
Browse files Browse the repository at this point in the history
Allow applications to expose slots when installed via snap on linux. This is needed for example in applications that want to implement the MPRIS interface to allow external media player control.
  • Loading branch information
ponyfleisch authored Jul 9, 2020
1 parent 70a0b80 commit e87bd28
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 0 deletions.
18 changes: 18 additions & 0 deletions packages/app-builder-lib/scheme.json
Original file line number Diff line number Diff line change
Expand Up @@ -4456,6 +4456,24 @@
],
"description": "The list of [plugs](https://snapcraft.io/docs/reference/interfaces).\nDefaults to `[\"desktop\", \"desktop-legacy\", \"home\", \"x11\", \"unity7\", \"browser-support\", \"network\", \"gsettings\", \"audio-playback\", \"pulseaudio\", \"opengl\"]`.\n\nIf list contains `default`, it will be replaced to default list, so, `[\"default\", \"foo\"]` can be used to add custom plug `foo` in addition to defaults.\n\nAdditional attributes can be specified using object instead of just name of plug:\n```\n[\n {\n \"browser-sandbox\": {\n \"interface\": \"browser-support\",\n \"allow-sandbox\": true\n },\n },\n \"another-simple-plug-name\"\n]\n```"
},
"slots": {
"anyOf": [
{
"items": {
"anyOf": [
{
"type": "string"
}
]
},
"type": "array"
},
{
"type": "null"
}
],
"description": "The list of [slots](https://snapcraft.io/docs/reference/interfaces)."
},
"publish": {
"anyOf": [
{
Expand Down
5 changes: 5 additions & 0 deletions packages/app-builder-lib/src/options/SnapOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ export interface SnapOptions extends CommonLinuxOptions, TargetSpecificOptions {
*/
readonly plugs?: Array<string | PlugDescriptor> | PlugDescriptor | null

/**
* The list of [slots](https://snapcraft.io/docs/reference/interfaces).
*/
readonly slots?: Array<string> | null

/**
* Specifies any [parts](https://snapcraft.io/docs/reference/parts) that should be built before this part.
* Defaults to `["desktop-gtk2""]`.
Expand Down
4 changes: 4 additions & 0 deletions packages/app-builder-lib/src/targets/snap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ export default class SnapTarget extends Target {
adapter: "none",
}

if (options.slots != null) {
appDescriptor.slots = options.slots
}

const snap: any = safeLoad(await readFile(path.join(getTemplatePath("snap"), "snapcraft.yaml"), "utf-8"))
if (this.isUseTemplateApp) {
delete appDescriptor.adapter
Expand Down
73 changes: 73 additions & 0 deletions test/snapshots/linux/snapTest.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1508,6 +1508,79 @@ Object {
}
`;

exports[`slots option 1`] = `
Object {
"apps": Object {
"sep": Object {
"command": "command.sh",
"environment": Object {
"DISABLE_WAYLAND": "1",
"LD_LIBRARY_PATH": "$SNAP_LIBRARY_PATH:$SNAP/lib:$SNAP/usr/lib:$SNAP/lib/x86_64-linux-gnu:$SNAP/usr/lib/x86_64-linux-gnu:$LD_LIBRARY_PATH:$SNAP/lib:$SNAP/usr/lib:$SNAP/lib/x86_64-linux-gnu:$SNAP/usr/lib/x86_64-linux-gnu",
"PATH": "$SNAP/usr/sbin:$SNAP/usr/bin:$SNAP/sbin:$SNAP/bin:$PATH",
"SNAP_DESKTOP_RUNTIME": "$SNAP/gnome-platform",
"TMPDIR": "$XDG_RUNTIME_DIR",
},
"plugs": Array [
"desktop",
"desktop-legacy",
"home",
"x11",
"wayland",
"unity7",
"browser-support",
"network",
"gsettings",
"audio-playback",
"pulseaudio",
"opengl",
],
"slots": Array [
"foo",
"bar",
],
},
},
"architectures": Array [
"amd64",
],
"base": "core18",
"confinement": "strict",
"description": "Test Application (test quite “ #378)",
"grade": "stable",
"name": "sep",
"plugs": Object {
"gnome-3-28-1804": Object {
"default-provider": "gnome-3-28-1804",
"interface": "content",
"target": "$SNAP/gnome-platform",
},
"gtk-3-themes": Object {
"default-provider": "gtk-common-themes",
"interface": "content",
"target": "$SNAP/data-dir/themes",
},
"icon-themes": Object {
"default-provider": "gtk-common-themes",
"interface": "content",
"target": "$SNAP/data-dir/icons",
},
"sound-themes": Object {
"default-provider": "gtk-common-themes",
"interface": "content",
"target": "$SNAP/data-dir/sounds",
},
},
"summary": "Sep",
"version": "1.1.0",
}
`;

exports[`slots option 2`] = `
Object {
"linux": Array [],
}
`;

exports[`snap 1`] = `
Object {
"linux": Array [
Expand Down
17 changes: 17 additions & 0 deletions test/src/linux/snapTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,23 @@ test.ifDevOrLinuxCi("plugs option", async () => {
}
})

test.ifDevOrLinuxCi("slots option", app({
targets: Platform.LINUX.createTarget("snap"),
config: {
extraMetadata: {
name: "sep",
},
productName: "Sep",
snap: {
slots: [ "foo", "bar" ],
}
},
effectiveOptionComputed: async ({snap}) => {
expect(snap).toMatchSnapshot()
return true
},
}))

test.ifDevOrLinuxCi("custom env", app({
targets: Platform.LINUX.createTarget("snap"),
config: {
Expand Down

0 comments on commit e87bd28

Please sign in to comment.