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 a1b7c5f
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 12 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
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
40 changes: 33 additions & 7 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 @@ -294,3 +294,29 @@ test.ifDevOrLinuxCi(
},
})
)

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 a1b7c5f

Please sign in to comment.