From c5f8b0869b761bdeeefbc4e09c0b3baf5c823366 Mon Sep 17 00:00:00 2001 From: Omer Akram Date: Thu, 13 Jan 2022 00:11:53 +0500 Subject: [PATCH] feat(snap): add lzo to Snap compression options (also as new default) (#6201) Signed-off-by: Omer Akram Co-authored-by: Maximilian Federle --- .changeset/spicy-crabs-draw.md | 13 ++ docker/base/Dockerfile | 2 +- packages/app-builder-lib/scheme.json | 19 ++- .../src/options/SnapOptions.ts | 6 + .../src/options/linuxOptions.ts | 2 +- packages/app-builder-lib/src/targets/snap.ts | 6 + .../templates/snap/snapcraft.yaml | 1 + packages/builder-util/package.json | 2 +- pnpm-lock.yaml | 8 +- test/snapshots/linux/snapTest.js.snap | 155 ++++++++++++++++++ test/src/linux/snapTest.ts | 41 +++++ 11 files changed, 247 insertions(+), 8 deletions(-) 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..4fa4d73d216 --- /dev/null +++ b/.changeset/spicy-crabs-draw.md @@ -0,0 +1,13 @@ +--- +"app-builder-lib": minor +"builder-util": major +--- + +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. 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 && \ diff --git a/packages/app-builder-lib/scheme.json b/packages/app-builder-lib/scheme.json index 4bd0561036c..1c387b84d7d 100644 --- a/packages/app-builder-lib/scheme.json +++ b/packages/app-builder-lib/scheme.json @@ -2141,7 +2141,8 @@ "enum": [ "bzip2", "gz", - "xz" + "xz", + "lzo" ], "type": "string" }, @@ -5395,6 +5396,22 @@ "string" ] }, + "compression": { + "anyOf": [ + { + "enum": [ + "xz", + "lzo" + ], + "type": "string" + }, + { + "type": "null" + } + ], + "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.", "type": "boolean" diff --git a/packages/app-builder-lib/src/options/SnapOptions.ts b/packages/app-builder-lib/src/options/SnapOptions.ts index 66b217b6c36..3d1d6658e49 100644 --- a/packages/app-builder-lib/src/options/SnapOptions.ts +++ b/packages/app-builder-lib/src/options/SnapOptions.ts @@ -125,6 +125,12 @@ 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 lzo when not specified. + * @default lzo + */ + readonly compression?: "xz" | "lzo" | null } export interface PlugDescriptor { 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 diff --git a/packages/app-builder-lib/src/targets/snap.ts b/packages/app-builder-lib/src/targets/snap.ts index 4a3438d2390..b170db4a8b5 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: { @@ -207,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 } @@ -221,6 +226,7 @@ export default class SnapTarget extends Target { if (this.isUseTemplateApp) { args.push("--template-url", `electron4:${snapArch}`) } + 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/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: 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", 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 + }, + }) +)