Skip to content

Commit

Permalink
feat(snap): support electron 2
Browse files Browse the repository at this point in the history
  • Loading branch information
develar committed Feb 24, 2018
1 parent 2154934 commit 43e23c8
Show file tree
Hide file tree
Showing 14 changed files with 105 additions and 33 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.

3 changes: 2 additions & 1 deletion docker/base/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ RUN curl -L https://yarnpkg.com/latest.tar.gz | tar xvz && mv yarn-* /yarn && ln
# python for node-gyp
# rpm is required for FPM to build rpm package
# libsecret-1-0 and libgnome-keyring-dev are required even for prebuild keytar
# libgtk2.0-dev for snap desktop-gtk2 (see https://github.com/ubuntu/snapcraft-desktop-helpers/blob/master/snapcraft.yaml#L248)
# libgtk2.0-dev for snap desktop-gtk2 sudo (see https://github.com/ubuntu/snapcraft-desktop-helpers/blob/master/snapcraft.yaml#L248)
# sudo for snapcraft (install build packages)
apt-get -qq install --no-install-recommends git qtbase5-dev bsdtar build-essential autoconf libssl-dev gcc-multilib g++-multilib lzip rpm python libcurl3 git git-lfs ssh unzip \
libsecret-1-dev libgnome-keyring-dev \
libopenjp2-tools \
Expand Down
4 changes: 3 additions & 1 deletion docker/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ docker build -t electronuserland/builder:9 -t electronuserland/builder:latest -t

docker build -t electronuserland/builder:wine docker/wine
docker build -t electronuserland/builder:wine-mono docker/wine-mono
docker build -t electronuserland/builder:wine-chrome docker/wine-chrome
docker build -t electronuserland/builder:wine-chrome docker/wine-chrome

docker build -t electronuserland/snapcraft-electron:2 docker/snapcraft-electron2
5 changes: 5 additions & 0 deletions docker/snapcraft-electron2/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM snapcore/snapcraft:latest

