From 8ea8928701bf8170d0e95da620e1a6137d8d2f6b Mon Sep 17 00:00:00 2001 From: Omer Akram Date: Sun, 29 Aug 2021 03:51:33 +0500 Subject: [PATCH 1/8] feat(snap): add Snap compression option Signed-off-by: Omer Akram --- packages/app-builder-lib/scheme.json | 16 ++++++++++++++++ .../app-builder-lib/src/options/SnapOptions.ts | 5 +++++ packages/app-builder-lib/src/targets/snap.ts | 1 + 3 files changed, 22 insertions(+) diff --git a/packages/app-builder-lib/scheme.json b/packages/app-builder-lib/scheme.json index e0698864005..91d7a71e3ff 100644 --- a/packages/app-builder-lib/scheme.json +++ b/packages/app-builder-lib/scheme.json @@ -5400,6 +5400,22 @@ "string" ] }, + "compression": { + "anyOf": [ + { + "enum": [ + "xz", + "lzo" + ], + "type": "string" + }, + { + "type": "null" + } + ], + "default": "xz", + "description": "Sets the compression type for the snap. Can be xz or lzo. Defaults to xz when not specified." + }, "useTemplateApp": { "description": "Whether to use template snap. Defaults to `true` if `stagePackages` not specified.", "type": "boolean" diff --git a/packages/app-builder-lib/src/options/SnapOptions.ts b/packages/app-builder-lib/src/options/SnapOptions.ts index 66b217b6c36..41692536756 100644 --- a/packages/app-builder-lib/src/options/SnapOptions.ts +++ b/packages/app-builder-lib/src/options/SnapOptions.ts @@ -125,6 +125,11 @@ export interface SnapOptions extends CommonLinuxOptions, TargetSpecificOptions { * An optional title for the snap, may contain uppercase letters and spaces. Defaults to `productName`. See [snap format documentation](https://snapcraft.io/docs/snap-format). */ readonly title?: string | null + + /** + * Sets the compression type for the snap. Can be xz or lzo. Defaults to xz when not specified. + */ + readonly compression?: "xz" | "lzo" | null } export interface PlugDescriptor { diff --git a/packages/app-builder-lib/src/targets/snap.ts b/packages/app-builder-lib/src/targets/snap.ts index 4a3438d2390..7f1dbd723f1 100644 --- a/packages/app-builder-lib/src/targets/snap.ts +++ b/packages/app-builder-lib/src/targets/snap.ts @@ -100,6 +100,7 @@ export default class SnapTarget extends Target { version: appInfo.version, title: options.title || appInfo.productName, summary: options.summary || appInfo.productName, + compression: options.compression, description: this.helper.getDescription(options), architectures: [toLinuxArchString(arch, "snap")], apps: { From 531acddfe4f380270c09dccff307c849c7dd42e6 Mon Sep 17 00:00:00 2001 From: Omer Akram Date: Sun, 29 Aug 2021 04:34:47 +0500 Subject: [PATCH 2/8] add lzo compression to linux options Signed-off-by: Omer Akram --- packages/app-builder-lib/scheme.json | 3 ++- packages/app-builder-lib/src/options/linuxOptions.ts | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/app-builder-lib/scheme.json b/packages/app-builder-lib/scheme.json index 91d7a71e3ff..bf423a3e8a3 100644 --- a/packages/app-builder-lib/scheme.json +++ b/packages/app-builder-lib/scheme.json @@ -2146,7 +2146,8 @@ "enum": [ "bzip2", "gz", - "xz" + "xz", + "lzo" ], "type": "string" }, diff --git a/packages/app-builder-lib/src/options/linuxOptions.ts b/packages/app-builder-lib/src/options/linuxOptions.ts index 8b84e140c70..8bb1214ad1d 100644 --- a/packages/app-builder-lib/src/options/linuxOptions.ts +++ b/packages/app-builder-lib/src/options/linuxOptions.ts @@ -77,7 +77,7 @@ export interface LinuxTargetSpecificOptions extends CommonLinuxOptions, TargetSp * The compression type. * @default xz */ - readonly compression?: "gz" | "bzip2" | "xz" | null + readonly compression?: "gz" | "bzip2" | "xz" | "lzo" | null readonly icon?: string From 2fe80b42f681baab1a9b6e7a859c3f11474c1a84 Mon Sep 17 00:00:00 2001 From: Maximilian Federle Date: Thu, 2 Dec 2021 17:56:00 +0100 Subject: [PATCH 3/8] changes for https://github.com/electron-userland/electron-builder/pull/6201 (#1) * use new app-builder-bin & hook up compression option * set default snap compression type to lzo --- packages/app-builder-lib/scheme.json | 4 ++-- packages/app-builder-lib/src/targets/snap.ts | 4 ++++ packages/builder-util/package.json | 2 +- pnpm-lock.yaml | 8 ++++---- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/packages/app-builder-lib/scheme.json b/packages/app-builder-lib/scheme.json index bf423a3e8a3..b765278bb94 100644 --- a/packages/app-builder-lib/scheme.json +++ b/packages/app-builder-lib/scheme.json @@ -5414,8 +5414,8 @@ "type": "null" } ], - "default": "xz", - "description": "Sets the compression type for the snap. Can be xz or lzo. Defaults to xz when not specified." + "default": "lzo", + "description": "Sets the compression type for the snap. Can be xz or lzo. Defaults to lzo when not specified." }, "useTemplateApp": { "description": "Whether to use template snap. Defaults to `true` if `stagePackages` not specified.", diff --git a/packages/app-builder-lib/src/targets/snap.ts b/packages/app-builder-lib/src/targets/snap.ts index 7f1dbd723f1..e6e0dbc99b3 100644 --- a/packages/app-builder-lib/src/targets/snap.ts +++ b/packages/app-builder-lib/src/targets/snap.ts @@ -222,6 +222,10 @@ export default class SnapTarget extends Target { if (this.isUseTemplateApp) { args.push("--template-url", `electron4:${snapArch}`) } + + if (options.compression != null) { + args.push("--compression", options.compression) + } await executeAppBuilder(args) await packager.info.callArtifactBuildCompleted({ diff --git a/packages/builder-util/package.json b/packages/builder-util/package.json index 6ba38574ed9..a8729b06a05 100644 --- a/packages/builder-util/package.json +++ b/packages/builder-util/package.json @@ -18,7 +18,7 @@ "7zip-bin": "~5.1.1", "@types/debug": "^4.1.6", "@types/fs-extra": "^9.0.11", - "app-builder-bin": "3.7.1", + "app-builder-bin": "4.1.0", "bluebird-lst": "^1.0.9", "builder-util-runtime": "workspace:*", "chalk": "^4.1.1", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 5eb17c576b8..40fd061bfb0 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -183,7 +183,7 @@ importers: '@types/js-yaml': 4.0.3 '@types/source-map-support': 0.5.4 7zip-bin: ~5.1.1 - app-builder-bin: 3.7.1 + app-builder-bin: 4.1.0 bluebird-lst: ^1.0.9 builder-util-runtime: workspace:* chalk: ^4.1.1 @@ -201,7 +201,7 @@ importers: '@types/debug': 4.1.7 '@types/fs-extra': 9.0.13 7zip-bin: 5.1.1 - app-builder-bin: 3.7.1 + app-builder-bin: 4.1.0 bluebird-lst: 1.0.9 builder-util-runtime: link:../builder-util-runtime chalk: 4.1.2 @@ -3145,8 +3145,8 @@ packages: normalize-path: 3.0.0 picomatch: 2.3.0 - /app-builder-bin/3.7.1: - resolution: {integrity: sha512-ql93vEUq6WsstGXD+SBLSIQw6SNnhbDEM0swzgugytMxLp3rT24Ag/jcC80ZHxiPRTdew1niuR7P3/FCrDqIjw==} + /app-builder-bin/4.1.0: + resolution: {integrity: sha512-rbdMe0sIVE95cpYqMQh4IFqhTDdB8LkKlTRcbO/Y3QleRYoIePejIbX774IYomYYzZbJfJuX7pLRiGvSdIxIYA==} dev: false /archiver-utils/2.1.0: From 8cfeaa5816b5c5a7c4b8c17b0884b21f7a970c86 Mon Sep 17 00:00:00 2001 From: Maximilian Federle Date: Mon, 6 Dec 2021 18:59:16 +0100 Subject: [PATCH 4/8] actually set lzo as default & add tests (#2) * make lzo the compression default in snap options * add lzo compression to snapcraft template * construct compression arg from descriptor * add tests for snap compression option --- .../src/options/SnapOptions.ts | 3 +- packages/app-builder-lib/src/targets/snap.ts | 7 ++-- .../templates/snap/snapcraft.yaml | 1 + test/src/linux/snapTest.ts | 41 +++++++++++++++++++ 4 files changed, 48 insertions(+), 4 deletions(-) diff --git a/packages/app-builder-lib/src/options/SnapOptions.ts b/packages/app-builder-lib/src/options/SnapOptions.ts index 41692536756..3d1d6658e49 100644 --- a/packages/app-builder-lib/src/options/SnapOptions.ts +++ b/packages/app-builder-lib/src/options/SnapOptions.ts @@ -127,7 +127,8 @@ export interface SnapOptions extends CommonLinuxOptions, TargetSpecificOptions { readonly title?: string | null /** - * Sets the compression type for the snap. Can be xz or lzo. Defaults to xz when not specified. + * Sets the compression type for the snap. Can be xz or lzo. Defaults to lzo when not specified. + * @default lzo */ readonly compression?: "xz" | "lzo" | null } diff --git a/packages/app-builder-lib/src/targets/snap.ts b/packages/app-builder-lib/src/targets/snap.ts index e6e0dbc99b3..b170db4a8b5 100644 --- a/packages/app-builder-lib/src/targets/snap.ts +++ b/packages/app-builder-lib/src/targets/snap.ts @@ -208,6 +208,10 @@ export default class SnapTarget extends Target { } } + if (snap.compression != null) { + args.push("--compression", snap.compression) + } + if (packager.packagerOptions.effectiveOptionComputed != null && (await packager.packagerOptions.effectiveOptionComputed({ snap, desktopFile, args }))) { return } @@ -223,9 +227,6 @@ export default class SnapTarget extends Target { args.push("--template-url", `electron4:${snapArch}`) } - if (options.compression != null) { - args.push("--compression", options.compression) - } await executeAppBuilder(args) await packager.info.callArtifactBuildCompleted({ diff --git a/packages/app-builder-lib/templates/snap/snapcraft.yaml b/packages/app-builder-lib/templates/snap/snapcraft.yaml index 08ed9604b8e..bfbc6142686 100644 --- a/packages/app-builder-lib/templates/snap/snapcraft.yaml +++ b/packages/app-builder-lib/templates/snap/snapcraft.yaml @@ -1,6 +1,7 @@ base: core18 grade: stable confinement: strict +compression: lzo parts: launch-scripts: plugin: dump diff --git a/test/src/linux/snapTest.ts b/test/src/linux/snapTest.ts index 9853964bef4..48fd03014d7 100644 --- a/test/src/linux/snapTest.ts +++ b/test/src/linux/snapTest.ts @@ -255,3 +255,44 @@ test.ifAll.ifDevOrLinuxCi( }, }) ) + +test.ifDevOrLinuxCi( + "default compression", + app({ + targets: snapTarget, + config: { + extraMetadata: { + name: "sep", + }, + productName: "Sep", + }, + effectiveOptionComputed: async ({ snap, args }) => { + expect(snap).toMatchSnapshot() + expect(snap.compression).toEqual("lzo") + expect(args).toEqual(expect.arrayContaining(["--compression", "lzo"])) + return true + }, + }) +) + +test.ifDevOrLinuxCi( + "compression option", + app({ + targets: snapTarget, + config: { + extraMetadata: { + name: "sep", + }, + productName: "Sep", + snap: { + compression: "xz" + } + }, + effectiveOptionComputed: async ({ snap, args }) => { + expect(snap).toMatchSnapshot() + expect(snap.compression).toEqual("xz") + expect(args).toEqual(expect.arrayContaining(["--compression", "xz"])) + return true + }, + }) +) From 5fd9ab7182807b92d81e93eac1277579c09d904d Mon Sep 17 00:00:00 2001 From: Maximilian Federle Date: Tue, 7 Dec 2021 10:21:28 +0100 Subject: [PATCH 5/8] update jest snapshots for snap tests (#3) --- test/snapshots/linux/snapTest.js.snap | 155 ++++++++++++++++++++++++++ 1 file changed, 155 insertions(+) diff --git a/test/snapshots/linux/snapTest.js.snap b/test/snapshots/linux/snapTest.js.snap index 0184fbe7db0..b7c3e1b2e49 100644 --- a/test/snapshots/linux/snapTest.js.snap +++ b/test/snapshots/linux/snapTest.js.snap @@ -44,6 +44,7 @@ Object { "amd64", ], "base": "core18", + "compression": "lzo", "confinement": "strict", "description": "Test Application (test quite “ #378)", "grade": "stable", @@ -115,6 +116,7 @@ Object { "amd64", ], "base": "core18", + "compression": "lzo", "confinement": "strict", "description": "Test Application (test quite “ #378)", "grade": "stable", @@ -306,6 +308,77 @@ Object { } `; +exports[`compression option 1`] = ` +Object { + "apps": Object { + "sep": Object { + "command": "command.sh", + "environment": Object { + "DISABLE_WAYLAND": "1", + "LD_LIBRARY_PATH": "$SNAP_LIBRARY_PATH:$SNAP/lib:$SNAP/usr/lib:$SNAP/lib/x86_64-linux-gnu:$SNAP/usr/lib/x86_64-linux-gnu:$LD_LIBRARY_PATH:$SNAP/lib:$SNAP/usr/lib:$SNAP/lib/x86_64-linux-gnu:$SNAP/usr/lib/x86_64-linux-gnu", + "PATH": "$SNAP/usr/sbin:$SNAP/usr/bin:$SNAP/sbin:$SNAP/bin:$PATH", + "SNAP_DESKTOP_RUNTIME": "$SNAP/gnome-platform", + "TMPDIR": "$XDG_RUNTIME_DIR", + }, + "plugs": Array [ + "desktop", + "desktop-legacy", + "home", + "x11", + "wayland", + "unity7", + "browser-support", + "network", + "gsettings", + "audio-playback", + "pulseaudio", + "opengl", + ], + }, + }, + "architectures": Array [ + "amd64", + ], + "base": "core18", + "compression": "xz", + "confinement": "strict", + "description": "Test Application (test quite “ #378)", + "grade": "stable", + "name": "sep", + "plugs": Object { + "gnome-3-28-1804": Object { + "default-provider": "gnome-3-28-1804", + "interface": "content", + "target": "$SNAP/gnome-platform", + }, + "gtk-3-themes": Object { + "default-provider": "gtk-common-themes", + "interface": "content", + "target": "$SNAP/data-dir/themes", + }, + "icon-themes": Object { + "default-provider": "gtk-common-themes", + "interface": "content", + "target": "$SNAP/data-dir/icons", + }, + "sound-themes": Object { + "default-provider": "gtk-common-themes", + "interface": "content", + "target": "$SNAP/data-dir/sounds", + }, + }, + "summary": "Sep", + "title": "Sep", + "version": "1.1.0", +} +`; + +exports[`compression option 2`] = ` +Object { + "linux": Array [], +} +`; + exports[`custom after, no desktop 1`] = ` Object { "apps": Object { @@ -338,6 +411,7 @@ Object { "amd64", ], "base": "core18", + "compression": "lzo", "confinement": "strict", "description": "Test Application (test quite “ #378)", "grade": "stable", @@ -409,6 +483,7 @@ Object { "amd64", ], "base": "core18", + "compression": "lzo", "confinement": "strict", "description": "Test Application (test quite “ #378)", "grade": "stable", @@ -447,6 +522,77 @@ Object { } `; +exports[`default compression 1`] = ` +Object { + "apps": Object { + "sep": Object { + "command": "command.sh", + "environment": Object { + "DISABLE_WAYLAND": "1", + "LD_LIBRARY_PATH": "$SNAP_LIBRARY_PATH:$SNAP/lib:$SNAP/usr/lib:$SNAP/lib/x86_64-linux-gnu:$SNAP/usr/lib/x86_64-linux-gnu:$LD_LIBRARY_PATH:$SNAP/lib:$SNAP/usr/lib:$SNAP/lib/x86_64-linux-gnu:$SNAP/usr/lib/x86_64-linux-gnu", + "PATH": "$SNAP/usr/sbin:$SNAP/usr/bin:$SNAP/sbin:$SNAP/bin:$PATH", + "SNAP_DESKTOP_RUNTIME": "$SNAP/gnome-platform", + "TMPDIR": "$XDG_RUNTIME_DIR", + }, + "plugs": Array [ + "desktop", + "desktop-legacy", + "home", + "x11", + "wayland", + "unity7", + "browser-support", + "network", + "gsettings", + "audio-playback", + "pulseaudio", + "opengl", + ], + }, + }, + "architectures": Array [ + "amd64", + ], + "base": "core18", + "compression": "lzo", + "confinement": "strict", + "description": "Test Application (test quite “ #378)", + "grade": "stable", + "name": "sep", + "plugs": Object { + "gnome-3-28-1804": Object { + "default-provider": "gnome-3-28-1804", + "interface": "content", + "target": "$SNAP/gnome-platform", + }, + "gtk-3-themes": Object { + "default-provider": "gtk-common-themes", + "interface": "content", + "target": "$SNAP/data-dir/themes", + }, + "icon-themes": Object { + "default-provider": "gtk-common-themes", + "interface": "content", + "target": "$SNAP/data-dir/icons", + }, + "sound-themes": Object { + "default-provider": "gtk-common-themes", + "interface": "content", + "target": "$SNAP/data-dir/sounds", + }, + }, + "summary": "Sep", + "title": "Sep", + "version": "1.1.0", +} +`; + +exports[`default compression 2`] = ` +Object { + "linux": Array [], +} +`; + exports[`default stagePackages 1`] = ` Object { "apps": Object { @@ -459,6 +605,7 @@ Object { "amd64", ], "base": "core18", + "compression": "lzo", "confinement": "classic", "description": "Test Application (test quite “ #378)", "grade": "stable", @@ -624,6 +771,7 @@ Object { "amd64", ], "base": "core18", + "compression": "lzo", "confinement": "classic", "description": "Test Application (test quite “ #378)", "grade": "stable", @@ -790,6 +938,7 @@ Object { "amd64", ], "base": "core18", + "compression": "lzo", "confinement": "classic", "description": "Test Application (test quite “ #378)", "grade": "stable", @@ -956,6 +1105,7 @@ Object { "amd64", ], "base": "core18", + "compression": "lzo", "confinement": "classic", "description": "Test Application (test quite “ #378)", "grade": "stable", @@ -1133,6 +1283,7 @@ Object { "amd64", ], "base": "core18", + "compression": "lzo", "confinement": "strict", "description": "Test Application (test quite “ #378)", "grade": "stable", @@ -1194,6 +1345,7 @@ Object { "amd64", ], "base": "core18", + "compression": "lzo", "confinement": "strict", "description": "Test Application (test quite “ #378)", "grade": "stable", @@ -1396,6 +1548,7 @@ Object { "amd64", ], "base": "core18", + "compression": "lzo", "confinement": "strict", "description": "Test Application (test quite “ #378)", "grade": "stable", @@ -1611,6 +1764,7 @@ Object { "amd64", ], "base": "core18", + "compression": "lzo", "confinement": "strict", "description": "Test Application (test quite “ #378)", "grade": "stable", @@ -1685,6 +1839,7 @@ Object { "amd64", ], "base": "core18", + "compression": "lzo", "confinement": "strict", "description": "Test Application (test quite “ #378)", "grade": "stable", From 80ecf40dac4e3af20322c79fce21ce569498deb8 Mon Sep 17 00:00:00 2001 From: Maximilian Federle Date: Wed, 22 Dec 2021 16:57:41 +0100 Subject: [PATCH 6/8] add changeset (#4) --- .changeset/spicy-crabs-draw.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 .changeset/spicy-crabs-draw.md diff --git a/.changeset/spicy-crabs-draw.md b/.changeset/spicy-crabs-draw.md new file mode 100644 index 00000000000..049fdddbc1e --- /dev/null +++ b/.changeset/spicy-crabs-draw.md @@ -0,0 +1,12 @@ +--- +"app-builder-lib": minor +--- + +Default to LZO compression for snap packages. +This greatly improves cold startup performance (https://snapcraft.io/blog/why-lzo-was-chosen-as-the-new-compression-method). +LZO has already been adopted by most desktop-oriented snaps outside of the Electron realm. + +For the rare case where developers prefer a smaller file size (XZ) to vastly improved decompression performance (LZO), +provide an option to override the default compression method. + +Consumers do not need to update their configuration unless they specifically want to stick to XZ compression. From ff23078731115cf91eaaf48bfa51fff43d94654e Mon Sep 17 00:00:00 2001 From: Maximilian Federle Date: Wed, 29 Dec 2021 17:36:14 +0100 Subject: [PATCH 7/8] changeset: Add major version bump for builder-util (#5) --- .changeset/spicy-crabs-draw.md | 1 + 1 file changed, 1 insertion(+) diff --git a/.changeset/spicy-crabs-draw.md b/.changeset/spicy-crabs-draw.md index 049fdddbc1e..4fa4d73d216 100644 --- a/.changeset/spicy-crabs-draw.md +++ b/.changeset/spicy-crabs-draw.md @@ -1,5 +1,6 @@ --- "app-builder-lib": minor +"builder-util": major --- Default to LZO compression for snap packages. From 77c00af9d16d60cf30cc71cc7f71e1c8e00f3426 Mon Sep 17 00:00:00 2001 From: Maximilian Federle Date: Sun, 9 Jan 2022 18:46:21 +0100 Subject: [PATCH 8/8] add liblzo2-2 to base dockerfile (#6) --- docker/base/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/base/Dockerfile b/docker/base/Dockerfile index 8e0b20b00a6..4f84550fae5 100644 --- a/docker/base/Dockerfile +++ b/docker/base/Dockerfile @@ -13,7 +13,7 @@ RUN apt-get -qq update && apt-get -qq dist-upgrade && \ apt-get -qq install --no-install-recommends \ qtbase5-dev build-essential autoconf libssl-dev gcc-multilib g++-multilib \ lzip rpm python libcurl4 git git-lfs ssh unzip libarchive-tools \ - libxtst6 libsecret-1-dev libopenjp2-tools \ + libxtst6 libsecret-1-dev libopenjp2-tools liblzo2-2 \ && \ # git-lfs git lfs install && \