Skip to content

Commit

Permalink
feat(snap): ubuntu-app-platform (disabled by default)
Browse files Browse the repository at this point in the history
  • Loading branch information
develar committed Dec 25, 2016
1 parent 1fc26a5 commit a0c0d8e
Show file tree
Hide file tree
Showing 20 changed files with 99 additions and 39 deletions.
1 change: 1 addition & 0 deletions .idea/dictionaries/develar.xml

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

2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ before_install:
install:
- nvm install $NODE_VERSION
- nvm use --delete-prefix $NODE_VERSION
- ln -sf $PWD/test/yarn.js /usr/local/bin/yarn
- ln -sf $PWD/test/vendor/yarn.js /usr/local/bin/yarn
- yarn install --pure-lockfile
- if [[ "$TRAVIS_BRANCH" == "master" && "$TRAVIS_PULL_REQUEST" == "false" && "$AUTO_PUBLISH" != "false" && "$TRAVIS_TAG" == "" && "$PUBLISH_TO_NPM" == "true" ]]; then yarn add @develar/semantic-release@next --dev ; fi

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ const Platform = builder.Platform
// Promise is returned
builder.build({
targets: Platform.MAC.createTarget(),
devMetadata: {
"//": "build and other properties, see https://goo.gl/5jVxoO"
config: {
"//": "build options, see https://goo.gl/ZhRfla"
}
})
.then(() => {
Expand Down
4 changes: 2 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ environment:

install:
- ps: Install-Product node 6 x64
- node ./test/yarn.js
- node ./test/vendor/yarn.js

build: off

test_script:
- node ./test/yarn.js test
- node ./test/vendor/yarn.js test
2 changes: 1 addition & 1 deletion circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ dependencies:
- sudo apt-get install git-lfs=1.3.0
- ssh [email protected] git-lfs-authenticate $CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME.git download
- git lfs pull
- docker run --rm --env-file ./test/docker-env.list -v ${PWD}:/project -v ~/.electron:/root/.electron -v ~/.cache/electron-builder:/root/.cache/electron-builder electronuserland/electron-builder:$([ "$CIRCLE_NODE_INDEX" == "2" ] && echo "6" || echo "wine") /bin/bash -c "node ./test/yarn.js && node ./test/yarn.js test"
- docker run --rm --env-file ./test/docker-env.list -v ${PWD}:/project -v ~/.electron:/root/.electron -v ~/.cache/electron-builder:/root/.cache/electron-builder electronuserland/electron-builder:$([ "$CIRCLE_NODE_INDEX" == "2" ] && echo "6" || echo "wine") /bin/bash -c "node ./test/vendor/yarn.js && node ./test/vendor/yarn.js test"

test:
override:
Expand Down
2 changes: 1 addition & 1 deletion docker/base/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ ENV DEBUG_COLORS true
ENV FORCE_COLOR true

RUN curl -L https://yarnpkg.com/latest.tar.gz | tar xvz && mv dist yarn && ln -s /yarn/bin/yarn /usr/local/bin/yarn && apt-get update -y && \
apt-get install --no-install-recommends -y git snapcraft xorriso bsdtar build-essential autoconf libssl-dev icnsutils graphicsmagick gcc-multilib g++-multilib libgnome-keyring-dev lzip rpm yasm && \
apt-get install --no-install-recommends -y git snapcraft qtbase5-dev xorriso bsdtar build-essential autoconf libssl-dev icnsutils graphicsmagick gcc-multilib g++-multilib libgnome-keyring-dev lzip rpm yasm && \
apt-get clean && \
rm -rf /var/lib/apt/lists/* && \
curl -L http://tukaani.org/xz/xz-$XZ_VERSION.tar.xz | tar -xJ && cd xz-$XZ_VERSION && ./configure && make && make install && cd .. && rm -rf xz-$XZ_VERSION && ldconfig && \
Expand Down
5 changes: 4 additions & 1 deletion docs/Options.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ Don't customize paths to background and icon, — just follow conventions.
| squirrelWindows | <a name="BuildMetadata-squirrelWindows"></a>See [.build.squirrelWindows](#SquirrelWindowsOptions).
| appx | <a name="BuildMetadata-appx"></a>See [.build.appx](#AppXOptions).
| linux | <a name="BuildMetadata-linux"></a>See [.build.linux](#LinuxBuildOptions).
| snap | <a name="BuildMetadata-snap"></a>See [.build.snap](#SnapOptions).
| compression | <a name="BuildMetadata-compression"></a>The compression level, one of `store`, `normal`, `maximum` (default: `normal`). If you want to rapidly test build, `store` can reduce build time significantly.
| afterPack | <a name="BuildMetadata-afterPack"></a>*programmatic API only* The function to be run after pack (but before pack into distributable format and sign). Promise must be returned.
| npmRebuild | <a name="BuildMetadata-npmRebuild"></a>Whether to [rebuild](https://docs.npmjs.com/cli/rebuild) native dependencies (`npm rebuild`) before starting to package the app. Defaults to `true`.
Expand Down Expand Up @@ -167,7 +168,7 @@ Linux specific build options.
| vendor | <a name="LinuxBuildOptions-vendor"></a>The vendor. Defaults to [author](#AppMetadata-author).
| desktop | <a name="LinuxBuildOptions-desktop"></a>The [Desktop file](https://developer.gnome.org/integration-guide/stable/desktop-files.html.en) entries (name to value).
| compression | <a name="LinuxBuildOptions-compression"></a>*deb-only.* The compression type, one of `gz`, `bzip2`, `xz`. Defaults to `xz`.
| depends | <a name="LinuxBuildOptions-depends"></a>Package dependencies. Defaults to `["libappindicator1", "libnotify-bin"]`.
| depends | <a name="LinuxBuildOptions-depends"></a>Package dependencies. Defaults to `["gconf2", "gconf-service", "libnotify4", "libappindicator1", "libxtst6", "libnss3"]` for `deb`.
| executableName | <a name="LinuxBuildOptions-executableName"></a><p>The executable name. Defaults to <code>productName</code>.</p> <p>Cannot be specified per target, allowed only in the <code>.build.linux</code>.</p>

<a name="MacOptions"></a>
Expand Down Expand Up @@ -281,6 +282,8 @@ Amazon S3 — `https` must be used, so, if you use direct Amazon S3 endpoints, f
| 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.
| stagePackages | <a name="SnapOptions-stagePackages"></a><p>The list of Ubuntu packages to use that are needed to support the <code>app</code> part creation. Like <code>depends</code> for <code>deb</code>. Defaults to <code>[&quot;libnotify4&quot;, &quot;libappindicator1&quot;, &quot;libxtst6&quot;, &quot;libnss3&quot;, &quot;fontconfig-config&quot;]</code>.</p>
| ubuntuAppPlatformContent | <a name="SnapOptions-ubuntuAppPlatformContent"></a><p>Specify <code>ubuntu-app-platform1</code> to use [ubuntu-app-platform](https://insights.ubuntu.com/2016/11/17/how-to-create-snap-packages-on-qt-applications/). Snap size will be greatly reduced, but it is not recommended for now because “the snaps must be connected before running uitk-gallery for the first time”.</p>

<a name="SquirrelWindowsOptions"></a>
### `.build.squirrelWindows`
Expand Down
2 changes: 1 addition & 1 deletion docs/programmaticUsage.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ builder.build({
platform: [builder.Platform.MAC],
"//": "platform, arch and other properties, see PackagerOptions in the node_modules/electron-builder/out/electron-builder.d.ts",
config: {
"//": "build and other properties, see https://goo.gl/5jVxoO"
"//": "build options, see https://goo.gl/ZhRfla"
}
})
.then(() => {
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
"scripts": {
"compile": "ts-babel . nsis-auto-updater test",
"lint": "node ./test/lint.js",
"pretest": "node ./test/yarn.js run compile && node ./test/yarn.js run lint",
"pretest": "node ./test/vendor/yarn.js run compile && node ./test/vendor/yarn.js run lint",
"check-deps": "node ./test/out/helpers/checkDeps.js",
"test": "node ./test/out/helpers/runTests.js",
"test-linux": "docker run --rm -ti -v ${PWD}:/project -v ${PWD##*/}-node-modules:/project/node_modules -v ~/.electron:/root/.electron electronuserland/electron-builder:wine /test.sh",
"pack-updater": "cd nsis-auto-updater && node ./test/yarn.js --production && cd ..",
"pack-updater": "cd nsis-auto-updater && node ./test/vendor/yarn.js --production && cd ..",
"semantic-release": "semantic-release pre && npm publish && semantic-release post",
"//": "Update wiki if docs changed. Update only if functionalily are generally available (latest release, not next)",
"update-wiki": "git subtree split -b wiki --prefix docs/ && git push -f wiki wiki:master",
Expand Down Expand Up @@ -89,7 +89,7 @@
"read-installed": "^4.0.3",
"sanitize-filename": "^1.6.1",
"semver": "^5.3.0",
"source-map-support": "^0.4.6",
"source-map-support": "^0.4.8",
"stat-mode": "^0.2.2",
"tunnel-agent": "^0.4.3",
"update-notifier": "^1.0.3",
Expand Down
7 changes: 6 additions & 1 deletion src/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { PlatformPackager } from "./platformPackager"
import { MacOptions, DmgOptions, MasBuildOptions } from "./options/macOptions"
import { Publish } from "./options/publishOptions"
import { WinBuildOptions, NsisOptions, SquirrelWindowsOptions, AppXOptions } from "./options/winOptions"
import { LinuxBuildOptions } from "./options/linuxOptions"
import { LinuxBuildOptions, SnapOptions } from "./options/linuxOptions"

export interface Metadata {
readonly repository?: string | RepositoryInfo | null
Expand Down Expand Up @@ -181,6 +181,11 @@ export interface BuildMetadata {

readonly deb?: LinuxBuildOptions | null

/*
See [.build.snap](#SnapOptions).
*/
readonly snap?: SnapOptions | null

/*
The compression level, one of `store`, `normal`, `maximum` (default: `normal`). If you want to rapidly test build, `store` can reduce build time significantly.
*/
Expand Down
14 changes: 13 additions & 1 deletion src/options/linuxOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export interface LinuxBuildOptions extends PlatformSpecificBuildOptions {
readonly compression?: string | null

/*
Package dependencies. Defaults to `["libappindicator1", "libnotify-bin"]`.
Package dependencies. Defaults to `["gconf2", "gconf-service", "libnotify4", "libappindicator1", "libxtst6", "libnss3"]` for `deb`.
*/
readonly depends?: string[] | null

Expand Down Expand Up @@ -98,4 +98,16 @@ export interface SnapOptions extends LinuxBuildOptions {
The list of features that must be supported by the core in order for this snap to install.
*/
assumes?: Array<string> | null

/*
The list of Ubuntu packages to use that are needed to support the `app` part creation. Like `depends` for `deb`.
Defaults to `["libnotify4", "libappindicator1", "libxtst6", "libnss3", "fontconfig-config"]`.
*/
stagePackages?: Array<string> | null

/*
Specify `ubuntu-app-platform1` to use [ubuntu-app-platform](https://insights.ubuntu.com/2016/11/17/how-to-create-snap-packages-on-qt-applications/).
Snap size will be greatly reduced, but it is not recommended for now because "the snaps must be connected before running uitk-gallery for the first time".
*/
ubuntuAppPlatformContent?: string | null
}
2 changes: 1 addition & 1 deletion src/targets/fpm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export default class FpmTarget extends Target {
let depends = options.depends
if (depends == null) {
if (target === "deb") {
depends = ["libnotify4", "libnss3"]
depends = ["gconf2", "gconf-service", "libnotify4", "libappindicator1", "libxtst6", "libnss3"]
}
else {
depends = []
Expand Down
36 changes: 30 additions & 6 deletions src/targets/snap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { safeDump } from "js-yaml"
import { spawn } from "../util/util"
import { homedir } from "os"
import { Target } from "./targetFactory"
import BluebirdPromise from "bluebird-lst-c"

export default class SnapTarget extends Target {
private readonly options: SnapOptions = Object.assign({}, this.packager.platformSpecificBuildOptions, (<any>this.packager.config)[this.name])
Expand All @@ -28,6 +29,13 @@ export default class SnapTarget extends Target {
const snapDir = `${appOutDir}-snap`
await emptyDir(snapDir)

const extraSnapSourceDir = path.join(snapDir, ".extra")
const isUseUbuntuPlatform = options.ubuntuAppPlatformContent != null
if (isUseUbuntuPlatform) {
// ubuntu-app-platform requires empty directory
await BluebirdPromise.all([this.helper.icons, emptyDir(path.join(extraSnapSourceDir, "ubuntu-app-platform"))])
}

const snap: any = {}
snap.name = packager.executableName
snap.version = appInfo.version
Expand Down Expand Up @@ -57,21 +65,36 @@ export default class SnapTarget extends Target {
[snap.name]: {
command: `desktop-launch $SNAP/${packager.executableName}`,
plugs: [
"home", "x11", "unity7", "unity8", "browser-support", "network", "gsettings", "pulseaudio", "opengl",
"home", "x11", "unity7", "unity8", "browser-support", "network", "gsettings", "pulseaudio", "opengl", "platform",
]
}
}

if (isUseUbuntuPlatform) {
snap.plugs = {
platform: {
interface: "content",
content: "ubuntu-app-platform1",
target: "ubuntu-app-platform",
"default-provider": "ubuntu-app-platform",
}
}
}

const isUseDocker = process.platform !== "linux"
snap.parts = {
app: {
plugin: "dump",
"stage-packages": ["libnotify4", "libnss3", "fontconfig-config"],
"stage-packages": options.stagePackages || (isUseUbuntuPlatform ? ["libnss3"] : ["libnotify4", "libappindicator1", "libxtst6", "libnss3", "fontconfig-config"]),
source: isUseDocker ? `/out/${path.basename(snapDir)}` : appOutDir,
filesets: {
app: [`${appOutDir}/*`],
},
after: ["desktop-glib-only"]
after: isUseUbuntuPlatform ? ["extra", "desktop-ubuntu-app-platform"] : ["desktop-glib-only"]
}
}

if (isUseUbuntuPlatform) {
snap.parts.extra = {
plugin: "dump",
source: extraSnapSourceDir
}
}

Expand All @@ -95,6 +118,7 @@ export default class SnapTarget extends Target {
else {
await spawn("snapcraft", ["snap"], {
cwd: snapDir,
stdio: ["ignore", "inherit", "pipe"]
})
}

Expand Down
1 change: 1 addition & 0 deletions test/jestSetup.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ test.ifNotCiWin = isCi && isWindows ? skip : test
test.ifDevOrWinCi = !isCi || isWindows ? test : skip
test.ifDevOrLinuxCi = !isCi || process.platform === "linux" ? test : skip
test.ifWinCi = isCi && isWindows ? test : skip
test.ifLinux = process.platform === "linux" ? test : skip

delete process.env.CSC_NAME
process.env.CSC_IDENTITY_AUTO_DISCOVERY = "false"
Expand Down
2 changes: 1 addition & 1 deletion test/src/helpers/packTester.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ async function checkLinuxResult(outDir: string, packager: Packager, checkOptions
Vendor: "Foo Bar <[email protected]>",
Package: "testapp",
Description: " \n Test Application (test quite “ #378)",
Depends: checkOptions == null || checkOptions.expectedDepends == null ? "libappindicator1, libnotify-bin" : checkOptions.expectedDepends,
Depends: checkOptions == null || checkOptions.expectedDepends == null ? "gconf2, gconf-service, libnotify4, libappindicator1, libxtst6, libnss3" : checkOptions.expectedDepends,
Section: "devel",
})
}
Expand Down
12 changes: 0 additions & 12 deletions test/src/linux/linuxPackagerTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,6 @@ import { Platform } from "out"

test.ifDevOrLinuxCi("AppImage", app({targets: Platform.LINUX.createTarget()}))

if (process.platform === "linux") {
test("snap", app({
targets: Platform.LINUX.createTarget("snap"),
config: {
productName: "Snap Electron Builder Test",
},
appMetadata: {
name: "snap-electron-builder-test",
},
}))
}

test.ifDevOrLinuxCi("AppImage - default icon, custom executable and custom desktop", app({
targets: Platform.LINUX.createTarget("appimage"),
effectiveOptionComputed: async (it) => {
Expand Down
25 changes: 25 additions & 0 deletions test/src/linux/snapTest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { Platform } from "out"
import { app } from "../helpers/packTester"

test.ifLinux("platform", app({
targets: Platform.LINUX.createTarget("snap"),
config: {
productName: "Sep P",
snap: {
ubuntuAppPlatformContent: "ubuntu-app-platform1",
},
},
appMetadata: {
name: "sep-p",
},
}))

test.ifLinux("snap", app({
targets: Platform.LINUX.createTarget("snap"),
config: {
productName: "Sep",
},
appMetadata: {
name: "sep",
},
}))
1 change: 1 addition & 0 deletions test/typings/jest-ex.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ declare module jest {
ifDevOrWinCi: jest.It
ifWinCi: jest.It
ifDevOrLinuxCi: jest.It
ifLinux: jest.It
}

interface Matchers {
Expand Down
File renamed without changes.
10 changes: 5 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2350,8 +2350,8 @@ lodash@^3.6.0:
resolved "https://registry.yarnpkg.com/lodash/-/lodash-3.10.1.tgz#5bf45e8e49ba4189e17d482789dfd15bd140b7b6"

lodash@^4.0.0, lodash@^4.14.0, lodash@^4.2.0, lodash@^4.2.1, lodash@^4.5.1, lodash@^4.8.0:
version "4.17.2"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.2.tgz#34a3055babe04ce42467b607d700072c7ff6bf42"
version "4.17.3"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.3.tgz#557ed7d2a9438cac5fd5a43043ca60cb455e01f7"

longest@^1.0.1:
version "1.0.1"
Expand Down Expand Up @@ -3184,9 +3184,9 @@ [email protected]:
dependencies:
hoek "2.x.x"

source-map-support@^0.4.2, source-map-support@^0.4.6:
version "0.4.7"
resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.4.7.tgz#7a7988e0e66241c778c78dd179199bb6bcd35bd6"
source-map-support@^0.4.2, source-map-support@^0.4.6, source-map-support@^0.4.8:
version "0.4.8"
resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.4.8.tgz#4871918d8a3af07289182e974e32844327b2e98b"
dependencies:
source-map "^0.5.3"

Expand Down

0 comments on commit a0c0d8e

Please sign in to comment.