Skip to content

Commit

Permalink
fix: strip extra fields out that are not allowed when creating snap.y…
Browse files Browse the repository at this point in the history
…aml (#7104) (#7110)
  • Loading branch information
MikeJerred authored Sep 8, 2022
1 parent 323618f commit 0a7025e
Show file tree
Hide file tree
Showing 5 changed files with 256 additions and 24 deletions.
5 changes: 5 additions & 0 deletions .changeset/small-dodos-worry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"app-builder-lib": patch
---

fix: strip extra fields out that are not allowed when creating snap.yaml (#7104)
12 changes: 8 additions & 4 deletions packages/app-builder-lib/src/targets/snap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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
}
Expand Down
218 changes: 207 additions & 11 deletions test/snapshots/linux/snapTest.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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 [],
}
`;
2 changes: 1 addition & 1 deletion test/src/helpers/packTester.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<any>
Expand Down
Loading

0 comments on commit 0a7025e

Please sign in to comment.