Skip to content

Commit 36bb640

Browse files
add Rosetta 2 exec on mac
fix licensing docs add support for floating license config as path AND base64 string fix occasional race condition when starting editor process exits faster than logs can be seen
1 parent ed05a9b commit 36bb640

5 files changed

Lines changed: 33 additions & 9 deletions

File tree

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,10 @@ unity-cli setup-unity --unity-version 2022.3.x --modules android,ios
6161

6262
#### Activate a Unity License
6363

64+
Supports personal, professional, and floating licenses (using a license server configuration).
65+
6466
```bash
65-
unity-cli activate-license --email <your-email> --password <your-password> --serial <your-serial>
67+
unity-cli activate-license --license personal --email <your-email> --password <your-password>
6668
```
6769

6870
#### Create a New Project from a Template

src/cli.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ program.command('license-version')
3636

3737
program.command('activate-license')
3838
.description('Activate a Unity license.')
39+
.option('-l, --license <license>', 'License type (personal, professional, floating). Required.')
3940
.option('-e, --email <email>', 'Email associated with the Unity account. Required when activating a personal or professional license.')
4041
.option('-p, --password <password>', 'Password for the Unity account. Required when activating a personal or professional license.')
4142
.option('-s, --serial <serial>', 'License serial number. Required when activating a professional license.')
42-
.option('-l, --license <license>', 'License type (personal, professional, floating).')
43-
.option('-c, --config <config>', 'Path to the configuration file. Required when activating a floating license.')
43+
.option('-c, --config <config>', 'Path to the configuration file, or base64 encoded JSON string. Required when activating a floating license.')
4444
.option('--verbose', 'Enable verbose logging.')
4545
.action(async (options) => {
4646
if (options.verbose) {

src/license-client.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,8 +354,19 @@ export class LicensingClient {
354354
throw new Error(`Unsupported platform: ${process.platform}`);
355355
}
356356

357+
// Ensure the services directory exists
358+
if (!fs.existsSync(servicesPath)) {
359+
await fs.promises.mkdir(servicesPath, { recursive: true });
360+
}
361+
357362
const servicesConfigPath = path.join(servicesPath, 'services-config.json');
358-
await fs.promises.writeFile(servicesConfigPath, Buffer.from(options.servicesConfig, 'base64'));
363+
364+
if (fs.existsSync(options.servicesConfig)) {
365+
await fs.promises.copyFile(options.servicesConfig, servicesConfigPath);
366+
}
367+
else {
368+
await fs.promises.writeFile(servicesConfigPath, Buffer.from(options.servicesConfig, 'base64'));
369+
}
359370
break;
360371
}
361372
default: { // personal and professional license activation

src/unity-editor.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ export class UnityEditor {
151151
*/
152152
public async Run(command: EditorCommand): Promise<void> {
153153
let isCancelled = false;
154-
let exitCode: number = 1;
154+
let exitCode: number | undefined = undefined;
155155
let procInfo: ProcInfo | null = null;
156156
let logTail: LogTailResult | null = null;
157157
let unityProcess: ChildProcessByStdio<null, null, null>;
@@ -196,6 +196,7 @@ export class UnityEditor {
196196
}
197197

198198
const logPath: string = GetArgumentValueAsString('-logFile', command.args);
199+
logTail = TailLogFile(logPath);
199200
const commandStr = `\x1b[34m${this.editorPath} ${command.args.join(' ')}\x1b[0m`;
200201
this.logger.startGroup(commandStr);
201202

@@ -211,6 +212,13 @@ export class UnityEditor {
211212
}
212213
});
213214
} else {
215+
if (process.platform === 'darwin') {
216+
if (this.version.architecture === 'X86_64' && process.arch === 'arm64') {
217+
// Force the Unity Editor to run under Rosetta 2 on Apple Silicon Macs if the editor is x86_64
218+
command.args.unshift('arch', '-x86_64');
219+
}
220+
}
221+
214222
unityProcess = spawn(
215223
this.editorPath,
216224
command.args, {
@@ -230,14 +238,13 @@ export class UnityEditor {
230238
process.once('SIGTERM', onCancel);
231239
procInfo = { pid: unityProcess.pid, ppid: process.pid, name: this.editorPath };
232240
this.logger.debug(`Unity process started with pid: ${procInfo.pid}`);
233-
await WaitForFileToBeCreatedAndReadable(logPath, 10_000);
234-
logTail = TailLogFile(logPath);
235241
exitCode = await new Promise((resolve, reject) => {
236242
unityProcess.on('close', (code) => {
237243
logTail?.stopLogTail();
238244
resolve(code === null ? 1 : code);
239245
});
240246
unityProcess.on('error', (error) => {
247+
this.logger.error(`Unity process error: ${error}`);
241248
logTail?.stopLogTail();
242249
reject(error);
243250
});
@@ -258,7 +265,9 @@ export class UnityEditor {
258265
if (!isCancelled) {
259266
await tryKillEditorProcesses();
260267

261-
if (exitCode !== 0) {
268+
if (exitCode === undefined) {
269+
throw Error('Failed to start Unity!');
270+
} else if (exitCode > 0) {
262271
throw Error(`Unity failed with exit code ${exitCode}`);
263272
}
264273
}

src/utilities.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,13 +390,15 @@ export function TailLogFile(logPath: string): LogTailResult {
390390
const tailPromise = new Promise<void>((resolve, reject) => {
391391
(async () => {
392392
try {
393+
await WaitForFileToBeCreatedAndReadable(logPath, 10_000);
394+
393395
while (!logEnded) {
394396
await Delay(logPollingInterval);
395397
await readNewLogContent();
396398
}
397399

398400
// Final read to capture any remaining content after tailing stops
399-
await WaitForFileToBeUnlocked(logPath, 10000);
401+
await WaitForFileToBeUnlocked(logPath, 10_000);
400402
await readNewLogContent();
401403

402404
try {

0 commit comments

Comments
 (0)