From 67f0c9dffac93b760622e78926055541882ea0c6 Mon Sep 17 00:00:00 2001 From: Mike Jerred Date: Tue, 6 Sep 2022 23:59:30 +0100 Subject: [PATCH] fix: strip extra fields out before creating snap.yaml (#7104) --- packages/app-builder-lib/src/targets/snap.ts | 12 ++- test/snapshots/linux/snapTest.js.snap | 81 +++++++++++++++++--- test/src/helpers/packTester.ts | 2 +- test/src/linux/snapTest.ts | 42 ++++++++-- 4 files changed, 112 insertions(+), 25 deletions(-) diff --git a/packages/app-builder-lib/src/targets/snap.ts b/packages/app-builder-lib/src/targets/snap.ts index 2f7dd22c7cf..8b455a93680 100644 --- a/packages/app-builder-lib/src/targets/snap.ts +++ b/packages/app-builder-lib/src/targets/snap.ts @@ -124,7 +124,6 @@ export default class SnapTarget extends Target { const archTriplet = archNameToTriplet(arch) appDescriptor.environment = { DISABLE_WAYLAND: options.allowNativeWayland ? "" : "1", - TMPDIR: "$XDG_RUNTIME_DIR", PATH: "$SNAP/usr/sbin:$SNAP/usr/bin:$SNAP/sbin:$SNAP/bin:$PATH", SNAP_DESKTOP_RUNTIME: "$SNAP/gnome-platform", LD_LIBRARY_PATH: [ @@ -175,9 +174,6 @@ export default class SnapTarget extends Target { }) const snap = await this.createDescriptor(arch) - if (this.isUseTemplateApp) { - delete snap.parts - } const stageDir = await createStageDirPath(this, packager, arch) const snapArch = toLinuxArchString(arch, "snap") @@ -210,6 +206,14 @@ export default class SnapTarget extends Target { args.push("--compression", snap.compression) } + if (this.isUseTemplateApp) { + // remove fields that are valid in snapcraft.yaml, but not snap.yaml + const fieldsToStrip = ["compression", "contact", "donation", "issues", "parts", "source-code", "website"] + for (const field of fieldsToStrip) { + delete snap[field] + } + } + if (packager.packagerOptions.effectiveOptionComputed != null && (await packager.packagerOptions.effectiveOptionComputed({ snap, desktopFile, args }))) { return } diff --git a/test/snapshots/linux/snapTest.js.snap b/test/snapshots/linux/snapTest.js.snap index 104f71b6ecf..a8d908e4baf 100644 --- a/test/snapshots/linux/snapTest.js.snap +++ b/test/snapshots/linux/snapTest.js.snap @@ -22,7 +22,6 @@ Object { "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", @@ -93,7 +92,6 @@ Object { "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", @@ -316,7 +314,6 @@ Object { "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", @@ -338,7 +335,6 @@ Object { "amd64", ], "base": "core18", - "compression": "xz", "confinement": "strict", "description": "Test Application (test quite “ #378)", "grade": "stable", @@ -387,7 +383,6 @@ Object { "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", @@ -458,7 +453,6 @@ Object { "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", @@ -528,7 +522,6 @@ Object { "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", @@ -1262,7 +1255,6 @@ Object { "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 [ "foo", @@ -1323,7 +1315,6 @@ Object { "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 [ "browser-sandbox", @@ -1525,7 +1516,6 @@ Object { "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 [ "browser-sandbox", @@ -1726,7 +1716,6 @@ Object { "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", @@ -1800,7 +1789,6 @@ Object { "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", @@ -1880,3 +1868,72 @@ Object { ], } `; + +exports[`use template app 1`] = ` +Object { + "apps": Object { + "testapp": 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", + }, + "plugs": Array [ + "desktop", + "desktop-legacy", + "home", + "x11", + "wayland", + "unity7", + "browser-support", + "network", + "gsettings", + "audio-playback", + "pulseaudio", + "opengl", + ], + }, + }, + "architectures": Array [ + "amd64", + ], + "base": "core18", + "confinement": "strict", + "description": "Test Application (test quite “ #378)", + "grade": "stable", + "name": "testapp", + "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": "Test App ßW", + "title": "Test App ßW", + "version": "1.1.0", +} +`; + +exports[`use template app 2`] = ` +Object { + "linux": Array [], +} +`; diff --git a/test/src/helpers/packTester.ts b/test/src/helpers/packTester.ts index 2712f060948..9aa2a509eff 100644 --- a/test/src/helpers/packTester.ts +++ b/test/src/helpers/packTester.ts @@ -27,7 +27,7 @@ if (process.env.TRAVIS !== "true") { } export const linuxDirTarget = Platform.LINUX.createTarget(DIR_TARGET) -export const snapTarget = Platform.LINUX.createTarget("snap") +export const snapTarget = Platform.LINUX.createTarget("snap", Arch.x64) export interface AssertPackOptions { readonly projectDirCreated?: (projectDir: string, tmpDir: TmpDir) => Promise diff --git a/test/src/linux/snapTest.ts b/test/src/linux/snapTest.ts index 9c0a2ba26a8..de557b5c1cc 100644 --- a/test/src/linux/snapTest.ts +++ b/test/src/linux/snapTest.ts @@ -40,7 +40,7 @@ test.ifAll.ifDevOrLinuxCi( test.ifAll.ifDevOrLinuxCi("default stagePackages", async () => { for (const p of [["default"], ["default", "custom"], ["custom", "default"], ["foo1", "default", "foo2"]]) { await assertPack("test-app-one", { - targets: Platform.LINUX.createTarget("snap"), + targets: snapTarget, config: { extraMetadata: { name: "sep", @@ -82,7 +82,7 @@ test.ifAll.ifDevOrLinuxCi( test.ifAll.ifDevOrLinuxCi("buildPackages", async () => { await assertPack("test-app-one", { - targets: Platform.LINUX.createTarget("snap"), + targets: snapTarget, config: { extraMetadata: { name: "sep", @@ -122,7 +122,7 @@ test.ifDevOrLinuxCi("plugs option", async () => { }, ]) { await assertPack("test-app-one", { - targets: Platform.LINUX.createTarget("snap"), + targets: snapTarget, config: { snap: { plugs: p, @@ -154,7 +154,7 @@ test.ifDevOrLinuxCi("slots option", async () => { ], ]) { await assertPack("test-app-one", { - targets: Platform.LINUX.createTarget("snap"), + targets: snapTarget, config: { extraMetadata: { name: "sep", @@ -175,7 +175,7 @@ test.ifDevOrLinuxCi("slots option", async () => { test.ifDevOrLinuxCi( "custom env", app({ - targets: Platform.LINUX.createTarget("snap"), + targets: snapTarget, config: { extraMetadata: { name: "sep", @@ -197,7 +197,7 @@ test.ifDevOrLinuxCi( test.ifDevOrLinuxCi( "custom after, no desktop", app({ - targets: Platform.LINUX.createTarget("snap"), + targets: snapTarget, config: { extraMetadata: { name: "sep", @@ -217,7 +217,7 @@ test.ifDevOrLinuxCi( test.ifDevOrLinuxCi( "no desktop plugs", app({ - targets: Platform.LINUX.createTarget("snap"), + targets: snapTarget, config: { extraMetadata: { name: "sep", @@ -288,9 +288,35 @@ test.ifDevOrLinuxCi( }, effectiveOptionComputed: async ({ snap, args }) => { expect(snap).toMatchSnapshot() - expect(snap.compression).toEqual("xz") + expect(snap.compression).toBeUndefined() expect(args).toEqual(expect.arrayContaining(["--compression", "xz"])) return true }, }) ) + +test.ifDevOrLinuxCi( + "use template app", + app({ + targets: snapTarget, + config: { + snap: { + useTemplateApp: true, + compression: "xz", + }, + }, + effectiveOptionComputed: async ({ snap, args }) => { + expect(snap).toMatchSnapshot() + expect(snap.parts).toBeUndefined() + expect(snap.compression).toBeUndefined() + expect(snap.contact).toBeUndefined() + expect(snap.donation).toBeUndefined() + expect(snap.issues).toBeUndefined() + expect(snap.parts).toBeUndefined() + expect(snap["source-code"]).toBeUndefined() + expect(snap.website).toBeUndefined() + expect(args).toEqual(expect.arrayContaining(["--exclude", "chrome-sandbox", "--compression", "xz"])) + return true + }, + }) +)