From 6853b37b321bbf34b3bd6c9ec7ff88545b37291f Mon Sep 17 00:00:00 2001 From: develar Date: Tue, 2 Jul 2019 09:45:57 +0200 Subject: [PATCH] feat(snap): template for armhf (arm 32-bit) --- package.json | 2 +- packages/app-builder-lib/package.json | 2 +- packages/app-builder-lib/src/packager.ts | 3 +- .../app-builder-lib/src/platformPackager.ts | 20 +--------- packages/app-builder-lib/src/targets/snap.ts | 37 +++++++++++++------ packages/builder-util/src/arch.ts | 27 ++++++++++++++ packages/electron-builder/package.json | 2 +- scripts/snap-template.sh | 7 +++- test/out/linux/__snapshots__/snapTest.js.snap | 11 ++++++ test/src/linux/snapTest.ts | 12 +++++- test/src/mac/masTest.ts | 2 +- yarn.lock | 32 ++++++++-------- 12 files changed, 105 insertions(+), 52 deletions(-) diff --git a/package.json b/package.json index 01da7a0b82d..aed005dc5b5 100644 --- a/package.json +++ b/package.json @@ -58,7 +58,7 @@ "normalize-package-data": "^2.5.0", "pako": "^1.0.10", "parse-color": "^1.0.0", - "read-config-file": "3.3.0", + "read-config-file": "4.0.0", "sanitize-filename": "^1.6.1", "sax": "^1.2.4", "semver": "^6.1.3", diff --git a/packages/app-builder-lib/package.json b/packages/app-builder-lib/package.json index f240e65ecd4..ae2e7156b1e 100644 --- a/packages/app-builder-lib/package.json +++ b/packages/app-builder-lib/package.json @@ -55,7 +55,7 @@ "is-ci": "^2.0.0", "isbinaryfile": "^4.0.1", "js-yaml": "^3.13.1", - "read-config-file": "3.3.0", + "read-config-file": "4.0.0", "minimatch": "^3.0.4", "normalize-package-data": "^2.5.0", "sanitize-filename": "^1.6.1", diff --git a/packages/app-builder-lib/src/packager.ts b/packages/app-builder-lib/src/packager.ts index c7b5557dba8..c3b6dcc8445 100644 --- a/packages/app-builder-lib/src/packager.ts +++ b/packages/app-builder-lib/src/packager.ts @@ -7,6 +7,7 @@ import { ensureDir, outputFile } from "fs-extra-p" import isCI from "is-ci" import { Lazy } from "lazy-val" import * as path from "path" +import { getArtifactArchName } from "builder-util/out/arch" import { AppInfo } from "./appInfo" import { readAsarJson } from "./asar/asar" import { createElectronFrameworkSupport } from "./electron/ElectronFramework" @@ -147,7 +148,7 @@ export class Packager { } stageDirPathCustomizer: (target: Target, packager: PlatformPackager, arch: Arch) => string = (target, packager, arch) => { - return path.join(target.outDir, `__${target.name}-${Arch[arch]}`) + return path.join(target.outDir, `__${target.name}-${getArtifactArchName(arch, target.name)}`) } private _buildResourcesDir: string | null = null diff --git a/packages/app-builder-lib/src/platformPackager.ts b/packages/app-builder-lib/src/platformPackager.ts index 2236a63fb11..f575a572d18 100644 --- a/packages/app-builder-lib/src/platformPackager.ts +++ b/packages/app-builder-lib/src/platformPackager.ts @@ -1,5 +1,6 @@ import BluebirdPromise from "bluebird-lst" import { Arch, asArray, AsyncTaskManager, debug, DebugLogger, deepAssign, getArchSuffix, InvalidConfigurationError, isEmptyOrSpaces, log, isEnvTrue } from "builder-util" +import { getArtifactArchName } from "builder-util/out/arch" import { FileTransformer, statOrNull } from "builder-util/out/fs" import { orIfFileNotExist } from "builder-util/out/promise" import { readdir } from "fs-extra-p" @@ -482,24 +483,7 @@ export abstract class PlatformPackager } private computeArtifactName(pattern: any, ext: string, arch: Arch | null | undefined): string { - let archName: string | null = arch == null ? null : Arch[arch] - if (arch === Arch.x64) { - if (ext === "AppImage" || ext === "rpm") { - archName = "x86_64" - } - else if (ext === "deb" || ext === "snap") { - archName = "amd64" - } - } - else if (arch === Arch.ia32) { - if (ext === "deb" || ext === "AppImage" || ext === "snap") { - archName = "i386" - } - else if (ext === "pacman" || ext === "rpm") { - archName = "i686" - } - } - + const archName = arch == null ? null : getArtifactArchName(arch, ext) return this.expandMacro(pattern, this.platform === Platform.MAC ? null : archName, { ext }) diff --git a/packages/app-builder-lib/src/targets/snap.ts b/packages/app-builder-lib/src/targets/snap.ts index 8d18b691d0b..d4d3848cbe7 100644 --- a/packages/app-builder-lib/src/targets/snap.ts +++ b/packages/app-builder-lib/src/targets/snap.ts @@ -1,4 +1,4 @@ -import { Arch, deepAssign, executeAppBuilder, replaceDefault as _replaceDefault, serializeToYaml, toLinuxArchString, InvalidConfigurationError, log } from "builder-util" +import { Arch, deepAssign, executeAppBuilder, InvalidConfigurationError, log, replaceDefault as _replaceDefault, serializeToYaml, toLinuxArchString } from "builder-util" import { asArray } from "builder-util-runtime" import { outputFile, readFile } from "fs-extra-p" import { safeLoad } from "js-yaml" @@ -31,12 +31,6 @@ export default class SnapTarget extends Target { return result } - private static getDefaultStagePackages() { - // libxss1 - was "error while loading shared libraries: libXss.so.1" on Xubuntu 16.04 - // noinspection SpellCheckingInspection - return ["libnspr4", "libnss3", "libxss1", "libappindicator3-1", "libsecret-1-0"] - } - private async createDescriptor(arch: Arch): Promise { if (!this.isElectronVersionGreaterOrEqualThen("4.0.0")) { if (!this.isElectronVersionGreaterOrEqualThen("2.0.0-beta.1")) { @@ -54,7 +48,13 @@ export default class SnapTarget extends Target { const plugNames = this.replaceDefault(plugs == null ? null : Object.getOwnPropertyNames(plugs), defaultPlugs) const buildPackages = asArray(options.buildPackages) - this.isUseTemplateApp = this.options.useTemplateApp !== false && arch === Arch.x64 && buildPackages.length === 0 + const defaultStagePackages = getDefaultStagePackages() + const stagePackages = this.replaceDefault(options.stagePackages, defaultStagePackages) + + this.isUseTemplateApp = this.options.useTemplateApp !== false && + (arch === Arch.x64 || arch === Arch.armv7l) && + buildPackages.length === 0 && + isArrayEqualRegardlessOfSort(stagePackages, defaultStagePackages) const appDescriptor: any = { command: "command.sh", @@ -83,7 +83,7 @@ export default class SnapTarget extends Target { }, parts: { app: { - "stage-packages": this.replaceDefault(options.stagePackages, SnapTarget.getDefaultStagePackages()), + "stage-packages": stagePackages, } }, }) @@ -151,11 +151,12 @@ export default class SnapTarget extends Target { } const stageDir = await createStageDirPath(this, packager, arch) + const snapArch = toLinuxArchString(arch, true) const args = [ "snap", "--app", appOutDir, "--stage", stageDir, - "--arch", toLinuxArchString(arch, true), + "--arch", snapArch, "--output", artifactPath, "--executable", this.packager.executableName, ] @@ -195,7 +196,7 @@ export default class SnapTarget extends Target { } if (this.isUseTemplateApp) { - args.push("--template-url", "electron4") + args.push("--template-url", `electron4:${snapArch}`) } await executeAppBuilder(args) @@ -224,6 +225,14 @@ function archNameToTriplet(arch: Arch): string { } } +function isArrayEqualRegardlessOfSort(a: Array, b: Array) { + a = a.slice() + b = b.slice() + a.sort() + b.sort() + return a.length === b.length && a.every((value, index) => value === b[index]) +} + function normalizePlugConfiguration(raw: Array | PlugDescriptor | null | undefined): { [key: string]: {[name: string]: any; } | null } | null { if (raw == null) { return null @@ -251,4 +260,10 @@ function isBrowserSandboxAllowed(snap: any): boolean { } } return false +} + +function getDefaultStagePackages() { + // libxss1 - was "error while loading shared libraries: libXss.so.1" on Xubuntu 16.04 + // noinspection SpellCheckingInspection + return ["libnspr4", "libnss3", "libxss1", "libappindicator3-1", "libsecret-1-0"] } \ No newline at end of file diff --git a/packages/builder-util/src/arch.ts b/packages/builder-util/src/arch.ts index a66ddf61825..89cb1e2091e 100644 --- a/packages/builder-util/src/arch.ts +++ b/packages/builder-util/src/arch.ts @@ -42,4 +42,31 @@ export function archFromString(name: string): Arch { default: throw new Error(`Unsupported arch ${name}`) } +} + +export function getArtifactArchName(arch: Arch, ext: string): string { + let archName = Arch[arch] + const isAppImage = ext === "AppImage" || ext === "appimage" + if (arch === Arch.x64) { + if (isAppImage || ext === "rpm") { + archName = "x86_64" + } + else if (ext === "deb" || ext === "snap") { + archName = "amd64" + } + } + else if (arch === Arch.ia32) { + if (ext === "deb" || isAppImage || ext === "snap") { + archName = "i386" + } + else if (ext === "pacman" || ext === "rpm") { + archName = "i686" + } + } + else if (arch === Arch.armv7l) { + if (ext === "snap") { + archName = "armhf" + } + } + return archName } \ No newline at end of file diff --git a/packages/electron-builder/package.json b/packages/electron-builder/package.json index a6b047b7c83..699a762eca6 100644 --- a/packages/electron-builder/package.json +++ b/packages/electron-builder/package.json @@ -51,7 +51,7 @@ "builder-util": "0.0.0-semantic-release", "fs-extra-p": "^8.1.0", "is-ci": "^2.0.0", - "read-config-file": "3.3.0", + "read-config-file": "4.0.0", "sanitize-filename": "^1.6.1", "update-notifier": "^3.0.0", "yargs": "^13.2.4", diff --git a/scripts/snap-template.sh b/scripts/snap-template.sh index d1496eaf3fa..c5f451093aa 100755 --- a/scripts/snap-template.sh +++ b/scripts/snap-template.sh @@ -1,11 +1,16 @@ #!/usr/bin/env bash -cd ~ +cd ~ || exit rm -rf ~/squashfs-root unsquashfs /media/psf/ramdisk/electron-builder-test/dist/__snap-x64/se-wo-template_1.1.0_amd64.snap rm -rf ~/squashfs-root/app ~/squashfs-root/snap ~/squashfs-root/meta ~/squashfs-root/command.sh +# cannot be removed as part of snapcraft yaml because not clear, maybe these dirs requried for custom stage packages +rm -rf ~/squashfs-root/etc ~/squashfs-root/var +#rm -f /home/develar/snap-template-electron-4.0.tar.7z && cd ~/squashfs-root && tar cf - . | zstd -22 --ultra --long -o ~/snap-template-electron-4.0.tar.zstd rm -f /home/develar/snap-template-electron-4.0.tar.7z && cd ~/squashfs-root && tar cf - . | 7za a -mx=9 -mfb=64 -si ~/snap-template-electron-4.0.tar.7z +#rm -f /home/develar/snap-template-electron-4.0.tar.7z && cd ~/squashfs-root && tar cf - . | 7za a -mx=9 -mfb=64 -si ~/snap-template-electron-4.0-1-arm.tar.7z + mv ~/snap-template-electron-4.0.tar.7z /media/psf/ramdisk/snap-template-electron-4.0.tar.7z shasum -a 512 /Volumes/ramdisk/snap-template-electron-4.0.tar.7z | xxd -r -p | base64 \ No newline at end of file diff --git a/test/out/linux/__snapshots__/snapTest.js.snap b/test/out/linux/__snapshots__/snapTest.js.snap index 537c854eabb..bf21cc3b3e6 100644 --- a/test/out/linux/__snapshots__/snapTest.js.snap +++ b/test/out/linux/__snapshots__/snapTest.js.snap @@ -1,5 +1,16 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`arm 1`] = ` +Object { + "linux": Array [ + Object { + "arch": "armv7l", + "file": "sep_1.1.0_armhf.snap", + }, + ], +} +`; + exports[`buildPackages 1`] = ` Object { "apps": Object { diff --git a/test/src/linux/snapTest.ts b/test/src/linux/snapTest.ts index d10b870860a..b2a7a46f37d 100644 --- a/test/src/linux/snapTest.ts +++ b/test/src/linux/snapTest.ts @@ -1,4 +1,4 @@ -import { Platform } from "electron-builder" +import { Arch, Platform } from "electron-builder" import { app, assertPack, snapTarget } from "../helpers/packTester" if (process.env.SNAP_TEST === "false") { @@ -22,6 +22,16 @@ test.ifAll.ifDevOrLinuxCi("snap", app({ }, })) +test.ifAll.ifDevOrLinuxCi("arm", app({ + targets: Platform.LINUX.createTarget("snap", Arch.armv7l), + config: { + extraMetadata: { + name: "sep", + }, + productName: "Sep", + }, +})) + test.ifAll.ifDevOrLinuxCi("default stagePackages", async () => { for (const p of [["default"], ["default", "custom"], ["custom", "default"], ["foo1", "default", "foo2"]]) { await assertPack("test-app-one", { diff --git a/test/src/mac/masTest.ts b/test/src/mac/masTest.ts index 13f66cc693c..f54e39ac6f7 100644 --- a/test/src/mac/masTest.ts +++ b/test/src/mac/masTest.ts @@ -19,7 +19,7 @@ test.ifNotCi("mas", createMacTargetTest(["mas"])) test.ifNotCi.ifAll("dev", createMacTargetTest(["mas-dev"])) test.ifNotCi.ifAll("mas and 7z", createMacTargetTest(["mas", "7z"])) -test.ifAll("custom mas", () => { +test.skip.ifAll("custom mas", () => { let platformPackager: CheckingMacPackager | null = null return assertPack("test-app-one", signed({ targets: Platform.MAC.createTarget(), diff --git a/yarn.lock b/yarn.lock index 86cbb6f2404..c71119fc0a1 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1820,9 +1820,9 @@ camelcase@^5.0.0, camelcase@^5.3.1: integrity sha512-L28STB170nwWS63UjtlEOE3dldQApaJXZkOI1uMFfzf3rRuPegHaHesyee+YxQ+W6SvRDQV6UrdOdRiR153wJg== caniuse-lite@^1.0.30000975: - version "1.0.30000978" - resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30000978.tgz#1e3346c27fc46bce9ac1ccd77863153a263dde56" - integrity sha512-H6gK6kxUzG6oAwg/Jal279z8pHw0BzrpZfwo/CA9FFm/vA0l8IhDfkZtepyJNE2Y4V6Dp3P3ubz6czby1/Mgsw== + version "1.0.30000979" + resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30000979.tgz#92f16d00186a6cf20d6c5711bb6e042a3d667029" + integrity sha512-gcu45yfq3B7Y+WB05fOMfr0EiSlq+1u+m6rPHyJli/Wy3PVQNGaU7VA4bZE5qw+AU2UVOBR/N5g1bzADUqdvFw== capture-exit@^2.0.0: version "2.0.0" @@ -2125,17 +2125,17 @@ crypto-random-string@^1.0.0: resolved "https://registry.yarnpkg.com/crypto-random-string/-/crypto-random-string-1.0.0.tgz#a230f64f568310e1498009940790ec99545bca7e" integrity sha1-ojD2T1aDEOFJgAmUB5DsmVRbyn4= -cssom@0.3.x, "cssom@>= 0.3.2 < 0.4.0": +"cssom@>= 0.3.2 < 0.4.0", cssom@~0.3.6: version "0.3.6" resolved "https://registry.yarnpkg.com/cssom/-/cssom-0.3.6.tgz#f85206cee04efa841f3c5982a74ba96ab20d65ad" integrity sha512-DtUeseGk9/GBW0hl0vVPpU22iHL6YB5BUX7ml1hB+GMpo0NX5G4voX3kdWiMSEguFtcW3Vh3djqNF4aIe6ne0A== cssstyle@^1.0.0: - version "1.2.2" - resolved "https://registry.yarnpkg.com/cssstyle/-/cssstyle-1.2.2.tgz#427ea4d585b18624f6fdbf9de7a2a1a3ba713077" - integrity sha512-43wY3kl1CVQSvL7wUY1qXkxVGkStjpkDmVjiIKX8R97uhajy8Bybay78uOtqvh7Q5GK75dNPfW0geWjE6qQQow== + version "1.3.0" + resolved "https://registry.yarnpkg.com/cssstyle/-/cssstyle-1.3.0.tgz#c36c466f7037fd30f03baa271b65f0f17b50585c" + integrity sha512-wXsoRfsRfsLVNaVzoKdqvEmK/5PFaEXNspVT22Ots6K/cnJdpoDKuQFw+qlMiXnmaif1OgeC466X1zISgAOcGg== dependencies: - cssom "0.3.x" + cssom "~0.3.6" dashdash@^1.12.0: version "1.14.1" @@ -2408,9 +2408,9 @@ electron-osx-sign@0.4.11: plist "^3.0.1" electron-to-chromium@^1.3.164: - version "1.3.179" - resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.179.tgz#908efa2732ca07ede53bbbb25bb6684623fbe069" - integrity sha512-hRjlOdKImgIRicKYRY6hHbUMrX2NJYBrIusTepwPt/apcabuzrzhXpkkWu7elWdTZEQwKV6BfX8EvWIBWLCNQw== + version "1.3.181" + resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.181.tgz#1c538401af8f3eb285db893b66e43f4bea72fd83" + integrity sha512-xf1dCoc6FSCVcNQu8VGiMSH55rOT/ov6U7UpMgw4Erg5KfD1LHTXqm34/IGp55TLX4WqwuT4IIeJWhdGhO8mYw== emoji-regex@^7.0.1: version "7.0.3" @@ -4932,17 +4932,17 @@ react-is@^16.8.4: resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.8.6.tgz#5bbc1e2d29141c9fbdfed456343fe2bc430a6a16" integrity sha512-aUk3bHfZ2bRSVFFbbeVS4i+lNPZr3/WM5jT2J5omUVV1zzcs1nAaf3l51ctA5FFvCRbhrH0bdAsRRQddFJZPtA== -read-config-file@3.3.0: - version "3.3.0" - resolved "https://registry.yarnpkg.com/read-config-file/-/read-config-file-3.3.0.tgz#fdb81476372aa63d39dc74b3b1393e5970d0decf" - integrity sha512-VzA1UVvNwEYQi9wGVa7Cji/E6YNr3VwbPXUcHed00cYoZsqg1kYcMnHgIx8nt0NQjFz/ai/8n8Xq0rmHD153Gg== +read-config-file@4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/read-config-file/-/read-config-file-4.0.0.tgz#d57d6edc3a4c8a0999860e57e85664570ef56cd5" + integrity sha512-ZEqYePqjCkOoZu+HFhpjSB0r1eJ7RNNqf8O5/oxPT85b7ZB910au4AGxxxuJ1b81atdmBpiyODonI6vnefVIAA== dependencies: ajv "^6.10.0" ajv-keywords "^3.4.0" bluebird-lst "^1.0.9" dotenv "^8.0.0" dotenv-expand "^5.1.0" - fs-extra-p "^8.0.2" + fs-extra "^8.1.0" js-yaml "^3.13.1" json5 "^2.1.0" lazy-val "^1.0.4"