From e329cb950dc2c352ca2dd8c942c7a00eefe9b126 Mon Sep 17 00:00:00 2001 From: Mike Jerred Date: Wed, 7 Sep 2022 20:54:07 +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 | 218 ++++++++++++++++++- test/src/helpers/packTester.ts | 2 +- test/src/linux/snapTest.ts | 43 +++- 4 files changed, 251 insertions(+), 24 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..166c1b4af90 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", @@ -310,13 +308,13 @@ exports[`compression option 1`] = ` Object { "apps": Object { "sep": Object { + "adapter": "none", "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", @@ -342,7 +340,144 @@ Object { "confinement": "strict", "description": "Test Application (test quite “ #378)", "grade": "stable", + "icon": "snap/gui/icon.png", "name": "sep", + "parts": Object { + "app": Object { + "plugin": "nil", + "stage": Array [ + "-usr/lib/python*", + "-usr/bin/python*", + "-var/lib/ucf", + "-usr/include", + "-usr/lib/X11", + "-usr/share", + "-usr/sbin", + "-usr/bin", + "-usr/lib/*/libicudata.*", + "-usr/lib/*/libicui18n.*", + "-usr/lib/*/libgtk-*", + "-usr/lib/*/libgdk-*", + "-usr/lib/*/glib-*", + "-usr/lib/*/gtk-*", + "-usr/lib/*/gdk-*", + "-usr/lib/*/krb5", + "-usr/lib/systemd", + "-usr/lib/glib-networking", + "-usr/lib/dconf", + "-usr/lib/*/avahi", + "-usr/lib/*/gio", + "-usr/lib/*/libatk*", + "-usr/lib/*/libatspi*", + "-usr/lib/*/libavahi*", + "-usr/lib/*/libcairo*", + "-usr/lib/*/libcolordprivate*", + "-usr/lib/*/libcolord*", + "-usr/lib/*/libcroco*", + "-usr/lib/*/libcups*", + "-usr/lib/*/libdatrie*", + "-usr/lib/*/libdconf*", + "-usr/lib/*/libepoxy*", + "-usr/lib/*/libexpatw*", + "-usr/lib/*/libffi*", + "-usr/lib/*/libfontconfig*", + "-usr/lib/*/libfreetype*", + "-usr/lib/*/libgdk_pixbuf*", + "-usr/lib/*/libgdk_pixbuf_xlib*", + "-usr/lib/*/libgio*", + "-usr/lib/*/libglib*", + "-usr/lib/*/libgmodule*", + "-usr/lib/*/libgmp*", + "-usr/lib/*/libgnutls*", + "-usr/lib/*/libgobject*", + "-usr/lib/*/libgraphite2*", + "-usr/lib/*/libgssapi_krb5*", + "-usr/lib/*/libgthread*", + "-usr/lib/*/libharfbuzz*", + "-usr/lib/*/libhogweed*", + "-usr/lib/*/libicuio*", + "-usr/lib/*/libicutest*", + "-usr/lib/*/libicutu*", + "-usr/lib/*/libicuuc*", + "-usr/lib/*/libidn2*", + "-usr/lib/*/libjbig*", + "-usr/lib/*/libjpeg*", + "-usr/lib/*/libjson*", + "-usr/lib/*/libk5crypto*", + "-usr/lib/*/libkrb5*", + "-usr/lib/*/libkrb5support*", + "-usr/lib/*/liblcms2*", + "-usr/lib/*/libnettle*", + "-usr/lib/*/libp11*", + "-usr/lib/*/libpango*", + "-usr/lib/*/libpangocairo*", + "-usr/lib/*/libpangoft2*", + "-usr/lib/*/libpixman*", + "-usr/lib/*/libpng16*", + "-usr/lib/*/libproxy*", + "-usr/lib/*/librest*", + "-usr/lib/*/librsvg*", + "-usr/lib/*/libsecret*", + "-usr/lib/*/libsoup*", + "-usr/lib/*/libsqlite3*", + "-usr/lib/*/libtasn1*", + "-usr/lib/*/libthai*", + "-usr/lib/*/libtiff*", + "-usr/lib/*/libunistring*", + "-usr/lib/*/libwayland*", + "-usr/lib/*/libX11*", + "-usr/lib/*/libXau*", + "-usr/lib/*/libxcb.so*", + "-usr/lib/*/libxcb-dri2*", + "-usr/lib/*/libxcb-dri3*", + "-usr/lib/*/libxcb-glx*", + "-usr/lib/*/libxcb-present*", + "-usr/lib/*/libxcb-render*", + "-usr/lib/*/libxcb-shm*", + "-usr/lib/*/libxcb-sync*", + "-usr/lib/*/libxcb-xfixes*", + "-usr/lib/*/libXcomposite*", + "-usr/lib/*/libXcursor*", + "-usr/lib/*/libXdamage*", + "-usr/lib/*/libXdmcp*", + "-usr/lib/*/libXext*", + "-usr/lib/*/libXfixes*", + "-usr/lib/*/libXinerama*", + "-usr/lib/*/libXi*", + "-usr/lib/*/libxkbcommon*", + "-usr/lib/*/libxml2*", + "-usr/lib/*/libXrandr*", + "-usr/lib/*/libXrender*", + ], + "stage-packages": Array [ + "libnspr4", + "libnss3", + "libxss1", + "libappindicator3-1", + "libsecret-1-0", + ], + }, + "app-files": Object { + "organize": Object { + "*": "app/", + }, + "plugin": "dump", + "source": "app", + "stage": Array [ + "-app/chrome-sandbox", + "-LICENSES.chromium.html", + ], + }, + "gnome-platform-empty-dirs": Object { + "override-build": "mkdir -p \\"$SNAPCRAFT_PART_INSTALL/data-dir/themes\\" mkdir -p \\"$SNAPCRAFT_PART_INSTALL/data-dir/icons\\" mkdir -p \\"$SNAPCRAFT_PART_INSTALL/data-dir/sounds\\" mkdir $SNAPCRAFT_PART_INSTALL/gnome-platform +", + "plugin": "nil", + }, + "launch-scripts": Object { + "plugin": "dump", + "source": "scripts", + }, + }, "plugs": Object { "gnome-3-28-1804": Object { "default-provider": "gnome-3-28-1804", @@ -387,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", @@ -458,7 +592,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 +661,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 +1394,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 +1454,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 +1655,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 +1855,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 +1928,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 +2007,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..6f284f78dee 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", @@ -283,14 +283,41 @@ test.ifDevOrLinuxCi( }, productName: "Sep", snap: { + useTemplateApp: false, compression: "xz", }, }, effectiveOptionComputed: async ({ snap, args }) => { expect(snap).toMatchSnapshot() - expect(snap.compression).toEqual("xz") + expect(snap.compression).toBe('xz') 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 + }, + }) +)