Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: "Can't reconcile two non-macho files" due to new "PreGyp Copy" functionality in electron/rebuild integration #7519

Merged
merged 12 commits into from
Apr 5, 2023
6 changes: 6 additions & 0 deletions .changeset/flat-jars-glow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"app-builder-lib": patch
"electron-builder": patch
---

fix: "Can't reconcile two non-macho files" due to `disablePreGypCopy` functionality in new electron/rebuild integration
5 changes: 4 additions & 1 deletion packages/app-builder-lib/src/fileMatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ export const excludedNames =
".yarn-integrity,.yarn-metadata.json,yarn-error.log,yarn.lock,package-lock.json,npm-debug.log," +
"appveyor.yml,.travis.yml,circle.yml,.nyc_output"

export const excludedExts = "iml,hprof,orig,pyc,pyo,rbc,swp,csproj,sln,suo,xproj,cc,d.ts"
export const excludedExts =
"iml,hprof,orig,pyc,pyo,rbc,swp,csproj,sln,suo,xproj,cc,d.ts," +
// https://github.com/electron-userland/electron-builder/issues/7512
"mk,a,o,h,forge-meta"

function ensureNoEndSlash(file: string): string {
if (path.sep !== "/") {
Expand Down
6 changes: 4 additions & 2 deletions packages/app-builder-lib/src/macPackager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,13 @@ export default class MacPackager extends PlatformPackager<MacConfiguration> {
return super.doPack(outDir, appOutDir, platformName, arch, platformSpecificBuildOptions, targets)
}
case Arch.universal: {
const outDirName = (arch: Arch) => `${appOutDir}-${Arch[arch]}-temp`

const x64Arch = Arch.x64
const x64AppOutDir = appOutDir + "--" + Arch[x64Arch]
const x64AppOutDir = outDirName(x64Arch)
await super.doPack(outDir, x64AppOutDir, platformName, x64Arch, platformSpecificBuildOptions, targets, false, true)
const arm64Arch = Arch.arm64
const arm64AppOutPath = appOutDir + "--" + Arch[arm64Arch]
const arm64AppOutPath = outDirName(arm64Arch)
await super.doPack(outDir, arm64AppOutPath, platformName, arm64Arch, platformSpecificBuildOptions, targets, false, true)
const framework = this.info.framework
log.info(
Expand Down
3 changes: 1 addition & 2 deletions packages/app-builder-lib/src/packager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ export class Packager {
const frameworkInfo = { version: this.framework.version, useCustomDist: true }
const config = this.config
if (config.nodeGypRebuild === true) {
await nodeGypRebuild(frameworkInfo, Arch[arch])
await nodeGypRebuild(frameworkInfo, arch)
}

if (config.npmRebuild === false) {
Expand Down Expand Up @@ -526,7 +526,6 @@ export class Packager {
frameworkInfo,
platform: platform.nodeName,
arch: Arch[arch],
productionDeps: this.getNodeDependencyInfo(null),
})
}
}
Expand Down
16 changes: 7 additions & 9 deletions packages/app-builder-lib/src/util/yarn.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { asArray, log, spawn } from "builder-util"
import { Arch, archFromString, asArray, log, spawn } from "builder-util"
import { pathExists } from "fs-extra"
import { Lazy } from "lazy-val"
import { homedir } from "os"
import * as path from "path"
import { Configuration } from "../configuration"
import { NodeModuleDirInfo } from "./packageDependencies"
import * as electronRebuild from "@electron/rebuild"
import * as searchModule from "@electron/rebuild/lib/src/search-module"

Expand All @@ -25,7 +23,8 @@ export async function installOrRebuild(config: Configuration, appDir: string, op
}
await installDependencies(appDir, effectiveOptions)
} else {
await rebuild(appDir, config.buildDependenciesFromSource === true, options.frameworkInfo, options.arch)
const arch = archFromString(options.arch || process.arch)
await rebuild(appDir, config.buildDependenciesFromSource === true, options.frameworkInfo, arch)
}
}

Expand Down Expand Up @@ -118,7 +117,7 @@ function installDependencies(appDir: string, options: RebuildOptions): Promise<a
})
}

export async function nodeGypRebuild(frameworkInfo: DesktopFrameworkInfo, arch: string) {
export async function nodeGypRebuild(frameworkInfo: DesktopFrameworkInfo, arch: Arch) {
return rebuild(process.cwd(), false, frameworkInfo, arch)
}

Expand All @@ -137,7 +136,6 @@ function isRunningYarn(execPath: string | null | undefined) {

export interface RebuildOptions {
frameworkInfo: DesktopFrameworkInfo
productionDeps?: Lazy<Array<NodeModuleDirInfo>>

platform?: NodeJS.Platform
arch?: string
Expand All @@ -148,15 +146,15 @@ export interface RebuildOptions {
}

/** @internal */
export async function rebuild(appDir: string, buildFromSource: boolean, frameworkInfo: DesktopFrameworkInfo, arch = process.arch) {
export async function rebuild(appDir: string, buildFromSource: boolean, frameworkInfo: DesktopFrameworkInfo, arch: Arch) {
log.info({ arch, version: frameworkInfo.version, appDir }, "executing @electron/rebuild")
const rootPath = await searchModule.getProjectRootPath(appDir)
const options: electronRebuild.RebuildOptions = {
buildPath: appDir,
electronVersion: frameworkInfo.version,
arch,
debug: log.isDebugEnabled,
arch: Arch[arch],
projectRootPath: rootPath,
Copy link
Contributor

@sandeep1995 sandeep1995 Apr 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also add a different cachePath argument for different arch?

https://github.com/electron/rebuild/blob/main/src/types.ts#L10

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What for? Why can't the default cache be used?

disablePreGypCopy: true,
}
if (buildFromSource) {
options.prebuildTagPrefix = "totally-not-a-real-prefix-to-force-rebuild"
Expand Down
10 changes: 4 additions & 6 deletions packages/electron-builder/src/cli/install-app-deps.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
#! /usr/bin/env node

import { PACKAGE_VERSION } from "app-builder-lib/out/version"
import { log, use, getArchCliNames } from "builder-util"
import { printErrorAndExit } from "builder-util/out/promise"
import { computeDefaultAppDirectory, getConfig } from "app-builder-lib/out/util/config"
import { getElectronVersion } from "app-builder-lib/out/electron/electronVersion"
import { createLazyProductionDeps } from "app-builder-lib/out/util/packageDependencies"
import { computeDefaultAppDirectory, getConfig } from "app-builder-lib/out/util/config"
import { installOrRebuild } from "app-builder-lib/out/util/yarn"
import { PACKAGE_VERSION } from "app-builder-lib/out/version"
import { getArchCliNames, log, use } from "builder-util"
import { printErrorAndExit } from "builder-util/out/promise"
import { readJson } from "fs-extra"
import { Lazy } from "lazy-val"
import * as path from "path"
Expand Down Expand Up @@ -63,7 +62,6 @@ export async function installAppDeps(args: any) {
frameworkInfo: { version, useCustomDist: true },
platform: args.platform,
arch: args.arch,
productionDeps: createLazyProductionDeps(appDir, null),
},
appDir !== projectDir
)
Expand Down