Skip to content

Commit

Permalink
refactor: move wine to electron-builder-util
Browse files Browse the repository at this point in the history
  • Loading branch information
develar committed Jul 26, 2017
1 parent 82c8905 commit e1dfeb7
Show file tree
Hide file tree
Showing 17 changed files with 34 additions and 41 deletions.
2 changes: 2 additions & 0 deletions .idea/dictionaries/develar.xml

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

1 change: 1 addition & 0 deletions .idea/electron-builder.iml

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

Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import BluebirdPromise from "bluebird-lst"
import { Arch } from "electron-builder"
import { debug, exec, log, spawn } from "electron-builder-util"
import { debug, exec, execWine, log, prepareWindowsExecutableArgs as prepareArgs, spawn } from "electron-builder-util"
import { copyFile, walk } from "electron-builder-util/out/fs"
import { execWine, prepareArgs } from "electron-builder/out/util/wine"
import { WinPackager } from "electron-builder/out/winPackager"
import { createWriteStream, ensureDir, remove, stat, unlink } from "fs-extra-p"
import * as path from "path"
Expand Down
3 changes: 2 additions & 1 deletion packages/electron-builder-util/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"source-map-support": "^0.4.15",
"7zip-bin": "^2.1.0",
"ini": "^1.3.4",
"tunnel-agent": "^0.6.0"
"tunnel-agent": "^0.6.0",
"semver": "^5.4.1"
},
"typings": "./out/electron-builder-util.d.ts"
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
import { getBinFromGithub } from "electron-builder-util/out/binDownload"
import { getBinFromGithub } from "./binDownload"

// 2 minutes
export const EXEC_TIMEOUT = {timeout: 120 * 1000}

/** @internal */
export interface ToolInfo {
path: string
env?: any
}

/** @internal */
export function computeEnv(oldValue: string | null | undefined, newValues: Array<string>): string {
const parsedOldValue = oldValue ? oldValue.split(":") : []
return newValues.concat(parsedOldValue).filter(it => it.length > 0).join(":")
}

