Skip to content

Commit

Permalink
test: do not copy test app, - just set custom out
Browse files Browse the repository at this point in the history
  • Loading branch information
develar committed Aug 16, 2016
1 parent 17c0a82 commit e108f5f
Show file tree
Hide file tree
Showing 32 changed files with 373 additions and 352 deletions.
1 change: 1 addition & 0 deletions .idea/dictionaries/develar.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion .idea/runConfigurations/BuildTest.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions .idea/runConfigurations/CodeSignTest.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions .idea/runConfigurations/linuxPackagerTest.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 0 additions & 8 deletions .idea/runConfigurations/osxPackagerTest.xml

This file was deleted.

1 change: 1 addition & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ Only IntelliJ Platform IDEs (IntelliJ IDEA, WebStorm) support debug. [Forked ver

Use one of the shared run configurations as a template and:

* Ensure that `Before launch` contains `Compile TypeScript`.
* Set `Node interpreter` to NodeJS 7. Yes — NodeJS 7 is required to debug. Download [nightly build](https://nodejs.org/download/nightly/).
* Set `Node parameters` to `--inspect`.
* Set `Application Parameters` to `--match="test name" relative-test-file-name` if you want to debug particular test. E.g.
Expand Down
50 changes: 11 additions & 39 deletions src/codeSign.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { exec, getTempName, isEmptyOrSpaces } from "./util/util"
import { deleteFile, outputFile, copy, rename } from "fs-extra-p"
import { download } from "./util/httpRequest"
import { tmpdir } from "os"
import * as path from "path"
import { executeFinally, all } from "./util/promise"
import { Promise as BluebirdPromise } from "bluebird"
import { randomBytes } from "crypto"
import { homedir } from "os"
import { TmpDir } from "./util/tmp"

//noinspection JSUnusedLocalSymbols
const __awaiter = require("./util/awaiter")
Expand All @@ -19,23 +19,13 @@ export interface CodeSigningInfo {
keychainName?: string | null
}

export function generateKeychainName(): string {
return path.join(tmpdir(), getTempName("csc") + ".keychain")
}

export function downloadCertificate(urlOrBase64: string): BluebirdPromise<string> {
const tempFile = path.join(tmpdir(), `${getTempName()}.p12`)
if (urlOrBase64.startsWith("https://")) {
return download(urlOrBase64, tempFile)
.thenReturn(tempFile)
}
else if (urlOrBase64.startsWith("file://")) {
export function downloadCertificate(urlOrBase64: string, tmpDir: TmpDir): BluebirdPromise<string> {
if (urlOrBase64.startsWith("file://")) {
return BluebirdPromise.resolve(urlOrBase64.substring("file://".length))
}
else {
return outputFile(tempFile, new Buffer(urlOrBase64, "base64"))
.thenReturn(tempFile)
}

return tmpDir.getTempFile(".p12")
.then(tempFile => (urlOrBase64.startsWith("https://") ? download(urlOrBase64, tempFile) : outputFile(tempFile, new Buffer(urlOrBase64, "base64"))).thenReturn(tempFile))
}

let bundledCertKeychainAdded: Promise<any> | null = null
Expand Down Expand Up @@ -66,12 +56,14 @@ async function createCustomCertKeychain() {
}
}

export async function createKeychain(keychainName: string, cscLink: string, cscKeyPassword: string, cscILink?: string | null, cscIKeyPassword?: string | null): Promise<CodeSigningInfo> {
export async function createKeychain(tmpDir: TmpDir, cscLink: string, cscKeyPassword: string, cscILink?: string | null, cscIKeyPassword?: string | null): Promise<CodeSigningInfo> {
if (bundledCertKeychainAdded == null) {
bundledCertKeychainAdded = createCustomCertKeychain()
}
await bundledCertKeychainAdded

const keychainName = await tmpDir.getTempFile(".keychain")

const certLinks = [cscLink]
if (cscILink != null) {
certLinks.push(cscILink)
Expand All @@ -80,21 +72,15 @@ export async function createKeychain(keychainName: string, cscLink: string, cscK
const certPaths = new Array(certLinks.length)
const keychainPassword = randomBytes(8).toString("hex")
return await executeFinally(BluebirdPromise.all([
BluebirdPromise.map(certLinks, (link, i) => downloadCertificate(link).then(it => certPaths[i] = it)),
BluebirdPromise.map(certLinks, (link, i) => downloadCertificate(link, tmpDir).then(it => certPaths[i] = it)),
BluebirdPromise.mapSeries([
["create-keychain", "-p", keychainPassword, keychainName],
["unlock-keychain", "-p", keychainPassword, keychainName],
["set-keychain-settings", "-t", "3600", "-u", keychainName]
], it => exec("security", it))
])
.then<CodeSigningInfo>(() => importCerts(keychainName, certPaths, <Array<string>>[cscKeyPassword, cscIKeyPassword].filter(it => it != null))),
errorOccurred => {
const tasks = certPaths.map((it, index) => certLinks[index].startsWith("https://") ? deleteFile(it, true) : BluebirdPromise.resolve())
if (errorOccurred) {
tasks.push(deleteKeychain(keychainName))
}
return all(tasks)
})
() => all(certPaths.map((it, index) => certLinks[index].startsWith("https://") ? deleteFile(it, true) : BluebirdPromise.resolve())))
}

async function importCerts(keychainName: string, paths: Array<string>, keyPasswords: Array<string>): Promise<CodeSigningInfo> {
Expand All @@ -115,20 +101,6 @@ export function sign(path: string, name: string, keychain: string): BluebirdProm
return exec("codesign", args)
}

export function deleteKeychain(keychainName: string, ignoreNotFound: boolean = true): BluebirdPromise<any> {
const result = exec("security", ["delete-keychain", keychainName])
if (ignoreNotFound) {
return result.catch(error => {
if (!error.message.includes("The specified keychain could not be found.")) {
throw error
}
})
}
else {
return result
}
}

export let findIdentityRawResult: Promise<Array<string>> | null = null

async function getValidIdentities(keychain?: string | null): Promise<Array<string>> {
Expand Down
2 changes: 1 addition & 1 deletion src/linuxPackager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export class LinuxPackager extends PlatformPackager<LinuxBuildOptions> {
let helper: LinuxTargetHelper | null
const getHelper = () => {
if (helper == null) {
helper = new LinuxTargetHelper(this, cleanupTasks)
helper = new LinuxTargetHelper(this)
}
return helper
}
Expand Down
8 changes: 3 additions & 5 deletions src/macPackager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Platform, MasBuildOptions, Arch, MacOptions } from "./metadata"
import * as path from "path"
import { Promise as BluebirdPromise } from "bluebird"
import { log, warn, task } from "./util/log"
import { createKeychain, deleteKeychain, CodeSigningInfo, generateKeychainName, findIdentity } from "./codeSign"
import { createKeychain, CodeSigningInfo, findIdentity } from "./codeSign"
import { deepAssign } from "./util/deepAssign"
import { signAsync, flatAsync, BaseSignOptions, SignOptions, FlatOptions } from "electron-osx-sign"
import { DmgTarget } from "./targets/dmg"
Expand All @@ -16,16 +16,14 @@ const __awaiter = require("./util/awaiter")
export default class MacPackager extends PlatformPackager<MacOptions> {
codeSigningInfo: Promise<CodeSigningInfo>

constructor(info: BuildInfo, cleanupTasks: Array<() => Promise<any>>) {
constructor(info: BuildInfo) {
super(info)

if (this.options.cscLink == null) {
this.codeSigningInfo = BluebirdPromise.resolve({})
}
else {
const keychainName = generateKeychainName()
cleanupTasks.push(() => deleteKeychain(keychainName))
this.codeSigningInfo = createKeychain(keychainName, this.options.cscLink, this.getCscPassword(), this.options.cscInstallerLink, this.options.cscInstallerKeyPassword)
this.codeSigningInfo = createKeychain(info.tempDirManager, this.options.cscLink!, this.getCscPassword(), this.options.cscInstallerLink, this.options.cscInstallerKeyPassword)
}
}

Expand Down
9 changes: 6 additions & 3 deletions src/packager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { AppInfo } from "./appInfo"
import MacPackager from "./macPackager"
import { createTargets } from "./targets/targetFactory"
import { readPackageJson } from "./util/readPackageJson"
import { TmpDir } from "./util/tmp"

//noinspection JSUnusedLocalSymbols
const __awaiter = require("./util/awaiter")
Expand All @@ -41,6 +42,8 @@ export class Packager implements BuildInfo {

appInfo: AppInfo

readonly tempDirManager = new TmpDir()

//noinspection JSUnusedGlobalSymbols
constructor(public options: PackagerOptions) {
this.projectDir = options.projectDir == null ? process.cwd() : path.resolve(options.projectDir)
Expand Down Expand Up @@ -91,7 +94,7 @@ export class Packager implements BuildInfo {

this.appInfo = new AppInfo(this.metadata, this.devMetadata)
const cleanupTasks: Array<() => Promise<any>> = []
return executeFinally(this.doBuild(cleanupTasks), () => all(cleanupTasks.map(it => it())))
return executeFinally(this.doBuild(cleanupTasks), () => all(cleanupTasks.map(it => it()).concat(this.tempDirManager.cleanup())))
}

private async doBuild(cleanupTasks: Array<() => Promise<any>>): Promise<Map<Platform, Map<String, Target>>> {
Expand Down Expand Up @@ -144,13 +147,13 @@ export class Packager implements BuildInfo {
case Platform.MAC:
{
const helperClass: typeof MacPackager = require("./macPackager").default
return new helperClass(this, cleanupTasks)
return new helperClass(this)
}

case Platform.WINDOWS:
{
const helperClass: typeof WinPackager = require("./winPackager").WinPackager
return new helperClass(this, cleanupTasks)
return new helperClass(this)
}

case Platform.LINUX:
Expand Down
19 changes: 9 additions & 10 deletions src/platformPackager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { AppMetadata, DevMetadata, Platform, PlatformSpecificBuildOptions, Arch
import EventEmitter = NodeJS.EventEmitter
import { Promise as BluebirdPromise } from "bluebird"
import * as path from "path"
import { readdir, remove, realpath } from "fs-extra-p"
import { readdir, remove } from "fs-extra-p"
import { statOrNull, use, unlinkIfExists, isEmptyOrSpaces } from "./util/util"
import { Packager } from "./packager"
import { AsarOptions } from "asar-electron-builder"
Expand All @@ -13,6 +13,7 @@ import { warn, log, task } from "./util/log"
import { AppInfo } from "./appInfo"
import { createFilter, copyFiltered, hasMagic, devDependencies } from "./util/filter"
import { ElectronPackagerOptions, pack } from "./packager/dirPackager"
import { TmpDir } from "./util/tmp"

//noinspection JSUnusedLocalSymbols
const __awaiter = require("./util/awaiter")
Expand Down Expand Up @@ -65,6 +66,8 @@ export interface BuildInfo {

// computed final effective appId
appInfo: AppInfo

readonly tempDirManager: TmpDir
}

export class Target {
Expand Down Expand Up @@ -165,18 +168,10 @@ export abstract class PlatformPackager<DC extends PlatformSpecificBuildOptions>
const extraFilePatterns = this.getExtraFilePatterns(false, arch, platformSpecificBuildOptions)

const p = pack(options, appOutDir, platformName, Arch[arch], this.info.electronVersion, async() => {
const ignoreFiles = new Set([path.relative(this.info.appDir, outDir), path.relative(this.info.appDir, this.buildResourcesDir)])
const ignoreFiles = new Set([path.resolve(this.info.appDir, outDir), path.resolve(this.info.appDir, this.buildResourcesDir)])
if (!this.info.isTwoPackageJsonProjectLayoutUsed) {
const result = await devDependencies(this.info.appDir)
// npm returns real path, so, we should use relative path to avoid any mismatch
const realAppDirPath = await realpath(this.info.appDir)
for (let it of result) {
if (it.startsWith(realAppDirPath)) {
it = it.substring(realAppDirPath.length + 1)
}
else if (it.startsWith(this.info.appDir)) {
it = it.substring(this.info.appDir.length + 1)
}
ignoreFiles.add(it)
}
}
Expand Down Expand Up @@ -418,6 +413,10 @@ export abstract class PlatformPackager<DC extends PlatformSpecificBuildOptions>
return null
}
}

async getTempFile(suffix: string): Promise<string> {
return this.info.tempDirManager.getTempFile(suffix)
}
}

export function getArchSuffix(arch: Arch): string {
Expand Down
16 changes: 5 additions & 11 deletions src/targets/LinuxTargetHelper.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { remove, emptyDir, readdir, outputFile } from "fs-extra-p"
import { readdir, outputFile, ensureDir } from "fs-extra-p"
import * as path from "path"
import { tmpdir } from "os"
import { getTempName, exec, debug } from "../util/util"
import { exec, debug } from "../util/util"
import { PlatformPackager } from "../platformPackager"
import { Promise as BluebirdPromise } from "bluebird"
import { LinuxBuildOptions } from "../metadata"
Expand All @@ -13,15 +12,10 @@ export const installPrefix = "/opt"

export class LinuxTargetHelper {
readonly icons: Promise<Array<Array<string>>>
readonly tempDirPromise: Promise<string>

maxIconPath: string | null = null

constructor(private packager: PlatformPackager<LinuxBuildOptions>, cleanupTasks: Array<() => Promise<any>>) {
const tempDir = path.join(tmpdir(), getTempName("electron-builder-linux"))
this.tempDirPromise = emptyDir(tempDir).thenReturn(tempDir)
cleanupTasks.push(() => remove(tempDir))

constructor(private packager: PlatformPackager<LinuxBuildOptions>) {
this.icons = this.computeDesktopIcons()
}

Expand All @@ -32,7 +26,7 @@ export class LinuxTargetHelper {
return this.iconsFromDir(path.join(this.packager.buildResourcesDir, "icons"))
}
else {
return this.createFromIcns(await this.tempDirPromise)
return this.createFromIcns(await this.packager.getTempFile("electron-builder-linux").then(it => ensureDir(it).thenReturn(it)))
}
}

Expand Down Expand Up @@ -81,7 +75,7 @@ export class LinuxTargetHelper {
}

const productFilename = appInfo.productFilename
const tempFile = path.join(await this.tempDirPromise, `${productFilename}.desktop`)
const tempFile = await this.packager.getTempFile(`${productFilename}.desktop`)
await outputFile(tempFile, this.packager.platformSpecificBuildOptions.desktop || `[Desktop Entry]
Name=${appInfo.productName}
Comment=${this.packager.platformSpecificBuildOptions.description || appInfo.description}
Expand Down
Loading

0 comments on commit e108f5f

Please sign in to comment.