# list from snapcraft message "Installing build dependencies"
RUN apt-get -qq update && apt-get -qq install --no-install-recommends acl adwaita-icon-theme at-spi2-core colord colord-data dbus dconf-gsettings-backend dconf-service gir1.2-atspi-2.0 gir1.2-gtk-3.0 glib-networking glib-networking-common glib-networking-services gsettings-desktop-schemas hicolor-icon-theme humanity-icon-theme libatk-bridge2.0-0 libatk-bridge2.0-dev libatspi2.0-0 libatspi2.0-dev libcap-ng0 libcolord2 libcolorhug2 libcroco3 libdbus-1-dev libdconf1 libepoxy-dev libepoxy0 libexif12 libgd3 libgmp-dev libgmpxx4ldbl libgphoto2-6 libgphoto2-l10n libgphoto2-port12 libgtk-3-0 libgtk-3-bin libgtk-3-common libgtk-3-dev libgusb2 libieee1284-3 libjson-glib-1.0-0 libjson-glib-1.0-common libltdl7 libpam-systemd libpolkit-agent-1-0 libpolkit-backend-1-0 libpolkit-gobject-1-0 librest-0.7-0 librsvg2-2 librsvg2-common libsane libsane-common libsoup-gnome2.4-1 libsoup2.4-1 libusb-1.0-0 libvpx3 libxpm4 libxtst-dev libxtst6 nettle-dev policykit-1 ubuntu-mono x11proto-record-dev

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@
"////": "All typings are added into root `package.json` to avoid duplication errors in the IDE compiler (several `node.d.ts` files).",
"dependencies": {
"7zip-bin": "~3.1.0",
"app-builder-bin": "1.4.1",
"app-builder-bin": "1.5.0",
"archiver": "^2.1.1",
"async-exit-hook": "^2.0.1",
"aws-sdk": "^2.201.0",
"aws-sdk": "^2.202.0",
"bluebird-lst": "^1.0.5",
"chalk": "^2.3.0",
"chromium-pickle-js": "^0.2.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/builder-util/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"out"
],
"dependencies": {
"app-builder-bin": "1.4.1",
"app-builder-bin": "1.5.0",
"temp-file": "^3.1.1",
"fs-extra-p": "^4.5.2",
"is-ci": "^1.1.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/electron-builder-lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"homepage": "https://github.com/electron-userland/electron-builder",
"dependencies": {
"7zip-bin": "~3.1.0",
"app-builder-bin": "1.4.1",
"app-builder-bin": "1.5.0",
"async-exit-hook": "^2.0.1",
"bluebird-lst": "^1.0.5",
"chromium-pickle-js": "^0.2.0",
Expand Down
18 changes: 13 additions & 5 deletions packages/electron-builder-lib/src/linuxPackager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Arch, AsyncTaskManager, log, executeAppBuilder } from "builder-util"
import { rename } from "fs-extra-p"
import * as path from "path"
import sanitizeFileName from "sanitize-filename"
import * as semver from "semver"
import { AfterPackContext } from "./configuration"
import { DIR_TARGET, Platform, Target, TargetSpecificOptions } from "./core"
import { LinuxConfiguration } from "./options/linuxOptions"
Expand All @@ -24,6 +25,10 @@ export class LinuxPackager extends PlatformPackager<LinuxConfiguration> {
this.executableName = executableName == null ? this.appInfo.sanitizedName.toLowerCase() : sanitizeFileName(executableName)
}

get isElectron2(): boolean {
return semver.gte(this.config.electronVersion || "1.8.3", "2.0.0-beta.1")
}

get defaultTarget(): Array<string> {
return ["snap", "appimage"]
}
Expand Down Expand Up @@ -84,11 +89,14 @@ export class LinuxPackager extends PlatformPackager<LinuxConfiguration> {
protected async postInitApp(packContext: AfterPackContext): Promise<void> {
const executable = path.join(packContext.appOutDir, this.executableName)
await rename(path.join(packContext.appOutDir, this.electronDistExecutableName), executable)
try {
await executeAppBuilder(["clear-exec-stack", "--input", executable])
}
catch (e) {
log.debug({error: e}, "cannot clear exec stack")

if (!this.isElectron2) {
try {
await executeAppBuilder(["clear-exec-stack", "--input", executable])
}
catch (e) {
log.debug({error: e}, "cannot clear exec stack")
}
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions packages/electron-builder-lib/src/targets/snap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export default class SnapTarget extends Target {
app: {
plugin: "nil",
"stage-packages": this.replaceDefault(options.stagePackages, defaultStagePackages),
after: this.replaceDefault(options.after, ["desktop-gtk2"]),
after: this.replaceDefault(options.after, [this.packager.isElectron2 ? "desktop-gtk3" : "desktop-gtk2"]),
}
},
}
Expand Down Expand Up @@ -129,7 +129,7 @@ export default class SnapTarget extends Target {
"--stage", stageDir,
"--arch", toLinuxArchString(arch),
"--output", artifactPath,
"--docker-image", "electronuserland/builder:latest",
"--docker-image", this.packager.isElectron2 ? "electronuserland/snapcraft-electron:2" : "electronuserland/builder:latest",
]

await this.helper.icons
Expand Down Expand Up @@ -163,7 +163,7 @@ export default class SnapTarget extends Target {
}

if (this.isUseTemplateApp) {
args.push("--template-url", "electron1")
args.push("--template-url", this.packager.isElectron2 ? "electron2" : "electron1")
}
await executeAppBuilder(args)
packager.dispatchArtifactCreated(artifactPath, this, arch)
Expand Down
2 changes: 1 addition & 1 deletion packages/electron-publisher-s3/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
],
"dependencies": {
"fs-extra-p": "^4.5.2",
"aws-sdk": "^2.201.0",
"aws-sdk": "^2.202.0",
"mime": "^2.2.0",
"electron-publish": "~0.0.0-semantic-release",
"builder-util": "^0.0.0-semantic-release",
Expand Down
8 changes: 8 additions & 0 deletions scripts/snap-template.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash

rm -rf ~/squashfs-root
unsquashfs /media/psf/test/se-electron2_1.1.0_amd64.snap
rm -rf ~/squashfs-root/app ~/squashfs-root/snap ~/squashfs-root/meta ~/squashfs-root/command.sh
mksquashfs ~/squashfs-root /media/psf/test/electron-template-2.snap -b 1048576 -comp xz -Xdict-size 100% -noappend -comp xz -no-xattrs -no-fragments -all-root

shasum -a 512 /Volumes/test/electron-template-2.snap | xxd -r -p | base64
22 changes: 22 additions & 0 deletions test/out/linux/__snapshots__/snapTest.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,17 @@ Object {
}
`;

exports[`snap electron 2 1`] = `
Object {
"linux": Array [
Object {
"arch": "x64",
"file": "sep-electron2_1.1.0_amd64.snap",
},
],
}
`;

exports[`snap full 1`] = `
Object {
"linux": Array [
Expand All @@ -514,3 +525,14 @@ Object {
],
}
`;

exports[`snap full electron 2 1`] = `
Object {
"linux": Array [
Object {
"arch": "x64",
"file": "se-electron2_1.1.0_amd64.snap",
},
],
}
`;
25 changes: 25 additions & 0 deletions test/src/linux/snapTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,17 @@ test.ifAll.ifDevOrLinuxCi("snap", app({
},
}))

test.ifAll.ifDevOrLinuxCi("snap electron 2", app({
targets: snapTarget,
config: {
extraMetadata: {
name: "sep-electron2",
},
productName: "Sep Electron 2",
electronVersion: "2.0.0-beta.1",
},
}))

// custom packages to test not-prepacked snap build
// very slow
test.skip("snap full", app({
Expand All @@ -34,6 +45,20 @@ test.skip("snap full", app({
},
}))

test.skip("snap full electron 2", app({
targets: snapTarget,
config: {
extraMetadata: {
name: "se-electron2",
},
electronVersion: "2.0.0-beta.1",
productName: "Snap Electron 2 App (full build)",
snap: {
useTemplateApp: false,
},
},
}))

test.ifAll.ifDevOrLinuxCi("default stagePackages", async () => {
for (const p of [["default"], ["default", "custom"], ["custom", "default"], ["foo1", "default", "foo2"]]) {
await assertPack("test-app-one", {
Expand Down
36 changes: 18 additions & 18 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -275,25 +275,25 @@ anymatch@^1.3.0:
micromatch "^2.1.5"
normalize-path "^2.0.0"

app-builder-bin-linux@1.4.1:
version "1.4.1"
resolved "https://registry.yarnpkg.com/app-builder-bin-linux/-/app-builder-bin-linux-1.4.1.tgz#00eca4fbd3e9bdb04073b94b06c5a2c4a659f3d1"
app-builder-bin-linux@1.5.0:
version "1.5.0"
resolved "https://registry.yarnpkg.com/app-builder-bin-linux/-/app-builder-bin-linux-1.5.0.tgz#c22df1ab9ee7fb0270ec27a3c8a6993966ea4220"

app-builder-bin-mac@1.4.1:
version "1.4.1"
resolved "https://registry.yarnpkg.com/app-builder-bin-mac/-/app-builder-bin-mac-1.4.1.tgz#7385b1ed97e58ac4d8e3dc3b5dc6d76b67d97d8d"
app-builder-bin-mac@1.5.0:
version "1.5.0"
resolved "https://registry.yarnpkg.com/app-builder-bin-mac/-/app-builder-bin-mac-1.5.0.tgz#40821128a1f20e0559f1fca71a59ecab81bb59b5"

app-builder-bin-win@1.4.1:
version "1.4.1"
resolved "https://registry.yarnpkg.com/app-builder-bin-win/-/app-builder-bin-win-1.4.1.tgz#30806d14b13bdb7fce4021a7d4f5a9c9ecc9708e"
app-builder-bin-win@1.5.0:
version "1.5.0"
resolved "https://registry.yarnpkg.com/app-builder-bin-win/-/app-builder-bin-win-1.5.0.tgz#0a12437d825ac89fc2357e8be0ba855f54c083e9"

app-builder-bin@1.4.1:
version "1.4.1"
resolved "https://registry.yarnpkg.com/app-builder-bin/-/app-builder-bin-1.4.1.tgz#3ae86df2d3eb624ad93d097abe986fe07c2f5aca"
app-builder-bin@1.5.0:
version "1.5.0"
resolved "https://registry.yarnpkg.com/app-builder-bin/-/app-builder-bin-1.5.0.tgz#dc768af9704876959c68af5456ef31f67a4663fe"
optionalDependencies:
app-builder-bin-linux "1.4.1"
app-builder-bin-mac "1.4.1"
app-builder-bin-win "1.4.1"
app-builder-bin-linux "1.5.0"
app-builder-bin-mac "1.5.0"
app-builder-bin-win "1.5.0"

append-transform@^0.4.0:
version "0.4.0"
Expand Down Expand Up @@ -484,9 +484,9 @@ atob@^2.0.0:
version "2.0.3"
resolved "https://registry.yarnpkg.com/atob/-/atob-2.0.3.tgz#19c7a760473774468f20b2d2d03372ad7d4cbf5d"

aws-sdk@^2.201.0:
version "2.201.0"
resolved "https://registry.yarnpkg.com/aws-sdk/-/aws-sdk-2.201.0.tgz#7a4528262d9097abe37ebf4e6bf9d1851db47003"
aws-sdk@^2.202.0:
version "2.202.0"
resolved "https://registry.yarnpkg.com/aws-sdk/-/aws-sdk-2.202.0.tgz#c1bd90c1dc0bfe835522fe81f29cf8bb71bf00cc"
dependencies:
buffer "4.9.1"
events "^1.1.1"
Expand Down

0 comments on commit 43e23c8

Please sign in to comment.