Skip to content

Commit

Permalink
fix(mac): Mac archive tar.* doesn't run after extraction
Browse files Browse the repository at this point in the history
Closes #784
  • Loading branch information
develar committed Oct 6, 2016
1 parent 4898eb1 commit a185040
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/platformPackager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,8 @@ export abstract class PlatformPackager<DC extends PlatformSpecificBuildOptions>
}

protected async archiveApp(format: string, appOutDir: string, outFile: string): Promise<any> {
return archiveApp(this.devMetadata.build.compression, format, outFile, this.platform === Platform.MAC ? path.join(appOutDir, `${this.appInfo.productFilename}.app`) : appOutDir)
const isMac = this.platform === Platform.MAC
return archiveApp(this.devMetadata.build.compression, format, outFile, isMac ? path.join(appOutDir, `${this.appInfo.productFilename}.app`) : appOutDir, isMac)
}

generateName(ext: string | null, arch: Arch, deployment: boolean, classifier: string | null = null): string {
Expand Down
12 changes: 9 additions & 3 deletions src/targets/archive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ const extToCompressionDescriptor: { [key: string]: CompressionDescriptor; } = {
"tar.bz2": new CompressionDescriptor("--bzip2", "BZIP2", "-1"),
}

export async function archiveApp(compression: CompressionLevel | n, format: string, outFile: string, dirToArchive: string, withoutDir: boolean = false): Promise<string> {
// withoutDir - not applicable for tar.* formats
export async function archiveApp(compression: CompressionLevel | n, format: string, outFile: string, dirToArchive: string, isMacApp: boolean = false, withoutDir: boolean = false): Promise<string> {
const storeOnly = compression === "store"

if (format.startsWith("tar.")) {
Expand All @@ -32,8 +33,13 @@ export async function archiveApp(compression: CompressionLevel | n, format: stri
tarEnv[info.env] = storeOnly ? info.minLevel : info.maxLevel
}

await spawn(process.platform === "darwin" || process.platform === "freebsd" ? "gtar" : "tar", [info.flag, "--transform", `s,^\.,${path.basename(outFile, "." + format)},`, "-cf", outFile, "."], {
cwd: dirToArchive,
const args = [info.flag, "-cf", outFile]
if (!isMacApp) {
args.push("--transform", `s,^\.,${path.basename(outFile, "." + format)},`)
}
args.push(isMacApp ? path.basename(dirToArchive) : ".")
await spawn(process.platform === "darwin" || process.platform === "freebsd" ? "gtar" : "tar", args, {
cwd: isMacApp ? path.dirname(dirToArchive) : dirToArchive,
env: tarEnv
})
return outFile
Expand Down
23 changes: 21 additions & 2 deletions test/src/macPackagerTest.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import test from "./helpers/avaEx"
import { assertPack, platform, modifyPackageJson, signed, app, appThrows } from "./helpers/packTester"
import OsXPackager from "out/macPackager"
import { writeFile, remove, copy } from "fs-extra-p"
import { writeFile, remove, copy, mkdir } from "fs-extra-p"
import * as path from "path"
import { BuildInfo } from "out/platformPackager"
import { Promise as BluebirdPromise } from "bluebird"
Expand All @@ -13,6 +13,8 @@ import { Target } from "out/platformPackager"
import { DmgTarget } from "out/targets/dmg"
import { DIR_TARGET } from "out/targets/targetFactory"
import { attachAndExecute } from "out/targets/dmg"
import { getTempName } from "out/util/util"
import { exec } from "out/util/util"

//noinspection JSUnusedLocalSymbols
const __awaiter = require("out/util/awaiter")
Expand All @@ -31,10 +33,27 @@ function createTargetTest(target: Array<string>, expectedContents: Array<string>
}
}
}
}, {expectedContents: expectedContents, signed: target.includes("mas")})
}, {
expectedContents: expectedContents,
signed: target.includes("mas"),
packed: async (context) => {
if (!target.includes("tar.gz")) {
return
}

const tempDir = path.join(context.outDir, getTempName())
await mkdir(tempDir)
await exec("tar", ["xf", path.join(context.outDir, "mac", "Test App ßW-1.1.0-mac.tar.gz")], {cwd: tempDir})
await assertThat(path.join(tempDir, "Test App ßW.app")).isDirectory()
}
})
}

test("only zip", createTargetTest(["zip"], ["Test App ßW-1.1.0-mac.zip"]))

test("tar.gz", createTargetTest(["tar.gz"], ["Test App ßW-1.1.0-mac.tar.gz"]))
test("tar.xz", createTargetTest(["tar.xz"], ["Test App ßW-1.1.0-mac.tar.xz"]))

test.ifOsx("invalid target", t => t.throws(createTargetTest(["ttt"], [])(), "Unknown target: ttt"))

if (process.env.CSC_KEY_PASSWORD == null || process.platform !== "darwin") {
Expand Down

0 comments on commit a185040

Please sign in to comment.