From bc9413891dc67f49449711771bdd9f51e6def640 Mon Sep 17 00:00:00 2001 From: teatimeguest Date: Thu, 7 Mar 2024 07:02:49 +0900 Subject: [PATCH] fix: use universal-darwin on apple silicon --- .../main/src/texlive/install-tl/profile.ts | 26 +++++++++++++++---- .../texlive/install-tl/profile.test.ts | 25 +++++++++++++++++- 2 files changed, 45 insertions(+), 6 deletions(-) diff --git a/packages/main/src/texlive/install-tl/profile.ts b/packages/main/src/texlive/install-tl/profile.ts index 3a64bab..f86d69a 100644 --- a/packages/main/src/texlive/install-tl/profile.ts +++ b/packages/main/src/texlive/install-tl/profile.ts @@ -1,15 +1,27 @@ import { writeFile } from 'node:fs/promises'; -import { platform } from 'node:os'; +import { arch, platform } from 'node:os'; import * as path from 'node:path'; import { Exclude, Expose, Type, instanceToPlain } from 'class-transformer'; import { Mixin } from 'ts-mixer'; -import { SystemTrees, UserTrees } from '#/texlive/install-tl/texmf'; +import { + SystemTrees, + type TexmfOptions, + UserTrees, +} from '#/texlive/install-tl/texmf'; +import type { Version } from '#/texlive/version'; import { Case, type Tmpdir, mkdtemp } from '#/util'; @Exclude() export class Profile extends Mixin(SystemTrees, UserTrees) { + constructor(version: Version, options: TexmfOptions) { + super(version, options); + if (version < '2020' && platform() === 'darwin' && arch() === 'arm64') { + this.binary = 'universal-darwin'; + } + } + @Case('snake') get selectedScheme(): string { // `scheme-infraonly` was first introduced in TeX Live 2016. @@ -19,6 +31,8 @@ export class Profile extends Mixin(SystemTrees, UserTrees) { readonly instopt = new InstOpt(); @Expose() readonly tlpdbopt = new TlpdbOpt(); + @Expose({ until: 2017, groups: ['darwin'] }) + declare readonly binary?: string; #tmpdir: Tmpdir | undefined; #path: string | undefined; @@ -50,13 +64,12 @@ export class Profile extends Mixin(SystemTrees, UserTrees) { } toJSON(): object { - const { instopt, tlpdbopt, ...plain } = instanceToPlain(this, { + const { instopt, tlpdbopt, binary, ...plain } = instanceToPlain(this, { version: Number.parseInt(this.version), groups: [platform()], - }) as { + }) as Record & { readonly instopt: object; readonly tlpdbopt: object; - [key: string]: object; }; const options = this.version < '2017' ? { option: { ...instopt, ...tlpdbopt } } @@ -66,6 +79,9 @@ export class Profile extends Mixin(SystemTrees, UserTrees) { plain[`${prefix}_${key}`] = value; } } + if (binary !== undefined) { + plain[`binary_${binary}`] = '1'; + } return plain; } } diff --git a/packages/main/tests/__tests__/texlive/install-tl/profile.test.ts b/packages/main/tests/__tests__/texlive/install-tl/profile.test.ts index d2f3e49..85828ca 100644 --- a/packages/main/tests/__tests__/texlive/install-tl/profile.test.ts +++ b/packages/main/tests/__tests__/texlive/install-tl/profile.test.ts @@ -1,4 +1,4 @@ -import { beforeAll, describe, expect, it, test, vi } from 'vitest'; +import { beforeAll, beforeEach, describe, expect, it, test, vi } from 'vitest'; import * as os from 'node:os'; @@ -11,6 +11,10 @@ vi.unmock('#/texlive/install-tl/profile'); const opts = { prefix: '' }; +beforeEach(() => { + vi.mocked(os.arch).mockReturnValue('x64'); +}); + describe('selected_scheme', () => { it('uses scheme-infraonly by default', () => { const profile = new Profile(LATEST_VERSION, opts); @@ -41,6 +45,25 @@ describe('instopt_adjustrepo', () => { ); }); +describe('binary', () => { + it.each( + ['linux', 'win32', 'darwin'] as const, + )('is unspecified by default', (platform) => { + vi.mocked(os.platform).withImplementation(() => platform, () => { + const profile = new Profile(LATEST_VERSION, opts); + expect(profile).not.toHaveProperty('binary'); + }); + }); + + it('uses universal-darwin on apple silicon', () => { + vi.mocked(os.arch).mockReturnValue('arm64'); + vi.mocked(os.platform).withImplementation(() => 'darwin', () => { + const profile = new Profile('2019', opts); + expect(profile).toHaveProperty('binary', 'universal-darwin'); + }); + }); +}); + describe.each([ ...(function*(): Generator { for (let year = 2008; year <= Number.parseInt(LATEST_VERSION); ++year) {