Skip to content

Commit

Permalink
feat: macOS default architecture (#5495) (#5504)
Browse files Browse the repository at this point in the history
  • Loading branch information
lutzroeder authored Jan 15, 2021
1 parent 283e1a2 commit 5203d7e
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 19 deletions.
14 changes: 14 additions & 0 deletions packages/app-builder-lib/scheme.json
Original file line number Diff line number Diff line change
Expand Up @@ -2389,6 +2389,20 @@
],
"default": "distribution",
"description": "Whether to sign app for development or for distribution."
},
"defaultArch": {
"anyOf": [
{
"enum": [
"arm64",
"universal",
"x64"
],
"type": "string"
}
],
"default": "x64",
"description": "The default arch to skip in target names."
}
},
"type": "object"
Expand Down
6 changes: 3 additions & 3 deletions packages/app-builder-lib/src/macPackager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,10 @@ export default class MacPackager extends PlatformPackager<MacConfiguration> {
}
case Arch.universal: {
const x64Arch = Arch.x64;
const x64AppOutDir = appOutDir + '-' + Arch[x64Arch];
const x64AppOutDir = appOutDir + '--' + Arch[x64Arch];
await super.doPack(outDir, x64AppOutDir, platformName, x64Arch, platformSpecificBuildOptions, targets, false);
const arm64Arch = Arch.arm64;
const arm64AppOutPath = appOutDir + '-' + Arch[arm64Arch];
const arm64AppOutPath = appOutDir + '--' + Arch[arm64Arch];
await super.doPack(outDir, arm64AppOutPath, platformName, arm64Arch, platformSpecificBuildOptions, targets, false);
const framework = this.info.framework
log.info({
Expand Down Expand Up @@ -278,7 +278,7 @@ export default class MacPackager extends PlatformPackager<MacConfiguration> {
const artifactName = this.expandArtifactNamePattern(masOptions, "pkg", arch)
const artifactPath = path.join(outDir!, artifactName)
await this.doFlat(appPath, artifactPath, masInstallerIdentity, keychainFile)
await this.dispatchArtifactCreated(artifactPath, null, Arch.x64, this.computeSafeArtifactName(artifactName, "pkg", arch))
await this.dispatchArtifactCreated(artifactPath, null, Arch.x64, this.computeSafeArtifactName(artifactName, "pkg", arch, true, this.platformSpecificBuildOptions.defaultArch))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ export interface PlatformSpecificBuildOptions extends TargetSpecificOptions {

/** @private */
cscKeyPassword?: string | null

readonly defaultArch?: string
}

export interface ReleaseInfo {
Expand Down
14 changes: 7 additions & 7 deletions packages/app-builder-lib/src/platformPackager.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import BluebirdPromise from "bluebird-lst"
import { Arch, asArray, AsyncTaskManager, debug, DebugLogger, deepAssign, getArchSuffix, InvalidConfigurationError, isEmptyOrSpaces, log, isEnvTrue } from "builder-util"
import { getArtifactArchName } from "builder-util/out/arch"
import { defaultArchFromString, getArtifactArchName } from "builder-util/out/arch"
import { FileTransformer, statOrNull } from "builder-util/out/fs"
import { orIfFileNotExist } from "builder-util/out/promise"
import { readdir } from "fs-extra"
Expand Down Expand Up @@ -100,7 +100,7 @@ export abstract class PlatformPackager<DC extends PlatformSpecificBuildOptions>
}

protected computeAppOutDir(outDir: string, arch: Arch): string {
return this.packagerOptions.prepackaged || path.join(outDir, `${this.platform.buildConfigurationKey}${getArchSuffix(arch)}${this.platform === Platform.MAC ? "" : "-unpacked"}`)
return this.packagerOptions.prepackaged || path.join(outDir, `${this.platform.buildConfigurationKey}${getArchSuffix(arch, this.platformSpecificBuildOptions.defaultArch)}${this.platform === Platform.MAC ? "" : "-unpacked"}`)
}

dispatchArtifactCreated(file: string, target: Target | null, arch: Arch | null, safeArtifactName?: string | null): Promise<void> {
Expand Down Expand Up @@ -483,11 +483,11 @@ export abstract class PlatformPackager<DC extends PlatformSpecificBuildOptions>
}

// tslint:disable-next-line:no-invalid-template-strings
computeSafeArtifactName(suggestedName: string | null, ext: string, arch?: Arch | null, skipArchIfX64 = true, safePattern: string = "${name}-${version}-${arch}.${ext}"): string | null {
return computeSafeArtifactNameIfNeeded(suggestedName, () => this.computeArtifactName(safePattern, ext, skipArchIfX64 && arch === Arch.x64 ? null : arch))
computeSafeArtifactName(suggestedName: string | null, ext: string, arch?: Arch | null, skipDefaultArch: boolean = true, defaultArch?: string, safePattern: string = "${name}-${version}-${arch}.${ext}"): string | null {
return computeSafeArtifactNameIfNeeded(suggestedName, () => this.computeArtifactName(safePattern, ext, skipDefaultArch && arch === defaultArchFromString(defaultArch) ? null : arch))
}

expandArtifactNamePattern(targetSpecificOptions: TargetSpecificOptions | null | undefined, ext: string, arch?: Arch | null, defaultPattern?: string, skipArchIfX64 = true): string {
expandArtifactNamePattern(targetSpecificOptions: TargetSpecificOptions | null | undefined, ext: string, arch?: Arch | null, defaultPattern?: string, skipDefaultArch: boolean = true, defaultArch?: string): string {
let pattern = targetSpecificOptions == null ? null : targetSpecificOptions.artifactName
if (pattern == null) {
pattern = this.platformSpecificBuildOptions.artifactName || this.config.artifactName
Expand All @@ -499,9 +499,9 @@ export abstract class PlatformPackager<DC extends PlatformSpecificBuildOptions>
} else {
// https://github.com/electron-userland/electron-builder/issues/3510
// always respect arch in user custom artifact pattern
skipArchIfX64 = this.platform === Platform.MAC
skipDefaultArch = this.platform === Platform.MAC
}
return this.computeArtifactName(pattern, ext, skipArchIfX64 && arch === Arch.x64 ? null : arch)
return this.computeArtifactName(pattern, ext, skipDefaultArch && arch === defaultArchFromString(defaultArch) ? null : arch)
}

expandArtifactBeautyNamePattern(targetSpecificOptions: TargetSpecificOptions | null | undefined, ext: string, arch?: Arch | null): string {
Expand Down
9 changes: 5 additions & 4 deletions packages/app-builder-lib/src/targets/ArchiveTarget.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Arch } from "builder-util"
import { Arch, defaultArchFromString } from "builder-util"
import * as path from "path"
import { Platform, Target, TargetSpecificOptions } from "../core"
import { copyFiles, getFileMatchers } from "../fileMatcher"
Expand All @@ -19,13 +19,14 @@ export class ArchiveTarget extends Target {
const format = this.name

let defaultPattern: string
const defaultArch: Arch = defaultArchFromString(packager.platformSpecificBuildOptions.defaultArch);
if (packager.platform === Platform.LINUX) {
// tslint:disable-next-line:no-invalid-template-strings
defaultPattern = "${name}-${version}" + (arch === Arch.x64 ? "" : "-${arch}") + ".${ext}"
defaultPattern = "${name}-${version}" + (arch === defaultArch ? "" : "-${arch}") + ".${ext}"
}
else {
// tslint:disable-next-line:no-invalid-template-strings
defaultPattern = "${productName}-${version}" + (arch === Arch.x64 ? "" : "-${arch}") + "-${os}.${ext}"
defaultPattern = "${productName}-${version}" + (arch === defaultArch ? "" : "-${arch}") + "-${os}.${ext}"
}

const artifactName = packager.expandArtifactNamePattern(this.options, format, arch, defaultPattern, false)
Expand Down Expand Up @@ -70,7 +71,7 @@ export class ArchiveTarget extends Target {
updateInfo,
file: artifactPath,
// tslint:disable-next-line:no-invalid-template-strings
safeArtifactName: packager.computeSafeArtifactName(artifactName, format, arch, false, defaultPattern.replace("${productName}", "${name}")),
safeArtifactName: packager.computeSafeArtifactName(artifactName, format, arch, false, packager.platformSpecificBuildOptions.defaultArch, defaultPattern.replace("${productName}", "${name}")),
target: this,
arch,
packager,
Expand Down
8 changes: 6 additions & 2 deletions packages/builder-util/src/arch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ export function getArchCliNames(): Array<string> {
return [Arch[Arch.ia32], Arch[Arch.x64], Arch[Arch.armv7l], Arch[Arch.arm64]]
}

export function getArchSuffix(arch: Arch): string {
return arch === Arch.x64 ? "" : `-${Arch[arch]}`
export function getArchSuffix(arch: Arch, defaultArch?: string): string {
return arch === defaultArchFromString(defaultArch) ? "" : `-${Arch[arch]}`
}

export function archFromString(name: string): Arch {
Expand All @@ -45,6 +45,10 @@ export function archFromString(name: string): Arch {
}
}

export function defaultArchFromString(name?: string): Arch {
return name ? archFromString(name) : Arch.x64;
}

export function getArtifactArchName(arch: Arch, ext: string): string {
let archName = Arch[arch]
const isAppImage = ext === "AppImage" || ext === "appimage"
Expand Down
2 changes: 1 addition & 1 deletion packages/builder-util/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ if (process.env.JEST_WORKER_ID == null) {
export { safeStringifyJson } from "builder-util-runtime"
export { TmpDir } from "temp-file"
export { log, debug } from "./log"
export { Arch, getArchCliNames, toLinuxArchString, getArchSuffix, ArchType, archFromString } from "./arch"
export { Arch, getArchCliNames, toLinuxArchString, getArchSuffix, ArchType, archFromString, defaultArchFromString } from "./arch"
export { AsyncTaskManager } from "./asyncTaskManager"
export { DebugLogger } from "./DebugLogger"

Expand Down
4 changes: 2 additions & 2 deletions packages/dmg-builder/src/dmg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class DmgTarget extends Target {
async build(appPath: string, arch: Arch) {
const packager = this.packager
// tslint:disable-next-line:no-invalid-template-strings
const artifactName = packager.expandArtifactNamePattern(this.options, "dmg", arch, "${productName}-" + (packager.platformSpecificBuildOptions.bundleShortVersion || "${version}") + "-${arch}.${ext}", true)
const artifactName = packager.expandArtifactNamePattern(this.options, "dmg", arch, "${productName}-" + (packager.platformSpecificBuildOptions.bundleShortVersion || "${version}") + "-${arch}.${ext}", true, packager.platformSpecificBuildOptions.defaultArch)
const artifactPath = path.join(this.outDir, artifactName)
await packager.info.callArtifactBuildStarted({
targetPresentableName: "DMG",
Expand Down Expand Up @@ -118,7 +118,7 @@ export class DmgTarget extends Target {
computeVolumeName(arch: Arch, custom?: string | null): string {
const appInfo = this.packager.appInfo
const shortVersion = this.packager.platformSpecificBuildOptions.bundleShortVersion || appInfo.version
const archString = getArchSuffix(arch)
const archString = getArchSuffix(arch, this.packager.platformSpecificBuildOptions.defaultArch)

if (custom == null) {
return `${appInfo.productFilename} ${shortVersion}${archString}`
Expand Down

0 comments on commit 5203d7e

Please sign in to comment.