Skip to content

Commit 8736559

Browse files
unity-cli@v1.3.3 (#31)
- throw an error if android sdk installation is not ran in elevated terminal - remove inherited env from android sdk processes
1 parent 37b66b8 commit 8736559

5 files changed

Lines changed: 33 additions & 7 deletions

File tree

.github/workflows/unity-build.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ jobs:
3838
unity-cli --version
3939
- name: Setup Unity
4040
shell: bash
41+
timeout-minutes: 30
4142
run: |
4243
unity-cli hub-install --auto-update
4344
unity-cli setup-unity --unity-version "${{ matrix.unity-version }}" --build-targets "${{ matrix.build-target }}" --json

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@rage-against-the-pixel/unity-cli",
3-
"version": "1.3.2",
3+
"version": "1.3.3",
44
"description": "A command line utility for the Unity Game Engine.",
55
"author": "RageAgainstThePixel",
66
"license": "MIT",

src/android-sdk.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { spawn } from 'child_process';
55
import { Logger } from './logging';
66
import { UnityEditor } from './unity-editor';
77
import {
8+
isProcessElevated,
89
ReadFileContents,
910
ResolveGlobToPath
1011
} from './utilities';
@@ -124,10 +125,21 @@ async function execSdkManager(sdkManagerPath: string, javaPath: string, args: st
124125

125126
try {
126127
exitCode = await new Promise<number>((resolve, reject) => {
127-
const child = spawn(sdkManagerPath, args, {
128+
let cmd = sdkManagerPath;
129+
let cmdArgs = args;
130+
131+
if (process.platform === 'win32') {
132+
if (!isProcessElevated()) {
133+
throw new Error('Android SDK installation requires elevated (administrator) privileges. Please rerun as Administrator.');
134+
}
135+
136+
cmd = 'cmd.exe';
137+
cmdArgs = ['/c', sdkManagerPath, ...args];
138+
}
139+
140+
const child = spawn(cmd, cmdArgs, {
128141
stdio: ['pipe', 'pipe', 'pipe'],
129142
env: {
130-
...process.env,
131143
JAVA_HOME: process.platform === 'win32' ? `"${javaPath}"` : javaPath
132144
}
133145
});
@@ -147,7 +159,7 @@ async function execSdkManager(sdkManagerPath: string, javaPath: string, args: st
147159
function handleDataStream(data: Buffer) {
148160
const chunk = data.toString();
149161
output += chunk;
150-
process.stderr.write(chunk);
162+
process.stdout.write(chunk);
151163
}
152164
const acceptBuffer = Buffer.from(Array(10).fill('y').join(os.EOL), 'utf8');
153165
child.stdin.write(acceptBuffer);

src/utilities.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import * as path from 'path';
44
import * as https from 'https';
55
import * as readline from 'readline';
66
import { glob } from 'glob';
7-
import { spawn } from 'child_process';
7+
import { spawn, spawnSync } from 'child_process';
88
import { Logger, LogLevel } from './logging';
99

1010
const logger = Logger.instance;
@@ -572,4 +572,17 @@ export async function KillChildProcesses(procInfo: ProcInfo): Promise<void> {
572572
} catch (error) {
573573
logger.error(`Failed to kill child processes of pid ${procInfo.pid}:\n${JSON.stringify(error)}`);
574574
}
575+
}
576+
577+
/**
578+
* Checks if the current process is running with elevated (administrator) privileges.
579+
* @returns True if the process is elevated, false otherwise.
580+
*/
581+
export function isProcessElevated(): boolean {
582+
if (process.platform !== 'win32') { return true; } // We can sudo easily on non-windows platforms
583+
const probe = spawnSync('powershell.exe', [
584+
'-NoLogo', '-NoProfile', '-Command',
585+
"[Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent().IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)"
586+
], { encoding: 'utf8' });
587+
return probe.status === 0 && probe.stdout.trim().toLowerCase() === 'true';
575588
}

0 commit comments

Comments
 (0)