Skip to content

Commit

Permalink
feat(snap): electron 5 support
Browse files Browse the repository at this point in the history
Close #3872, Close #3923
  • Loading branch information
develar committed Jun 14, 2019
1 parent 1d9d5ed commit 66b1225
Show file tree
Hide file tree
Showing 33 changed files with 1,441 additions and 401 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.

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# electron-builder [![npm version](https://img.shields.io/npm/v/electron-builder.svg?label=latest)](https://yarn.pm/electron-builder) [![downloads per month](https://img.shields.io/npm/dm/electron-builder.svg)](https://yarn.pm/electron-builder) [![donate](https://img.shields.io/badge/Donate-Donorbox-green.svg)](https://www.electron.build/donate)
A complete solution to package and build a ready for distribution [Electron](https://electronjs.org), [Proton Native](https://proton-native.js.org/) or [Muon](https://github.com/brave/muon) app for macOS, Windows and Linux with “auto update” support out of the box.
A complete solution to package and build a ready for distribution [Electron](https://electronjs.org), [Proton Native](https://proton-native.js.org/) app for macOS, Windows and Linux with “auto update” support out of the box.

See documentation on [electron.build](https://www.electron.build).

Expand All @@ -21,7 +21,7 @@ See documentation on [electron.build](https://www.electron.build).
* Build and publish in parallel, using hard links on CI server to reduce IO and disk space usage.
* [electron-compile](https://github.com/electron/electron-compile) support (compile for release-time on the fly on build).
* [Docker](https://www.electron.build/multi-platform-build#docker) images to build Electron app for Linux or Windows on any platform.
* [Proton Native](https://www.electron.build/configuration/configuration/#proton-native) and [Muon](https://github.com/brave/muon) support.
* [Proton Native](https://www.electron.build/configuration/configuration/#proton-native) support.
* Downloads all required tools files on demand automatically (e.g. to code sign windows application, to make AppX), no need to setup.

| Question | Answer |
Expand Down
29 changes: 4 additions & 25 deletions docker/base/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,12 @@ RUN apt-get -qq update && apt-get -qq dist-upgrade && \
# python for node-gyp
# rpm is required for FPM to build rpm package
# libsecret-1-dev and libgnome-keyring-dev are required even for prebuild keytar
# 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 \
apt-get -qq install --no-install-recommends 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 \
# for snap desktop-gtk3 sudo (see https://github.com/ubuntu/snapcraft-desktop-helpers/blob/master/snapcraft.yaml#L189)
libxkbcommon0 ttf-ubuntu-font-family dmz-cursor-theme light-themes adwaita-icon-theme gnome-themes-standard shared-mime-info libgtk-3-0 libgdk-pixbuf2.0-0 libglib2.0-bin libgtk-3-bin unity-gtk3-module libappindicator3-1 locales-all xdg-user-dirs ibus-gtk3 libibus-1.0-5 \
# snap build packages
apt-transport-https autotools-dev bsdmainutils debhelper dh-strip-nondeterminism file gettext gettext-base gir1.2-atk-1.0 gir1.2-atspi-2.0 gir1.2-freedesktop gir1.2-gdkpixbuf-2.0 gir1.2-gtk-3.0 gir1.2-pango-1.0 groff-base intltool-debian libarchive-zip-perl libasprintf-dev libasprintf0v5 libatk-bridge2.0-dev libatk1.0-dev libatspi2.0-dev libcairo-script-interpreter2 libcairo2-dev libdbus-1-dev libepoxy-dev libexpat1-dev libfile-stripnondeterminism-perl libfontconfig1-dev libfreetype6-dev libgdk-pixbuf2.0-dev libgettextpo-dev libgettextpo0 libgmp-dev libgmpxx4ldbl libgtk-3-dev libharfbuzz-dev libharfbuzz-gobject0 libharfbuzz-icu0 libice-dev libmail-sendmail-perl libpango1.0-dev libpangoxft-1.0-0 libpipeline1 libpixman-1-dev libpng12-dev libsm-dev libsys-hostname-long-perl libtimedate-perl libunistring0 libxcb-shm0-dev libxcomposite-dev libxcursor-dev libxft-dev libxft2 libxi-dev libxinerama-dev libxrandr-dev libxrender-dev libxtst-dev libxtst6 man-db nettle-dev po-debconf x11proto-composite-dev x11proto-randr-dev x11proto-record-dev x11proto-render-dev x11proto-xinerama-dev && \
libopenjp2-tools && \
# git-lfs
git lfs install && \
# snap
apt-get -qq install --no-install-recommends jq squashfs-tools && \
curl -L $(curl -H 'X-Ubuntu-Series: 16' 'https://api.snapcraft.io/api/v1/snaps/details/core' | jq '.download_url' -r) --output core.snap && \
mkdir -p /snap/core && unsquashfs -d /snap/core/current core.snap && rm core.snap && \
curl -L $(curl -H 'X-Ubuntu-Series: 16' 'https://api.snapcraft.io/api/v1/snaps/details/snapcraft?channel=edge' | jq '.download_url' -r) --output snapcraft.snap && \
mkdir -p /snap/snapcraft && unsquashfs -d /snap/snapcraft/current snapcraft.snap && rm snapcraft.snap && \
mkdir -p /snap/bin && \
echo "#!/bin/sh" > /usr/bin/snapcraft && \
echo 'exec $SNAP/usr/bin/python3 $SNAP/bin/snapcraft "$@"' >> /usr/bin/snapcraft && \
chmod a+x /usr/bin/snapcraft && \
apt-get -qq purge jq squashfs-tools && \
rm -rf /var/lib/apt/lists/*
apt-get purge -y --auto-remove && rm -rf /var/lib/apt/lists/*

COPY test.sh /test.sh

Expand All @@ -47,9 +31,4 @@ ENV LC_ALL C.UTF-8
ENV USE_UNZIP true

ENV DEBUG_COLORS true
ENV FORCE_COLOR true

ENV SNAP=/snap/snapcraft/current
ENV SNAP_ARCH=amd64
ENV SNAP_NAME=snapcraft
ENV SNAP_VERSION=edge
ENV FORCE_COLOR true
2 changes: 1 addition & 1 deletion docker/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ set -e

docker build -t electronuserland/builder:base -t electronuserland/builder:base-06.19 docker/base

docker build -t electronuserland/builder:12 -t electronuserland/builder:latest -t electronuserland/builder:12-06.19 docker/12
docker build -t electronuserland/builder:12 -t electronuserland/builder:latest -t electronuserland/builder:12-06.19 docker/node

docker build -t electronuserland/builder:wine docker/wine
docker build -t electronuserland/builder:wine-mono docker/wine-mono
Expand Down
File renamed without changes.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"@types/debug": "^4.1.4",
"@types/is-ci": "^2.0.0",
"@types/semver": "^6.0.0",
"app-builder-bin": "2.6.7",
"app-builder-bin": "2.6.11",
"archiver": "^3.0.0",
"async-exit-hook": "^2.0.1",
"bluebird-lst": "^1.0.9",
Expand Down Expand Up @@ -92,7 +92,7 @@
"@babel/preset-react": "^7.0.0",
"@types/ejs": "^2.6.3",
"@types/ini": "^1.3.30",
"@types/jest": "^24.0.13",
"@types/jest": "^24.0.14",
"@types/js-yaml": "^3.12.1",
"@types/lodash.isequal": "^4.5.5",
"@types/node-emoji": "^1.8.1",
Expand All @@ -117,7 +117,7 @@
"ts-babel": "6.1.4",
"ts-jsdoc": "^3.0.1",
"tslint": "^5.17.0",
"typescript": "~3.5.1",
"typescript": "~3.5.2",
"whitespace": "^2.1.0",
"worker-farm": "^1.7.0"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/app-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": "~4.1.0",
"app-builder-bin": "2.6.7",
"app-builder-bin": "2.6.11",
"async-exit-hook": "^2.0.1",
"bluebird-lst": "^1.0.9",
"chromium-pickle-js": "^0.2.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/app-builder-lib/src/Framework.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,5 @@ export interface PrepareApplicationStageDirectoryOptions {
}

export function isElectronBased(framework: Framework) {
return framework.name === "electron" || framework.name === "muon"
return framework.name === "electron"
}
5 changes: 0 additions & 5 deletions packages/app-builder-lib/src/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,6 @@ export interface Configuration extends PlatformSpecificBuildOptions {
*/
readonly ?: boolean

/**
* The version of muon you are packaging for.
*/
readonly muonVersion?: string | null

/**
* *libui-based frameworks only* The version of NodeJS you are packaging for.
* You can set it to `current` to set the Node.js version that you use to run.
Expand Down
33 changes: 2 additions & 31 deletions packages/app-builder-lib/src/electron/ElectronFramework.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { CONCURRENCY, copyDir, DO_NOT_USE_HARD_LINKS, statOrNull, unlinkIfExists
import { emptyDir, readdir, remove, rename } from "fs-extra-p"
import { Lazy } from "lazy-val"
import * as path from "path"
import * as semver from "semver"
import { Configuration } from "../configuration"
import { BeforeCopyExtraFilesOptions, Framework, PrepareApplicationStageDirectoryOptions } from "../Framework"
import { ElectronPlatformName, Packager, Platform } from "../index"
Expand Down Expand Up @@ -52,22 +51,13 @@ function createDownloadOpts(opts: Configuration, platform: ElectronPlatformName,
}
}

async function beforeCopyExtraFiles(options: BeforeCopyExtraFilesOptions, isClearExecStack: boolean) {
async function beforeCopyExtraFiles(options: BeforeCopyExtraFilesOptions) {
const packager = options.packager
const appOutDir = options.appOutDir
if (packager.platform === Platform.LINUX) {
const linuxPackager = (packager as LinuxPackager)
const executable = path.join(appOutDir, linuxPackager.executableName)
await rename(path.join(appOutDir, packager.electronDistExecutableName), executable)

if (isClearExecStack) {
try {
await executeAppBuilder(["clear-exec-stack", "--input", executable])
}
catch (e) {
log.debug({error: e}, "cannot clear exec stack")
}
}
}
else if (packager.platform === Platform.WINDOWS) {
const executable = path.join(appOutDir, `${packager.appInfo.productFilename}.exe`)
Expand Down Expand Up @@ -126,30 +116,11 @@ class ElectronFramework implements Framework {
}

beforeCopyExtraFiles(options: BeforeCopyExtraFilesOptions) {
return beforeCopyExtraFiles(options, this.name === "electron" && semver.lte(this.version || "1.8.3", "1.8.3"))
}
}

class MuonFramework extends ElectronFramework {
constructor(version: string) {
super("muon", version, "Brave.app")
}

prepareApplicationStageDirectory(options: PrepareApplicationStageDirectoryOptions) {
return unpack(options, {
mirror: "https://github.com/brave/muon/releases/download/v",
customFilename: `brave-v${options.version}-${options.platformName}-${options.arch}.zip`,
isVerifyChecksum: false,
...createDownloadOpts(options.packager.config, options.platformName, options.arch, options.version),
}, this.distMacOsAppName)
return beforeCopyExtraFiles(options)
}
}

export async function createElectronFrameworkSupport(configuration: Configuration, packager: Packager): Promise<Framework> {
if (configuration.muonVersion != null) {
return new MuonFramework(configuration.muonVersion!!)
}

let version = configuration.electronVersion
if (version == null) {
// for prepacked app asar no dev deps in the app.asar
Expand Down
2 changes: 1 addition & 1 deletion packages/app-builder-lib/src/options/SnapOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,4 @@ export interface SnapOptions extends CommonLinuxOptions, TargetSpecificOptions {

export interface PlugDescriptor {
[key: string]: {[key: string]: any} | null
}
}
2 changes: 1 addition & 1 deletion packages/app-builder-lib/src/packager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ export class Packager {
return
}

const frameworkInfo = {version: this.framework.version, useCustomDist: this.config.muonVersion == null}
const frameworkInfo = {version: this.framework.version, useCustomDist: true}
const config = this.config
if (config.nodeGypRebuild === true) {
log.info({arch: Arch[arch]}, "executing node-gyp rebuild")
Expand Down
4 changes: 2 additions & 2 deletions packages/app-builder-lib/src/platformPackager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,11 @@ export abstract class PlatformPackager<DC extends PlatformSpecificBuildOptions>
}

get electronDistExecutableName() {
return this.config.muonVersion == null ? "electron" : "brave"
return "electron"
}

get electronDistMacOsExecutableName() {
return this.config.muonVersion == null ? "Electron" : "Brave"
return "Electron"
}

createGetFileMatchersOptions(outDir: string, arch: Arch, customBuildOptions: PlatformSpecificBuildOptions): GetFileMatchersOptions {
Expand Down
Loading

0 comments on commit 66b1225

Please sign in to comment.