Skip to content

Commit

Permalink
fix(snap): allow to set classic confinement
Browse files Browse the repository at this point in the history
  • Loading branch information
develar committed Feb 24, 2017
1 parent 79077bf commit f1d524a
Show file tree
Hide file tree
Showing 8 changed files with 616 additions and 39 deletions.
2 changes: 1 addition & 1 deletion .idea/rc-producer.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

341 changes: 324 additions & 17 deletions CHANGELOG.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/Options.md
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ To use Squirrel.Windows please install `electron-builder-squirrel-windows` depen
### `snap` [Snap](http://snapcraft.io) Specific Options
| Name | Description
| --- | ---
| confinement | <a name="SnapOptions-confinement"></a>The type of confinement supported by the snap. Can be either `devmode` (i.e. this snap doesn’t support running under confinement) or `strict` (i.e. full confinement supported via interfaces). Defaults to `strict`.
| confinement | <a name="SnapOptions-confinement"></a>The type of [confinement](https://snapcraft.io/docs/reference/confinement) supported by the snap. Defaults to `strict`.
| summary | <a name="SnapOptions-summary"></a>The 78 character long summary. Defaults to [productName](#AppMetadata-productName).
| grade | <a name="SnapOptions-grade"></a><p>The quality grade of the snap. It can be either <code>devel</code> (i.e. a development version of the snap, so not to be published to the “stable” or “candidate” channels) or “stable” (i.e. a stable release or release candidate, which can be released to all channels). Defaults to <code>stable</code>.</p>
| assumes | <a name="SnapOptions-assumes"></a>The list of features that must be supported by the core in order for this snap to install.
Expand Down
4 changes: 2 additions & 2 deletions packages/electron-builder/src/options/linuxOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ export interface DebOptions extends LinuxBuildOptions {
*/
export interface SnapOptions extends LinuxBuildOptions {
/**
The type of confinement supported by the snap. Can be either `devmode` (i.e. this snap doesn’t support running under confinement) or `strict` (i.e. full confinement supported via interfaces). Defaults to `strict`.
The type of [confinement](https://snapcraft.io/docs/reference/confinement) supported by the snap. Defaults to `strict`.
*/
readonly confinement?: "devmode" | "strict" | null
readonly confinement?: "devmode" | "strict" | "classic" | null

/**
The 78 character long summary. Defaults to [productName](#AppMetadata-productName).
Expand Down
26 changes: 13 additions & 13 deletions packages/electron-builder/src/targets/snap.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { LinuxTargetHelper } from "./LinuxTargetHelper"
import { LinuxPackager } from "../linuxPackager"
import { Arch, Target, toLinuxArchString } from "electron-builder-core"
import { spawn } from "electron-builder-util"
import { log } from "electron-builder-util/out/log"
import { SnapOptions } from "../options/linuxOptions"
import { emptyDir, outputFile, copy } from "fs-extra-p"
import * as path from "path"
import { copy, emptyDir, outputFile } from "fs-extra-p"
import { safeDump } from "js-yaml"
import { spawn } from "electron-builder-util"
import { homedir } from "os"
import { Target, Arch, toLinuxArchString } from "electron-builder-core"
import * as path from "path"
import { LinuxPackager } from "../linuxPackager"
import { SnapOptions } from "../options/linuxOptions"
import { LinuxTargetHelper } from "./LinuxTargetHelper"

export default class SnapTarget extends Target {
private readonly options: SnapOptions = Object.assign({}, this.packager.platformSpecificBuildOptions, (<any>this.packager.config)[this.name])
Expand Down Expand Up @@ -35,7 +35,7 @@ export default class SnapTarget extends Target {
}

const snap: any = {}
snap.name = packager.executableName
snap.name = packager.executableName.toLowerCase()
snap.version = appInfo.version
snap.summary = options.summary || appInfo.productName
snap.description = this.helper.getDescription(options)
Expand All @@ -48,7 +48,7 @@ export default class SnapTarget extends Target {
await copy(this.helper.maxIconPath, path.join(snapDir, "gui", "icon.png"))
}

await this.helper.computeDesktopEntry(this.options, `${snap.name}`, path.join(snapDir, "gui", `${snap.name}.desktop`), {
const desktopFile = await this.helper.computeDesktopEntry(this.options, `${packager.executableName}`, path.join(snapDir, "gui", `${snap.name}.desktop`), {
"Icon": "${SNAP}/meta/gui/icon.png"
})

Expand Down Expand Up @@ -98,15 +98,15 @@ export default class SnapTarget extends Target {
}
}

if (packager.packagerOptions.effectiveOptionComputed != null && await packager.packagerOptions.effectiveOptionComputed(snap)) {
if (packager.packagerOptions.effectiveOptionComputed != null && await packager.packagerOptions.effectiveOptionComputed({snap, desktopFile})) {
return
}

const snapcraft = path.join(snapDir, "snapcraft.yaml")
await outputFile(snapcraft, safeDump(snap, {lineWidth: 160}))

const snapName = `${snap.name}_${snap.version}_${toLinuxArchString(arch)}.snap`
const resultFile = path.join(this.outDir, snapName)
const snapFileName = `${snap.name}_${snap.version}_${toLinuxArchString(arch)}.snap`
const resultFile = path.join(this.outDir, snapFileName)

if (isUseDocker) {
await spawn("docker", ["run", "--rm",
Expand All @@ -115,7 +115,7 @@ export default class SnapTarget extends Target {
// dist dir can be outside of project dir
"-v", `${this.outDir}:/out`,
"electronuserland/electron-builder:latest",
"/bin/bash", "-c", `snapcraft --version && cp -R /out/${path.basename(stageDir)} /s/ && cd /s && snapcraft snap --target-arch ${toLinuxArchString(arch)} -o /out/${snapName}`], {
"/bin/bash", "-c", `snapcraft --version && cp -R /out/${path.basename(stageDir)} /s/ && cd /s && snapcraft snap --target-arch ${toLinuxArchString(arch)} -o /out/${snapFileName}`], {
cwd: packager.info.projectDir,
stdio: ["ignore", "inherit", "inherit"],
})
Expand Down
2 changes: 1 addition & 1 deletion test/jestSetup.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jasmine.DEFAULT_TIMEOUT_INTERVAL = (isWindows ? 30 : 10) * 1000 * 60
const skip = test.skip
const skipSuite = describe.skip

const isAllTests = process.env.ALL_TESTS === undefined || process.env.ALL_TESTS === "true"
const isAllTests = process.env.ALL_TESTS !== "false"
describe.ifAll = isAllTests ? describe : skipSuite
test.ifAll = isAllTests ? test : skip

Expand Down
256 changes: 256 additions & 0 deletions test/out/linux/__snapshots__/snapTest.js.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,261 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`default stagePackages 1`] = `
Object {
"apps": Object {
"sep": Object {
"command": "desktop-launch $SNAP/sep",
"plugs": Array [
"home",
"x11",
"unity7",
"browser-support",
"network",
"gsettings",
"pulseaudio",
"opengl",
],
},
},
"confinement": "strict",
"description": "Test Application (test quite “ #378)",
"grade": "stable",
"icon": "snap/gui/icon.png",
"name": "sep",
"parts": Object {
"app": Object {
"after": Array [
"desktop-glib-only",
],
"plugin": "dump",
"stage-packages": Array [
"libnotify4",
"libappindicator1",
"libxtst6",
"libnss3",
"libxss1",
"fontconfig-config",
"gconf2",
"libasound2",
"pulseaudio",
],
},
},
"summary": "Sep",
"version": "1.1.0",
}
`;

exports[`default stagePackages 2`] = `
Object {
"apps": Object {
"sep": Object {
"command": "desktop-launch $SNAP/sep",
"plugs": Array [
"home",
"x11",
"unity7",
"browser-support",
"network",
"gsettings",
"pulseaudio",
"opengl",
"custom",
],
},
},
"confinement": "strict",
"description": "Test Application (test quite “ #378)",
"grade": "stable",
"icon": "snap/gui/icon.png",
"name": "sep",
"parts": Object {
"app": Object {
"after": Array [
"desktop-glib-only",
],
"plugin": "dump",
"stage-packages": Array [
"libnotify4",
"libappindicator1",
"libxtst6",
"libnss3",
"libxss1",
"fontconfig-config",
"gconf2",
"libasound2",
"pulseaudio",
"custom",
],
},
},
"summary": "Sep",
"version": "1.1.0",
}
`;

exports[`default stagePackages 3`] = `
Object {
"apps": Object {
"sep": Object {
"command": "desktop-launch $SNAP/sep",
"plugs": Array [
"custom",
"home",
"x11",
"unity7",
"browser-support",
"network",
"gsettings",
"pulseaudio",
"opengl",
],
},
},
"confinement": "strict",
"description": "Test Application (test quite “ #378)",
"grade": "stable",
"icon": "snap/gui/icon.png",
"name": "sep",
"parts": Object {
"app": Object {
"after": Array [
"desktop-glib-only",
],
"plugin": "dump",
"stage-packages": Array [
"custom",
"libnotify4",
"libappindicator1",
"libxtst6",
"libnss3",
"libxss1",
"fontconfig-config",
"gconf2",
"libasound2",
"pulseaudio",
],
},
},
"summary": "Sep",
"version": "1.1.0",
}
`;

exports[`default stagePackages 4`] = `
Object {
"apps": Object {
"sep": Object {
"command": "desktop-launch $SNAP/sep",
"plugs": Array [
"foo1",
"home",
"x11",
"unity7",
"browser-support",
"network",
"gsettings",
"pulseaudio",
"opengl",
"foo2",
],
},
},
"confinement": "strict",
"description": "Test Application (test quite “ #378)",
"grade": "stable",
"icon": "snap/gui/icon.png",
"name": "sep",
"parts": Object {
"app": Object {
"after": Array [
"desktop-glib-only",
],
"plugin": "dump",
"stage-packages": Array [
"foo1",
"libnotify4",
"libappindicator1",
"libxtst6",
"libnss3",
"libxss1",
"fontconfig-config",
"gconf2",
"libasound2",
"pulseaudio",
"foo2",
],
},
},
"summary": "Sep",
"version": "1.1.0",
}
`;

exports[`platform 1`] = `
Object {
"apps": Object {
"sep": Object {
"command": "desktop-launch $SNAP/Sep",
"plugs": Array [
"home",
"x11",
"unity7",
"browser-support",
"network",
"gsettings",
"pulseaudio",
"opengl",
"platform",
],
},
},
"confinement": "strict",
"description": "Test Application (test quite “ #378)",
"grade": "stable",
"icon": "snap/gui/icon.png",
"name": "sep",
"parts": Object {
"app": Object {
"after": Array [
"extra",
"desktop-ubuntu-app-platform",
],
"plugin": "dump",
"stage-packages": Array [
"libnss3",
],
},
"extra": Object {
"plugin": "dump",
"source": "/out/linux-unpacked-snap/extra",
},
},
"plugs": Object {
"platform": Object {
"content": "ubuntu-app-platform1",
"default-provider": "ubuntu-app-platform",
"interface": "content",
"target": "ubuntu-app-platform",
},
},
"summary": "Sep P",
"version": "1.1.0",
}
`;

exports[`platform 2`] = `
"[Desktop Entry]
Name=Sep P
Comment=Test Application (test quite “ #378)
Exec=Sep
Terminal=false
Type=Application
Icon=\${SNAP}/meta/gui/icon.png
Categories=Development;
"
`;

exports[`snap 1`] = `
Array [
"sep_1.1.0_amd64.snap",
Expand Down
Loading

0 comments on commit f1d524a

Please sign in to comment.