Skip to content

Commit

Permalink
fix: strip extra fields out before creating snap.yaml (#7104)
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeJerred committed Sep 6, 2022
1 parent dd29013 commit 67f0c9d
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 25 deletions.
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
81 changes: 69 additions & 12 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 @@ -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",
Expand All @@ -338,7 +335,6 @@ Object {
"amd64",
],
"base": "core18",
"compression": "xz",
"confinement": "strict",
"description": "Test Application (test quite “ #378)",
"grade": "stable",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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 [],
}
`;
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
42 changes: 34 additions & 8 deletions test/src/linux/snapTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -197,7 +197,7 @@ test.ifDevOrLinuxCi(
test.ifDevOrLinuxCi(
"custom after, no desktop",
app({
targets: Platform.LINUX.createTarget("snap"),
targets: snapTarget,
config: {
extraMetadata: {
name: "sep",
Expand All @@ -217,7 +217,7 @@ test.ifDevOrLinuxCi(
test.ifDevOrLinuxCi(
"no desktop plugs",
app({
targets: Platform.LINUX.createTarget("snap"),
targets: snapTarget,
config: {
extraMetadata: {
name: "sep",
Expand Down Expand Up @@ -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
},
})
)

0 comments on commit 67f0c9d

Please sign in to comment.