X Tutup
Skip to content

Commit 73f1be4

Browse files
committed
do arch test on macos broth binaries for amd64 -> arm64 migration #3379
1 parent 1a8bae4 commit 73f1be4

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

src/main/broth/package.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ import { Logger } from "common/logger";
44
import { PackageState, ProgressInfo, Store } from "common/types";
55
import { MinimalContext } from "main/context";
66
import spawn from "main/os/spawn";
7+
import { execFile } from "child_process";
78
import { dirname, join } from "path";
89
import querystring from "querystring";
910
import * as semver from "semver";
11+
import { promisify } from "util";
1012
import which from "which";
1113
import { downloadToFileWithRetry } from "main/net/download";
1214
import { request } from "main/net/request/metal-request";
@@ -17,6 +19,7 @@ import formulas, { FormulaSpec } from "main/broth/formulas";
1719
import { platformString } from "main/broth/platform";
1820
import { unzip } from "main/broth/unzip";
1921

22+
const execFileAsync = promisify(execFile);
2023
const sanityCheckTimeout = 10000;
2124
const platform = platformString();
2225

@@ -450,11 +453,42 @@ export class Package implements PackageLike {
450453
return presentVersions;
451454
}
452455

456+
private async isBinaryNativeArch(
457+
logger: Logger,
458+
versionPrefix: string
459+
): Promise<boolean> {
460+
if (process.platform !== "darwin" || process.arch !== "arm64") {
461+
return true;
462+
}
463+
464+
const binaryPath = join(versionPrefix, this.name);
465+
try {
466+
const { stdout } = await execFileAsync("/usr/bin/file", [binaryPath]);
467+
logger.debug(`Architecture check for ${this.name}: ${stdout.trim()}`);
468+
469+
if (!stdout.includes("arm64")) {
470+
logger.info(
471+
`${this.name} binary is not arm64-native, will re-download`
472+
);
473+
return false;
474+
}
475+
return true;
476+
} catch (e) {
477+
logger.warn(`Could not check architecture of ${this.name}: ${e.message}`);
478+
return true;
479+
}
480+
}
481+
453482
async isVersionValid(logger: Logger, v: Version): Promise<boolean> {
454483
const ctx = new MinimalContext();
455484
const { formula } = this;
456485
const { sanityCheck } = formula;
457486
const versionPrefix = this.getVersionPrefix(v);
487+
488+
if (!(await this.isBinaryNativeArch(logger, versionPrefix))) {
489+
return false;
490+
}
491+
458492
try {
459493
let t1 = Date.now();
460494
await Promise.race([

0 commit comments

Comments
 (0)
X Tutup