Skip to content

Commit

Permalink
fix: use universal-darwin on apple silicon
Browse files Browse the repository at this point in the history
  • Loading branch information
teatimeguest committed Mar 6, 2024
1 parent 04c4eb4 commit bc94138
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 6 deletions.
26 changes: 21 additions & 5 deletions packages/main/src/texlive/install-tl/profile.ts
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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;
Expand Down Expand Up @@ -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<string, unknown> & {
readonly instopt: object;
readonly tlpdbopt: object;
[key: string]: object;
};
const options = this.version < '2017'
? { option: { ...instopt, ...tlpdbopt } }
Expand All @@ -66,6 +79,9 @@ export class Profile extends Mixin(SystemTrees, UserTrees) {
plain[`${prefix}_${key}`] = value;
}
}
if (binary !== undefined) {
plain[`binary_${binary}`] = '1';
}
return plain;
}
}
Expand Down
25 changes: 24 additions & 1 deletion packages/main/tests/__tests__/texlive/install-tl/profile.test.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -11,6 +11,10 @@ vi.unmock('#/texlive/install-tl/profile');

const opts = { prefix: '<prefix>' };

beforeEach(() => {
vi.mocked(os.arch).mockReturnValue('x64');
});

describe('selected_scheme', () => {
it('uses scheme-infraonly by default', () => {
const profile = new Profile(LATEST_VERSION, opts);
Expand Down Expand Up @@ -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<Version, void, void> {
for (let year = 2008; year <= Number.parseInt(LATEST_VERSION); ++year) {
Expand Down

0 comments on commit bc94138

Please sign in to comment.