Skip to content

Commit 7166580

Browse files
committed
fix: windows codesign on Linux
1 parent ae3f1bb commit 7166580

File tree

5 files changed

+27
-27
lines changed

5 files changed

+27
-27
lines changed

src/platformPackager.ts

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,18 @@ export abstract class PlatformPackager<DC extends PlatformSpecificBuildOptions>
151151
abstract pack(outDir: string, arch: Arch, targets: Array<string>, postAsyncTasks: Array<Promise<any>>): Promise<any>
152152

153153
protected async doPack(options: ElectronPackagerOptions, outDir: string, appOutDir: string, arch: Arch, customBuildOptions: DC) {
154-
await this.packApp(options, appOutDir)
154+
await pack(options)
155155
await this.copyExtraFiles(appOutDir, arch, customBuildOptions)
156+
157+
const afterPack = this.devMetadata.build.afterPack
158+
if (afterPack != null) {
159+
await afterPack({
160+
appOutDir: appOutDir,
161+
options: options,
162+
})
163+
}
164+
165+
await this.sanityCheckPackage(appOutDir, <boolean>options.asar)
156166
}
157167

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

198-
protected async packApp(options: ElectronPackagerOptions, appOutDir: string): Promise<any> {
199-
await pack(options)
200-
201-
const afterPack = this.devMetadata.build.afterPack
202-
if (afterPack != null) {
203-
await afterPack({
204-
appOutDir: appOutDir,
205-
options: options,
206-
})
207-
}
208-
209-
await this.sanityCheckPackage(appOutDir, <boolean>options.asar)
210-
}
211-
212208
private getExtraResources(isResources: boolean, arch: Arch, customBuildOptions: DC): Promise<Array<string>> {
213209
const buildMetadata: any = this.devMetadata.build
214210
let extra: Array<string> | n = buildMetadata == null ? null : buildMetadata[isResources ? "extraResources" : "extraFiles"]

src/util.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,8 @@ export function debug7zArgs(command: "a" | "x"): Array<string> {
215215
}
216216

217217
let tmpDirCounter = 0
218+
const pidAsString = process.pid.toString(36)
218219

219220
export function getTempName(prefix?: string | n): string {
220-
return `${prefix == null ? "" : prefix + "-"}${process.pid}-${tmpDirCounter++}`
221+
return `${prefix == null ? "" : prefix + "-"}${pidAsString}-${tmpDirCounter++}-${Date.now().toString(36)}`
221222
}

src/winPackager.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,16 +76,17 @@ export class WinPackager extends PlatformPackager<WinBuildOptions> {
7676
return path.join(outDir, `win${getArchSuffix(arch)}-unpacked`)
7777
}
7878

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

82-
if (process.platform !== "linux" && this.options.cscLink != null && this.options.cscKeyPassword != null) {
83-
const filename = this.appName + ".exe"
82+
const cert = await this.certFilePromise
83+
if (cert != null) {
84+
const filename = `${this.appName}.exe`
8485
log(`Signing ${filename}`)
8586
await BluebirdPromise.promisify(sign)({
8687
path: path.join(appOutDir, filename),
87-
cert: (await this.certFilePromise)!,
88-
password: this.options.cscKeyPassword,
88+
cert: cert,
89+
password: this.options.cscKeyPassword!,
8990
name: this.appName,
9091
site: await this.computePackageUrl(),
9192
overwrite: true,

test/src/helpers/packTester.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { parse as parsePlist } from "plist"
55
import { CSC_LINK, CSC_KEY_PASSWORD, CSC_INSTALLER_LINK, CSC_INSTALLER_KEY_PASSWORD } from "./codeSignData"
66
import { expectedLinuxContents, expectedWinContents } from "./expectedContents"
77
import { Packager, PackagerOptions, Platform, getProductName, ArtifactCreated, Arch, DIR_TARGET } from "out"
8-
import { exec } from "out/util"
8+
import { exec, getTempName } from "out/util"
99
import { tmpdir } from "os"
1010
import DecompressZip = require("decompress-zip")
1111
import { getArchSuffix } from "out/platformPackager"
@@ -14,9 +14,6 @@ import pathSorter = require("path-sort")
1414
//noinspection JSUnusedLocalSymbols
1515
const __awaiter = require("out/awaiter")
1616

17-
const tmpDirPrefix = "electron-builder-test-" + process.pid + "-"
18-
let tmpDirCounter = 0
19-
2017
if (process.env.TRAVIS !== "true") {
2118
// we don't use CircleCI, so, we can safely set this env
2219
process.env.CIRCLE_BUILD_NUM = 42
@@ -42,7 +39,7 @@ export async function assertPack(fixtureName: string, packagerOptions: PackagerO
4239
const customTmpDir = process.env.TEST_APP_TMP_DIR
4340
if (useTempDir) {
4441
// non-osx test uses the same dir as osx test, but we cannot share node_modules (because tests executed in parallel)
45-
const dir = customTmpDir == null ? path.join(tmpdir(), `${tmpDirPrefix}${fixtureName}-${tmpDirCounter++}`) : path.resolve(customTmpDir)
42+
const dir = customTmpDir == null ? path.join(tmpdir(), `${getTempName("electron-builder-test")}-${fixtureName}}`) : path.resolve(customTmpDir)
4643
if (customTmpDir != null) {
4744
console.log("Custom temp dir used: %s", customTmpDir)
4845
}

test/src/winPackagerTest.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ test.ifNotCiOsx("win", () => assertPack("test-app-one", signed({
1818
})
1919
))
2020

21+
test.ifNotCiOsx("win 32", () => assertPack("test-app-one", signed({
22+
targets: Platform.WINDOWS.createTarget(null, Arch.ia32),
23+
})
24+
))
25+
2126
// very slow
2227
test.ifWinCi("delta", () => assertPack("test-app-one", {
2328
targets: Platform.WINDOWS.createTarget(null, Arch.ia32),

0 commit comments

Comments
 (0)