mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-21 10:34:35 -07:00
Build binary (#18933)
Co-authored-by: Gal Zahavi <38544478+galz10@users.noreply.github.com>
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import { spawn } from 'node:child_process';
|
||||
import { spawn, execSync } from 'node:child_process';
|
||||
import type {
|
||||
HookConfig,
|
||||
CommandHookConfig,
|
||||
@@ -331,12 +331,17 @@ export class HookRunner {
|
||||
let timedOut = false;
|
||||
|
||||
const shellConfig = getShellConfiguration();
|
||||
const command = this.expandCommand(
|
||||
let command = this.expandCommand(
|
||||
hookConfig.command,
|
||||
input,
|
||||
shellConfig.shell,
|
||||
);
|
||||
|
||||
if (shellConfig.shell === 'powershell') {
|
||||
// Append exit code check to ensure the exit code of the command is propagated
|
||||
command = `${command}; if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }`;
|
||||
}
|
||||
|
||||
// Set up environment variables
|
||||
const env = {
|
||||
...sanitizeEnvironment(process.env, this.config.sanitizationConfig),
|
||||
@@ -359,12 +364,31 @@ export class HookRunner {
|
||||
// Set up timeout
|
||||
const timeoutHandle = setTimeout(() => {
|
||||
timedOut = true;
|
||||
child.kill('SIGTERM');
|
||||
|
||||
if (process.platform === 'win32' && child.pid) {
|
||||
try {
|
||||
execSync(`taskkill /pid ${child.pid} /f /t`, { timeout: 2000 });
|
||||
} catch (_e) {
|
||||
// Ignore errors if process is already dead or access denied
|
||||
debugLogger.debug(`Taskkill failed: ${_e}`);
|
||||
}
|
||||
} else {
|
||||
child.kill('SIGTERM');
|
||||
}
|
||||
|
||||
// Force kill after 5 seconds
|
||||
setTimeout(() => {
|
||||
if (!child.killed) {
|
||||
child.kill('SIGKILL');
|
||||
if (process.platform === 'win32' && child.pid) {
|
||||
try {
|
||||
execSync(`taskkill /pid ${child.pid} /f /t`, { timeout: 2000 });
|
||||
} catch (_e) {
|
||||
// Ignore
|
||||
debugLogger.debug(`Taskkill failed: ${_e}`);
|
||||
}
|
||||
} else {
|
||||
child.kill('SIGKILL');
|
||||
}
|
||||
}
|
||||
}, 5000);
|
||||
}, timeout);
|
||||
|
||||
@@ -74,16 +74,41 @@ async function main() {
|
||||
});
|
||||
|
||||
if (zipProcess.error || zipProcess.status !== 0) {
|
||||
// Fallback to tar --format=zip if zip is not available (common on Windows)
|
||||
console.log('zip command not found, falling back to tar...');
|
||||
zipProcess = spawnSync(
|
||||
'tar',
|
||||
['-a', '-c', '--format=zip', '-f', outputFilename, '.'],
|
||||
{
|
||||
cwd: skillPath,
|
||||
stdio: 'inherit',
|
||||
},
|
||||
);
|
||||
if (process.platform === 'win32') {
|
||||
// Fallback to PowerShell Compress-Archive on Windows
|
||||
// Note: Compress-Archive only supports .zip extension, so we zip to .zip and rename
|
||||
console.log('zip command not found, falling back to PowerShell...');
|
||||
const tempZip = outputFilename + '.zip';
|
||||
// Escape single quotes for PowerShell (replace ' with '') and use single quotes for the path
|
||||
const safeTempZip = tempZip.replace(/'/g, "''");
|
||||
zipProcess = spawnSync(
|
||||
'powershell.exe',
|
||||
[
|
||||
'-NoProfile',
|
||||
'-Command',
|
||||
`Compress-Archive -Path .\\* -DestinationPath '${safeTempZip}' -Force`,
|
||||
],
|
||||
{
|
||||
cwd: skillPath,
|
||||
stdio: 'inherit',
|
||||
},
|
||||
);
|
||||
|
||||
if (zipProcess.status === 0 && require('node:fs').existsSync(tempZip)) {
|
||||
require('node:fs').renameSync(tempZip, outputFilename);
|
||||
}
|
||||
} else {
|
||||
// Fallback to tar on Unix-like systems
|
||||
console.log('zip command not found, falling back to tar...');
|
||||
zipProcess = spawnSync(
|
||||
'tar',
|
||||
['-a', '-c', '--format=zip', '-f', outputFilename, '.'],
|
||||
{
|
||||
cwd: skillPath,
|
||||
stdio: 'inherit',
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (zipProcess.error) {
|
||||
|
||||
Reference in New Issue
Block a user