Skip to content

Commit

Permalink
fix: remote building
Browse files Browse the repository at this point in the history
  • Loading branch information
develar committed Jan 3, 2018
1 parent 67d224f commit 357d330
Show file tree
Hide file tree
Showing 11 changed files with 74 additions and 42 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.

6 changes: 3 additions & 3 deletions packages/builder-util/src/asyncTaskManager.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import BluebirdPromise from "bluebird-lst"
import { CancellationToken } from "builder-util-runtime"
import { log } from "./log"
import { NestedError } from "./promise"
import { debug } from "./util"

export class AsyncTaskManager {
readonly tasks: Array<Promise<any>> = []
Expand All @@ -18,7 +18,7 @@ export class AsyncTaskManager {

addTask(promise: Promise<any>) {
if (this.cancellationToken.cancelled) {
debug(`Async task not added because cancelled: ${new Error().stack}`)
log.debug({reason: "cancelled", stack: new Error().stack}, "async task not added")
if ("cancel" in promise) {
(promise as any).cancel()
}
Expand All @@ -27,7 +27,7 @@ export class AsyncTaskManager {

this.tasks.push(promise
.catch(it => {
debug(`Async task error: ${it.stack || it}`)
log.debug({error: it.message}, "async task error")
this.errors.push(it)
return BluebirdPromise.resolve(null)
}))
Expand Down
5 changes: 2 additions & 3 deletions packages/builder-util/src/binDownload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,12 @@ async function doGetBin(name: string, dirName: string, url: string, checksum: st
const logFlags = {path: dirPath}

const dirStat = await statOrNull(dirPath)
//noinspection ES6MissingAwait
if (dirStat != null && dirStat.isDirectory()) {
log.debug(logFlags, `found existing`)
log.debug(logFlags, "found existing")
return dirPath
}

log.info({...logFlags, url}, `downloading`)
log.info({...logFlags, url}, "downloading")

// 7z cannot be extracted from the input stream, temp file is required
const tempUnpackDir = path.join(cachePath, getTempName())
Expand Down
17 changes: 13 additions & 4 deletions packages/electron-builder-lib/src/linuxPackager.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Arch, log } from "builder-util"
import { Arch, AsyncTaskManager, log } from "builder-util"
import { rename } from "fs-extra-p"
import * as path from "path"
import sanitizeFileName from "sanitize-filename"
Expand Down Expand Up @@ -91,6 +91,8 @@ export class LinuxPackager extends PlatformPackager<LinuxConfiguration> {
}

class RemoteTarget extends Target {
private buildTaskManager = new AsyncTaskManager(this.remoteBuilder.packager.info.cancellationToken)

get options(): TargetSpecificOptions | null | undefined {
return this.target.options
}
Expand All @@ -103,11 +105,18 @@ class RemoteTarget extends Target {
super(target.name, true /* all must be scheduled in time (so, on finishBuild RemoteBuilder will have all targets added - so, we must set isAsyncSupported to true (resolved promise is returned)) */)
}

finishBuild(): Promise<any> {
return this.remoteBuilder.build()
async finishBuild() {
await this.buildTaskManager.awaitTasks()
await this.remoteBuilder.build()
}

build(appOutDir: string, arch: Arch) {
const promise = this.doBuild(appOutDir, arch)
this.buildTaskManager.addTask(promise)
return promise
}

async build(appOutDir: string, arch: Arch) {
private async doBuild(appOutDir: string, arch: Arch) {
log.info({target: this.target.name, arch: Arch[arch]}, "scheduling remote build")
await this.target.checkOptions()
this.remoteBuilder.scheduleBuild(this.target, arch, appOutDir)
Expand Down
6 changes: 4 additions & 2 deletions packages/electron-builder-lib/src/platformPackager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,10 @@ export abstract class PlatformPackager<DC extends PlatformSpecificBuildOptions>
}

protected packageInDistributableFormat(appOutDir: string, arch: Arch, targets: Array<Target>, taskManager: AsyncTaskManager): void {
taskManager.addTask(BluebirdPromise.map(targets, it => it.isAsyncSupported ? it.build(appOutDir, arch) : null)
.then(() => BluebirdPromise.each(targets, it => it.isAsyncSupported ? null : it.build(appOutDir, arch))))
taskManager.addTask(
BluebirdPromise.map(targets, it => it.isAsyncSupported ? it.build(appOutDir, arch) : null)
.then(() => BluebirdPromise.each(targets, it => it.isAsyncSupported ? null : it.build(appOutDir, arch)))
)
}

private getExtraFileMatchers(isResources: boolean, appOutDir: string, macroExpander: (pattern: string) => string, customBuildOptions: DC): Array<FileMatcher> | null {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,9 @@ export class RemoteBuildManager {

stream.setEncoding("utf8")
const eventSource = new JsonStreamParser(data => {
log.debug({event: JSON.stringify(data, null, 2)}, "remote builder event")
if (log.isDebugEnabled) {
log.debug({event: JSON.stringify(data, null, 2)}, "remote builder event")
}

const error = data.error
if (error != null) {
Expand All @@ -199,7 +201,7 @@ export class RemoteBuildManager {
message = "job started"
break
}
log.info(message)
log.info({status: message}, "remote building")
return
}

Expand Down Expand Up @@ -231,8 +233,8 @@ export class RemoteBuildManager {

const fileWritten = () => {
this.finishedStreamCount++
log.info({time: downloadTimer.endAndGet(), file: artifact.file}, `downloaded remote build artifact`)
log.debug({file: localFile}, `saved remote artifact`)
log.info({time: downloadTimer.endAndGet(), file: artifact.file}, "downloaded remote build artifact")
log.debug({file: localFile}, "saved remote build artifact")

// PublishManager uses outDir and options, real (the same as for local build) values must be used
this.projectInfoManager.packager.dispatchArtifactCreated(artifactCreatedEvent)
Expand Down Expand Up @@ -317,7 +319,7 @@ export class RemoteBuildManager {
BluebirdPromise.all([this.projectInfoManager.infoFile.value, getZstd()])
.then(results => {
const infoFile = results[0]
log.info(`compressing and uploading to remote build agent`)
log.info("compressing and uploading to remote builder")
const compressAndUploadTimer = new DevTimer("compress and upload")
// noinspection SpellCheckingInspection
const tarProcess = spawn(path7za, [
Expand All @@ -338,7 +340,7 @@ export class RemoteBuildManager {
zstdProcess.stdout.pipe(stream)

zstdProcess.stdout.on("end", () => {
log.info({time: compressAndUploadTimer.endAndGet()}, `uploaded`)
log.info({time: compressAndUploadTimer.endAndGet()}, "uploaded to remote builder")
})
})
.catch(reject)
Expand Down
12 changes: 6 additions & 6 deletions packages/electron-builder-lib/src/remoteBuilder/RemoteBuilder.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import BluebirdPromise from "bluebird-lst"
import { Arch, debug, isEnvTrue, log } from "builder-util"
import { Arch, isEnvTrue, log } from "builder-util"
import { connect, constants } from "http2"
import * as path from "path"
import { promisify } from "util"
Expand All @@ -21,7 +21,7 @@ export class RemoteBuilder {
private readonly toBuild = new Map<Arch, Array<TargetInfo>>()
private buildStarted = false

constructor(private readonly packager: PlatformPackager<any>) {
constructor(readonly packager: PlatformPackager<any>) {
}

scheduleBuild(target: Target, arch: Arch, unpackedDirectory: string) {
Expand Down Expand Up @@ -57,8 +57,8 @@ export class RemoteBuilder {

// noinspection JSMethodCanBeStatic
private async _build(targets: Array<TargetInfo>, packager: PlatformPackager<any>): Promise<any> {
if (debug.enabled) {
debug(`Remote build targets: ${JSON.stringify(targets, null, 2)}`)
if (log.isDebugEnabled) {
log.debug({remoteTargets: JSON.stringify(targets, null, 2)}, "remote building")
}

const projectInfoManager = new ProjectInfoManager(packager.info)
Expand Down Expand Up @@ -141,8 +141,8 @@ async function findBuildAgent(): Promise<string> {
let data = ""
stream.on("end", () => {
try {
if (debug.enabled) {
debug(`Remote build: ${data}`)
if (log.isDebugEnabled) {
log.debug({data}, "remote build response")
}
resolve(JSON.parse(data).endpoint)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as path from "path"
import { Target } from "../core"
import { PlatformPackager } from "../platformPackager"
import { ArchiveOptions } from "./archive"
import { getTool } from "./tools"
import { getBlockMapTool } from "./tools"

export const BLOCK_MAP_FILE_SUFFIX = ".blockmap"

Expand Down Expand Up @@ -44,20 +44,6 @@ export function configureDifferentialAwareArchiveOptions(archiveOptions: Archive
return archiveOptions
}

function getBlockMapTool() {
// noinspection SpellCheckingInspection
return getTool({
repository: "develar/block-map-builder",
name: "block-map-builder",
version: "0.2.0",
mac: "J+aspHER9Hba70oDJAg9ZUyr5KC8beTjIedMQRgrdsWd5Qlc+0COy+zXMw7Pcq+hqDvsEFoM2N4Yx6wQAaXDXA==",
"linux-ia32": "2zkhj4GVvLg8JDsGIDc4CUeZ+eHxwPchNuub+FTjO98YJyCIKDItJorfTStoZe4qlYqCE1tAX7Q/NXmBvpwj6A==",
"linux-x64": "2iErpiWfSMWMMFALd2sIcfU7cd4mFc96EzA/6j9/XCAx0Z6y6vSJinwjMlcemN2SUUsyVkUnHkinCLK7M34GXQ==",
"win-ia32": "QH/b+cmbsPtyaGzKriNGQtvKQ0KEUictieprGgcP7s4flHDXcsO+WtkecZpuJn5m3VLR0dGeSOw/oDxGxszBZA==",
"win-x64": "GMT7M9IibT8v5OY45N7Ar97rHpBcc9HexUGGePnzkv++4Dh7DjIlEeo/Q50MRRkp6pdgIrkG1OawEbJIt2DkLw==",
})
}

export async function appendBlockmap(file: string): Promise<BlockMapDataHolder> {
log.info({file: log.filePath(file)}, "building embedded block map")
return JSON.parse(await exec(await getBlockMapTool(), ["-in", file, "-compression", "deflate"]))
Expand Down
16 changes: 15 additions & 1 deletion packages/electron-builder-lib/src/targets/tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const fpmPath = new Lazy(() => {
// noinspection JSUnusedGlobalSymbols
export function prefetchBuildTools() {
// yes, we starting to use native Promise
return Promise.all([getAppImage(), fpmPath.value])
return Promise.all([getAppImage(), fpmPath.value, getBlockMapTool()])
}

export function getZstd() {
Expand Down Expand Up @@ -100,4 +100,18 @@ export function getTool(descriptor: ToolDescriptor): Promise<string> {
const tagPrefix = descriptor.repository == null ? `${name}-` : "v"
return getBin(name, `${name}-v${version}-${process.arch}`, `https://github.com/${repository}/releases/download/${tagPrefix}${version}/${name}-v${version}-${platform.buildConfigurationKey}${archQualifier}.7z`, checksum)
.then(it => path.join(it, `${name}${platform === Platform.WINDOWS ? ".exe" : ""}`))
}

export function getBlockMapTool() {
// noinspection SpellCheckingInspection
return getTool({
repository: "develar/block-map-builder",
name: "block-map-builder",
version: "0.2.0",
mac: "J+aspHER9Hba70oDJAg9ZUyr5KC8beTjIedMQRgrdsWd5Qlc+0COy+zXMw7Pcq+hqDvsEFoM2N4Yx6wQAaXDXA==",
"linux-ia32": "2zkhj4GVvLg8JDsGIDc4CUeZ+eHxwPchNuub+FTjO98YJyCIKDItJorfTStoZe4qlYqCE1tAX7Q/NXmBvpwj6A==",
"linux-x64": "2iErpiWfSMWMMFALd2sIcfU7cd4mFc96EzA/6j9/XCAx0Z6y6vSJinwjMlcemN2SUUsyVkUnHkinCLK7M34GXQ==",
"win-ia32": "QH/b+cmbsPtyaGzKriNGQtvKQ0KEUictieprGgcP7s4flHDXcsO+WtkecZpuJn5m3VLR0dGeSOw/oDxGxszBZA==",
"win-x64": "GMT7M9IibT8v5OY45N7Ar97rHpBcc9HexUGGePnzkv++4Dh7DjIlEeo/Q50MRRkp6pdgIrkG1OawEbJIt2DkLw==",
})
}
4 changes: 2 additions & 2 deletions packages/electron-builder-lib/src/util/packageMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ function checkDependencies(dependencies: { [key: string]: string } | null | unde
}

const updaterVersion = dependencies["electron-updater"]
if (updaterVersion != null && !semver.satisfies(versionFromDependencyRange(updaterVersion), ">=2.16.1")) {
errors.push(`At least electron-updater 2.16.1 is required by current electron-builder version. Please set electron-updater version to "^2.16.1"`)
if (updaterVersion != null && !semver.satisfies(versionFromDependencyRange(updaterVersion), ">=2.18.2")) {
errors.push(`At least electron-updater 2.18.2 is required by current electron-builder version. Please set electron-updater version to "^2.18.2"`)
}

const deps = ["electron", "electron-prebuilt", "electron-rebuild"]
Expand Down
19 changes: 19 additions & 0 deletions packages/electron-updater/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
## 2.18.2

### Bug Fixes

* **electron-updater:** AutoUpdate takes 60 seconds to fail validating signature on Windows 7 due to PowerShell version [#2421](https://github.com/electron-userland/electron-builder/issues/2421) ([da96e73](https://github.com/electron-userland/electron-builder/commit/da96e73))

## 2.18.1

### Bug Fixes

* **electron-updater:** add error codes ([2822049](https://github.com/electron-userland/electron-builder/commit/2822049)), closes [#2415](https://github.com/electron-userland/electron-builder/issues/2415)

## 2.18.0

### Bug Fixes

* **electron-updater:** redirect event in electron.net ([e2ac601](https://github.com/electron-userland/electron-builder/commit/e2ac601)), closes [#2374](https://github.com/electron-userland/electron-builder/issues/2374)
* use solid compression for web installer package ([6ea5668](https://github.com/electron-userland/electron-builder/commit/6ea5668))

## 2.17.2

### Bug Fixes
Expand Down

0 comments on commit 357d330

Please sign in to comment.