Skip to content

Commit

Permalink
feat(snap): template for armhf (arm 32-bit)
Browse files Browse the repository at this point in the history
  • Loading branch information
develar committed Jul 2, 2019
1 parent 1bd73c9 commit 6853b37
Show file tree
Hide file tree
Showing 12 changed files with 105 additions and 52 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
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 @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion packages/app-builder-lib/src/packager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -147,7 +148,7 @@ export class Packager {
}

stageDirPathCustomizer: (target: Target, packager: PlatformPackager<any>, 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
Expand Down
20 changes: 2 additions & 18 deletions packages/app-builder-lib/src/platformPackager.ts
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -482,24 +483,7 @@ export abstract class PlatformPackager<DC extends PlatformSpecificBuildOptions>
}

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
})
Expand Down
37 changes: 26 additions & 11 deletions packages/app-builder-lib/src/targets/snap.ts
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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<any> {
if (!this.isElectronVersionGreaterOrEqualThen("4.0.0")) {
if (!this.isElectronVersionGreaterOrEqualThen("2.0.0-beta.1")) {
Expand All @@ -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",
Expand Down Expand Up @@ -83,7 +83,7 @@ export default class SnapTarget extends Target {
},
parts: {
app: {
"stage-packages": this.replaceDefault(options.stagePackages, SnapTarget.getDefaultStagePackages()),
"stage-packages": stagePackages,
}
},
})
Expand Down Expand Up @@ -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,
]
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -224,6 +225,14 @@ function archNameToTriplet(arch: Arch): string {
}
}

function isArrayEqualRegardlessOfSort(a: Array<string>, b: Array<string>) {
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<string | PlugDescriptor> | PlugDescriptor | null | undefined): { [key: string]: {[name: string]: any; } | null } | null {
if (raw == null) {
return null
Expand Down Expand Up @@ -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"]
}
27 changes: 27 additions & 0 deletions packages/builder-util/src/arch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
2 changes: 1 addition & 1 deletion packages/electron-builder/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
7 changes: 6 additions & 1 deletion scripts/snap-template.sh
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions test/out/linux/__snapshots__/snapTest.js.snap
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
12 changes: 11 additions & 1 deletion test/src/linux/snapTest.ts
Original file line number Diff line number Diff line change
@@ -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") {
Expand All @@ -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", {
Expand Down
2 changes: 1 addition & 1 deletion test/src/mac/masTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
32 changes: 16 additions & 16 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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=

[email protected], "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"
Expand Down Expand Up @@ -2408,9 +2408,9 @@ [email protected]:
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"
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 6853b37

Please sign in to comment.