From 5203d7eb15726605e8987aeed7a5ccedc8152e04 Mon Sep 17 00:00:00 2001 From: Lutz Roeder Date: Thu, 14 Jan 2021 23:49:00 -0800 Subject: [PATCH] feat: macOS default architecture (#5495) (#5504) --- packages/app-builder-lib/scheme.json | 14 ++++++++++++++ packages/app-builder-lib/src/macPackager.ts | 6 +++--- .../src/options/PlatformSpecificBuildOptions.ts | 2 ++ packages/app-builder-lib/src/platformPackager.ts | 14 +++++++------- .../app-builder-lib/src/targets/ArchiveTarget.ts | 9 +++++---- packages/builder-util/src/arch.ts | 8 ++++++-- packages/builder-util/src/util.ts | 2 +- packages/dmg-builder/src/dmg.ts | 4 ++-- 8 files changed, 40 insertions(+), 19 deletions(-) diff --git a/packages/app-builder-lib/scheme.json b/packages/app-builder-lib/scheme.json index 4b5f9c77f4b..bf1d8e0a2a6 100644 --- a/packages/app-builder-lib/scheme.json +++ b/packages/app-builder-lib/scheme.json @@ -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" diff --git a/packages/app-builder-lib/src/macPackager.ts b/packages/app-builder-lib/src/macPackager.ts index a142c3fa509..580ef5f455c 100644 --- a/packages/app-builder-lib/src/macPackager.ts +++ b/packages/app-builder-lib/src/macPackager.ts @@ -99,10 +99,10 @@ export default class MacPackager extends PlatformPackager { } 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({ @@ -278,7 +278,7 @@ export default class MacPackager extends PlatformPackager { 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)) } } diff --git a/packages/app-builder-lib/src/options/PlatformSpecificBuildOptions.ts b/packages/app-builder-lib/src/options/PlatformSpecificBuildOptions.ts index 268a4f209a4..49af68b56e6 100644 --- a/packages/app-builder-lib/src/options/PlatformSpecificBuildOptions.ts +++ b/packages/app-builder-lib/src/options/PlatformSpecificBuildOptions.ts @@ -115,6 +115,8 @@ export interface PlatformSpecificBuildOptions extends TargetSpecificOptions { /** @private */ cscKeyPassword?: string | null + + readonly defaultArch?: string } export interface ReleaseInfo { diff --git a/packages/app-builder-lib/src/platformPackager.ts b/packages/app-builder-lib/src/platformPackager.ts index 50277cffeb2..b4fa90e9403 100644 --- a/packages/app-builder-lib/src/platformPackager.ts +++ b/packages/app-builder-lib/src/platformPackager.ts @@ -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" @@ -100,7 +100,7 @@ export abstract class PlatformPackager } 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 { @@ -483,11 +483,11 @@ export abstract class PlatformPackager } // 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 @@ -499,9 +499,9 @@ export abstract class PlatformPackager } 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 { diff --git a/packages/app-builder-lib/src/targets/ArchiveTarget.ts b/packages/app-builder-lib/src/targets/ArchiveTarget.ts index bfb660e913c..d7494fc892b 100644 --- a/packages/app-builder-lib/src/targets/ArchiveTarget.ts +++ b/packages/app-builder-lib/src/targets/ArchiveTarget.ts @@ -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" @@ -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) @@ -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, diff --git a/packages/builder-util/src/arch.ts b/packages/builder-util/src/arch.ts index a9aa260cd42..04c16aa9a3d 100644 --- a/packages/builder-util/src/arch.ts +++ b/packages/builder-util/src/arch.ts @@ -24,8 +24,8 @@ export function getArchCliNames(): Array { 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 { @@ -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" diff --git a/packages/builder-util/src/util.ts b/packages/builder-util/src/util.ts index c68f33a0a47..37005855892 100644 --- a/packages/builder-util/src/util.ts +++ b/packages/builder-util/src/util.ts @@ -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" diff --git a/packages/dmg-builder/src/dmg.ts b/packages/dmg-builder/src/dmg.ts index c46a0f5a38b..6fa80e61bfe 100644 --- a/packages/dmg-builder/src/dmg.ts +++ b/packages/dmg-builder/src/dmg.ts @@ -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", @@ -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}`