Skip to content

Commit

Permalink
fix: windows codesign on Linux
Browse files Browse the repository at this point in the history
  • Loading branch information
develar committed May 31, 2016
1 parent ae3f1bb commit 7166580
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 27 deletions.
26 changes: 11 additions & 15 deletions src/platformPackager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,18 @@ export abstract class PlatformPackager<DC extends PlatformSpecificBuildOptions>
abstract pack(outDir: string, arch: Arch, targets: Array<string>, postAsyncTasks: Array<Promise<any>>): Promise<any>

protected async doPack(options: ElectronPackagerOptions, outDir: string, appOutDir: string, arch: Arch, customBuildOptions: DC) {
await this.packApp(options, appOutDir)
await pack(options)
await this.copyExtraFiles(appOutDir, arch, customBuildOptions)

const afterPack = this.devMetadata.build.afterPack
if (afterPack != null) {
await afterPack({
appOutDir: appOutDir,
options: options,
})
}

await this.sanityCheckPackage(appOutDir, <boolean>options.asar)
}

protected computePackOptions(outDir: string, appOutDir: string, arch: Arch): ElectronPackagerOptions {
Expand Down Expand Up @@ -195,20 +205,6 @@ export abstract class PlatformPackager<DC extends PlatformSpecificBuildOptions>
return options
}

protected async packApp(options: ElectronPackagerOptions, appOutDir: string): Promise<any> {
await pack(options)

const afterPack = this.devMetadata.build.afterPack
if (afterPack != null) {
await afterPack({
appOutDir: appOutDir,
options: options,
})
}

await this.sanityCheckPackage(appOutDir, <boolean>options.asar)
}

private getExtraResources(isResources: boolean, arch: Arch, customBuildOptions: DC): Promise<Array<string>> {
const buildMetadata: any = this.devMetadata.build
let extra: Array<string> | n = buildMetadata == null ? null : buildMetadata[isResources ? "extraResources" : "extraFiles"]
Expand Down
3 changes: 2 additions & 1 deletion src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,8 @@ export function debug7zArgs(command: "a" | "x"): Array<string> {
}

let tmpDirCounter = 0
const pidAsString = process.pid.toString(36)

export function getTempName(prefix?: string | n): string {
return `${prefix == null ? "" : prefix + "-"}${process.pid}-${tmpDirCounter++}`
return `${prefix == null ? "" : prefix + "-"}${pidAsString}-${tmpDirCounter++}-${Date.now().toString(36)}`
}
13 changes: 7 additions & 6 deletions src/winPackager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,17 @@ export class WinPackager extends PlatformPackager<WinBuildOptions> {
return path.join(outDir, `win${getArchSuffix(arch)}-unpacked`)
}

protected async packApp(options: any, appOutDir: string) {
await super.packApp(options, appOutDir)
protected async doPack(options: ElectronPackagerOptions, outDir: string, appOutDir: string, arch: Arch, customBuildOptions: WinBuildOptions) {
await super.doPack(options, outDir, appOutDir, arch, customBuildOptions)

if (process.platform !== "linux" && this.options.cscLink != null && this.options.cscKeyPassword != null) {
const filename = this.appName + ".exe"
const cert = await this.certFilePromise
if (cert != null) {
const filename = `${this.appName}.exe`
log(`Signing ${filename}`)
await BluebirdPromise.promisify(sign)({
path: path.join(appOutDir, filename),
cert: (await this.certFilePromise)!,
password: this.options.cscKeyPassword,
cert: cert,
password: this.options.cscKeyPassword!,
name: this.appName,
site: await this.computePackageUrl(),
overwrite: true,
Expand Down
7 changes: 2 additions & 5 deletions test/src/helpers/packTester.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { parse as parsePlist } from "plist"
import { CSC_LINK, CSC_KEY_PASSWORD, CSC_INSTALLER_LINK, CSC_INSTALLER_KEY_PASSWORD } from "./codeSignData"
import { expectedLinuxContents, expectedWinContents } from "./expectedContents"
import { Packager, PackagerOptions, Platform, getProductName, ArtifactCreated, Arch, DIR_TARGET } from "out"
import { exec } from "out/util"
import { exec, getTempName } from "out/util"
import { tmpdir } from "os"
import DecompressZip = require("decompress-zip")
import { getArchSuffix } from "out/platformPackager"
Expand All @@ -14,9 +14,6 @@ import pathSorter = require("path-sort")
//noinspection JSUnusedLocalSymbols
const __awaiter = require("out/awaiter")

const tmpDirPrefix = "electron-builder-test-" + process.pid + "-"
let tmpDirCounter = 0

if (process.env.TRAVIS !== "true") {
// we don't use CircleCI, so, we can safely set this env
process.env.CIRCLE_BUILD_NUM = 42
Expand All @@ -42,7 +39,7 @@ export async function assertPack(fixtureName: string, packagerOptions: PackagerO
const customTmpDir = process.env.TEST_APP_TMP_DIR
if (useTempDir) {
// non-osx test uses the same dir as osx test, but we cannot share node_modules (because tests executed in parallel)
const dir = customTmpDir == null ? path.join(tmpdir(), `${tmpDirPrefix}${fixtureName}-${tmpDirCounter++}`) : path.resolve(customTmpDir)
const dir = customTmpDir == null ? path.join(tmpdir(), `${getTempName("electron-builder-test")}-${fixtureName}}`) : path.resolve(customTmpDir)
if (customTmpDir != null) {
console.log("Custom temp dir used: %s", customTmpDir)
}
Expand Down
5 changes: 5 additions & 0 deletions test/src/winPackagerTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ test.ifNotCiOsx("win", () => assertPack("test-app-one", signed({
})
))

test.ifNotCiOsx("win 32", () => assertPack("test-app-one", signed({
targets: Platform.WINDOWS.createTarget(null, Arch.ia32),
})
))

// very slow
test.ifWinCi("delta", () => assertPack("test-app-one", {
targets: Platform.WINDOWS.createTarget(null, Arch.ia32),
Expand Down

0 comments on commit 7166580

Please sign in to comment.