/** @internal */
export function computeToolEnv(libPath: Array<string>): any {
// noinspection SpellCheckingInspection
return {
Expand All @@ -24,7 +21,6 @@ export function computeToolEnv(libPath: Array<string>): any {
}
}

/** @private */
export function getLinuxToolsPath() {
//noinspection SpellCheckingInspection
return getBinFromGithub("linux-tools", "mac-10.12", "DowDogHsS6X4a5au4r8T8qYprf7hqjfzcU7DL5oiD43jhZMfkQOjmFFYC1s7Lp9ARXp+sm8OJhuwaqCHMVGZYg==")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { debug, Lazy } from "electron-builder-util"
import { readFile } from "fs-extra-p"
import * as semver from "semver"
import { debug, Lazy } from "./util"

const macOsVersion = new Lazy<string>(async () => {
const file = await readFile("/System/Library/CoreServices/SystemVersion.plist", "utf8")
Expand All @@ -20,7 +20,6 @@ async function isOsVersionGreaterThanOrEqualTo(input: string) {
return semver.gte(await macOsVersion.value, clean(input))
}

/** @internal */
export async function isMacOsSierra() {
return process.platform === "darwin" && await isOsVersionGreaterThanOrEqualTo("10.12.0")
}
9 changes: 9 additions & 0 deletions packages/electron-builder-util/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import "source-map-support/register"
export { TmpDir } from "./tmp"
export { log, warn, task, subTask } from "./log"
export { Lazy } from "electron-builder-http"
export { isMacOsSierra } from "./macosVersion"
export { execWine, prepareWindowsExecutableArgs } from "./wine"

export const debug = _debug("electron-builder")
export const debug7z = _debug("electron-builder:7z")
Expand Down Expand Up @@ -277,4 +279,11 @@ export function safeStringifyJson(data: any, skippedNames?: Set<string>) {
}
return value
}, 2)
}

export function isEnvTrue(value: string | null | undefined) {
if (value != null) {
value = value.trim()
}
return value === "true" || value === "" || value === "1"
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { debug, exec, ExecOptions, Lazy } from "electron-builder-util"
import { getBinFromGithub } from "electron-builder-util/out/binDownload"
import * as path from "path"
import { lt as isVersionLessThan } from "semver"
import { getBinFromGithub } from "./binDownload"
import { computeEnv, EXEC_TIMEOUT, ToolInfo } from "./bundledTool"
import { isUseSystemWine } from "./flags"
import { isMacOsSierra } from "./macosVersion"
import { debug, exec, ExecOptions, isEnvTrue, Lazy } from "./util"

const wineExecutable = new Lazy<ToolInfo>(async () => {
debug(`USE_SYSTEM_WINE: ${process.env.USE_SYSTEM_WINE}`)
if (!isUseSystemWine() && await isMacOsSierra()) {
if (!isEnvTrue(process.env.USE_SYSTEM_WINE) && await isMacOsSierra()) {
// noinspection SpellCheckingInspection
const wineDir = await getBinFromGithub("wine", "2.0.1-mac-10.12", "IvKwDml/Ob0vKfYVxcu92wxUzHu8lTQSjjb8OlCTQ6bdNpVkqw17OM14TPpzGMIgSxfVIrQZhZdCwpkxLyG3mg==")
return {
Expand Down Expand Up @@ -38,7 +37,7 @@ export function execWine(file: string, args: Array<string>, options: ExecOptions
}

/** @private */
export function prepareArgs(args: Array<string>, exePath: string) {
export function prepareWindowsExecutableArgs(args: Array<string>, exePath: string) {
if (process.platform !== "win32") {
args.unshift(exePath)
}
Expand Down
1 change: 1 addition & 0 deletions packages/electron-builder-util/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
],
"files": [
"../../typings/is-ci.d.ts",
"../../typings/semver.d.ts",
"../../typings/stat-mode.d.ts",
"../../typings/chalk.d.ts",
"../../typings/debug.d.ts",
Expand Down
5 changes: 2 additions & 3 deletions packages/electron-builder/src/targets/archive.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { path7za } from "7zip-bin"
import { debug7z, debug7zArgs, spawn } from "electron-builder-util"
import { debug7z, debug7zArgs, isMacOsSierra, spawn } from "electron-builder-util"
import { computeEnv, getLinuxToolsPath } from "electron-builder-util/out/bundledTool"
import { exists } from "electron-builder-util/out/fs"
import { unlink } from "fs-extra-p"
import * as path from "path"
import { CompressionLevel } from "../core"
import { computeEnv, getLinuxToolsPath } from "../util/bundledTool"
import { isMacOsSierra } from "../util/macosVersion"

class CompressionDescriptor {
constructor(public flag: string, public env: string, public minLevel: string, public maxLevel: string = "-9") {
Expand Down
5 changes: 2 additions & 3 deletions packages/electron-builder/src/targets/fpm.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import BluebirdPromise from "bluebird-lst"
import { debug, exec, log, smarten, TmpDir, use, warn } from "electron-builder-util"
import { debug, exec, isMacOsSierra, log, smarten, TmpDir, use, warn } from "electron-builder-util"
import { getBin } from "electron-builder-util/out/binDownload"
import { computeEnv, getLinuxToolsPath } from "electron-builder-util/out/bundledTool"
import { unlinkIfExists } from "electron-builder-util/out/fs"
import { ensureDir, outputFile, readFile } from "fs-extra-p"
import * as path from "path"
import { Arch, Target, toLinuxArchString } from "../core"
import * as errorMessages from "../errorMessages"
import { LinuxPackager } from "../linuxPackager"
import { DebOptions, LinuxTargetSpecificOptions } from "../options/linuxOptions"
import { computeEnv, getLinuxToolsPath } from "../util/bundledTool"
import { isMacOsSierra } from "../util/macosVersion"
import { installPrefix, LinuxTargetHelper } from "./LinuxTargetHelper"

const fpmPath = (process.platform === "win32" || process.env.USE_SYSTEM_FPM === "true") ?
Expand Down
5 changes: 2 additions & 3 deletions packages/electron-builder/src/targets/nsis.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { path7za } from "7zip-bin"
import BluebirdPromise from "bluebird-lst"
import _debug from "debug"
import { asArray, debug7zArgs, doSpawn, getPlatformIconFileName, handleProcess, isEmptyOrSpaces, log, spawn, use, warn } from "electron-builder-util"
import { asArray, debug7zArgs, doSpawn, execWine, getPlatformIconFileName, handleProcess, isEmptyOrSpaces, log, spawn, use, warn } from "electron-builder-util"
import { getBinFromGithub } from "electron-builder-util/out/binDownload"
import { copyFile } from "electron-builder-util/out/fs"
import { readFile, writeFile } from "fs-extra-p"
Expand All @@ -13,7 +13,6 @@ import { NsisOptions, PortableOptions } from "../options/winOptions"
import { normalizeExt } from "../platformPackager"
import { AsyncTaskManager } from "../util/asyncTaskManager"
import { time } from "../util/timer"
import { execWine } from "../util/wine"
import { WinPackager } from "../winPackager"
import { addZipArgs, archive, ArchiveOptions } from "./archive"
import { computeBlockMap } from "./blockMap"
Expand Down Expand Up @@ -43,7 +42,7 @@ export class NsisTarget extends Target {

this.packageHelper.refCount++

this.options = targetName === "portable" ? Object.create(null) : Object.assign(Object.create(null), this.packager.config.nsis)
this.options = targetName === "portable" ? Object.create(null) : {...this.packager.config.nsis}
if (targetName !== "nsis") {
Object.assign(this.options, (this.packager.config as any)[targetName === "nsis-web" ? "nsisWeb" : targetName])
}
Expand Down
11 changes: 1 addition & 10 deletions packages/electron-builder/src/util/flags.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
export function isUseSystemWine() {
return isEnvTrue(process.env.USE_SYSTEM_WINE)
}
import { isEnvTrue } from "electron-builder-util"

export function isUseSystemSigncode() {
return isEnvTrue(process.env.USE_SYSTEM_SIGNCODE)
Expand All @@ -12,11 +10,4 @@ export function isBuildCacheEnabled() {

export function isAutoDiscoveryCodeSignIdentity() {
return process.env.CSC_IDENTITY_AUTO_DISCOVERY !== "false"
}

function isEnvTrue(value: string | null | undefined) {
if (value != null) {
value = value.trim()
}
return value === "true" || value === "" || value === "1"
}
3 changes: 1 addition & 2 deletions packages/electron-builder/src/winPackager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import BluebirdPromise from "bluebird-lst"
import { createHash } from "crypto"
import _debug from "debug"
import { parseDn } from "electron-builder-http/out/rfc2253Parser"
import { asArray, exec, Lazy, log, use, warn } from "electron-builder-util"
import { asArray, exec, execWine, Lazy, log, use, warn } from "electron-builder-util"
import { close, open, read, rename } from "fs-extra-p"
import isCI from "is-ci"
import * as path from "path"
Expand All @@ -20,7 +20,6 @@ import { createCommonTarget } from "./targets/targetFactory"
import { BuildCacheManager, digest } from "./util/cacheManager"
import { isBuildCacheEnabled } from "./util/flags"
import { time } from "./util/timer"
import { execWine } from "./util/wine"
import { FileCodeSigningInfo, getSignVendorPath, sign, SignOptions } from "./windowsCodeSign"

export class WinPackager extends PlatformPackager<WinBuildOptions> {
Expand Down
5 changes: 2 additions & 3 deletions packages/electron-builder/src/windowsCodeSign.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { exec, warn } from "electron-builder-util"
import { exec, isMacOsSierra, warn } from "electron-builder-util"
import { getBinFromGithub } from "electron-builder-util/out/binDownload"
import { computeToolEnv, ToolInfo } from "electron-builder-util/out/bundledTool"
import { rename } from "fs-extra-p"
import isCi from "is-ci"
import * as os from "os"
import * as path from "path"
import { WinBuildOptions } from "./options/winOptions"
import { computeToolEnv, ToolInfo } from "./util/bundledTool"
import { isUseSystemSigncode } from "./util/flags"
import { isMacOsSierra } from "./util/macosVersion"

/** @internal */
export function getSignVendorPath() {
Expand Down
2 changes: 1 addition & 1 deletion test/src/BuildTest.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import BluebirdPromise from "bluebird-lst"
import { Arch, createTargets, DIR_TARGET, Platform } from "electron-builder"
import { walk } from "electron-builder-util/out/fs"
import { checkWineVersion } from "electron-builder-util/out/wine"
import { readAsarJson } from "electron-builder/out/asar"
import { checkWineVersion } from "electron-builder/out/util/wine"
import { move, outputJson, readJson } from "fs-extra-p"
import * as path from "path"
import { app, appTwo, appTwoThrows, assertPack, modifyPackageJson, packageJson } from "./helpers/packTester"
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 @@ -4,12 +4,12 @@ import { Arch, ArtifactCreated, DIR_TARGET, getArchSuffix, MacOsTargetName, Pack
import { CancellationToken } from "electron-builder-http"
import { convertVersion } from "electron-builder-squirrel-windows/out/squirrelPack"
import { addValue, exec, getTempName, log, spawn, warn } from "electron-builder-util"
import { getLinuxToolsPath } from "electron-builder-util/out/bundledTool"
import { deepAssign } from "electron-builder-util/out/deepAssign"
import { copyDir, FileCopier } from "electron-builder-util/out/fs"
import { executeFinally } from "electron-builder-util/out/promise"
import { PublishManager } from "electron-builder/out/publish/PublishManager"
import { computeArchToTargetNamesMap } from "electron-builder/out/targets/targetFactory"
import { getLinuxToolsPath } from "electron-builder/out/util/bundledTool"
import { PublishPolicy } from "electron-publish"
import { emptyDir, mkdir, readFile, readJson, remove, writeJson } from "fs-extra-p"
import { safeLoad } from "js-yaml"
Expand Down

0 comments on commit e1dfeb7

Please sign in to comment.