Pipeline Planning

This commit is contained in:
2026-04-14 01:08:38 +02:00
parent 5bd4a58bff
commit b766ff1348
3 changed files with 161 additions and 29 deletions
+66 -16
View File
@@ -145,7 +145,25 @@ func BuildHAKsWithProgress(p *project.Project, progress ProgressFunc) (BuildResu
return buildHAKs(p, progress)
}
func PlanHAKs(p *project.Project) (BuildResult, error) {
return planHAKs(p, nil)
}
func PlanHAKsWithProgress(p *project.Project, progress ProgressFunc) (BuildResult, error) {
return planHAKs(p, progress)
}
func buildHAKs(p *project.Project, progress ProgressFunc) (BuildResult, error) {
return planOrBuildHAKs(p, progress, true)
}
func planHAKs(p *project.Project, progress ProgressFunc) (BuildResult, error) {
return planOrBuildHAKs(p, progress, false)
}
func planOrBuildHAKs(p *project.Project, progress ProgressFunc, writeArchives bool) (BuildResult, error) {
preserveExistingHAKs := envBool("SOW_BUILD_HAKS_KEEP_EXISTING")
progressf(progress, "Validating project...")
if err := validateForBuild(p); err != nil {
return BuildResult{}, err
@@ -176,21 +194,48 @@ func buildHAKs(p *project.Project, progress ProgressFunc) (BuildResult, error) {
if err != nil {
return BuildResult{}, err
}
previousManifest, err := loadPreviousBuildManifest(p.BuildDir())
if err != nil {
return BuildResult{}, err
}
progressf(progress, "Reusing unchanged generated HAKs where possible...")
manifest := BuildManifest{
ModuleHAKs: moduleHakOrder,
HAKs: make([]BuildManifestHAK, 0, len(chunks)),
}
currentNames := make(map[string]struct{}, len(chunks))
for index, chunk := range chunks {
hakPath := filepath.Join(p.BuildDir(), chunk.Name+".hak")
for _, chunk := range chunks {
manifestEntry := buildManifestEntry(chunk)
currentNames[chunk.Name] = struct{}{}
manifest.HAKs = append(manifest.HAKs, manifestEntry)
}
manifestPath := filepath.Join(p.BuildDir(), "haks.json")
manifestBytes, err := json.MarshalIndent(manifest, "", " ")
if err != nil {
return BuildResult{}, fmt.Errorf("marshal hak manifest: %w", err)
}
manifestBytes = append(manifestBytes, '\n')
if !writeArchives {
progressf(progress, "Cleaning previous generated HAKs...")
if err := cleanupGeneratedHAKs(p.BuildDir(), p.Config.Module.ResRef); err != nil {
return BuildResult{}, err
}
progressf(progress, "Writing HAK manifest...")
if err := os.WriteFile(manifestPath, manifestBytes, 0o644); err != nil {
return BuildResult{}, fmt.Errorf("write hak manifest: %w", err)
}
result.Manifest = manifestPath
return result, nil
}
previousManifest, err := loadPreviousBuildManifest(p.BuildDir())
if err != nil {
return BuildResult{}, err
}
progressf(progress, "Reusing unchanged generated HAKs where possible...")
result.HAKPaths = make([]string, 0, len(chunks))
for index, chunk := range chunks {
hakPath := filepath.Join(p.BuildDir(), chunk.Name+".hak")
manifestEntry := manifest.HAKs[index]
reused, err := reuseExistingHAK(previousManifest, manifestEntry, hakPath)
if err != nil {
return BuildResult{}, err
@@ -213,20 +258,15 @@ func buildHAKs(p *project.Project, progress ProgressFunc) (BuildResult, error) {
}
result.HAKPaths = append(result.HAKPaths, hakPath)
manifest.HAKs = append(manifest.HAKs, manifestEntry)
}
progressf(progress, "Cleaning stale generated HAKs...")
if err := cleanupStaleGeneratedHAKs(p.BuildDir(), p.Config.Module.ResRef, currentNames); err != nil {
return BuildResult{}, err
if !preserveExistingHAKs {
if err := cleanupStaleGeneratedHAKs(p.BuildDir(), p.Config.Module.ResRef, currentNames); err != nil {
return BuildResult{}, err
}
}
progressf(progress, "Writing HAK manifest...")
manifestPath := filepath.Join(p.BuildDir(), "haks.json")
manifestBytes, err := json.MarshalIndent(manifest, "", " ")
if err != nil {
return BuildResult{}, fmt.Errorf("marshal hak manifest: %w", err)
}
manifestBytes = append(manifestBytes, '\n')
if err := os.WriteFile(manifestPath, manifestBytes, 0o644); err != nil {
return BuildResult{}, fmt.Errorf("write hak manifest: %w", err)
}
@@ -240,6 +280,16 @@ func progressf(progress ProgressFunc, message string) {
}
}
func envBool(name string) bool {
value := strings.TrimSpace(strings.ToLower(os.Getenv(name)))
switch value {
case "1", "true", "yes", "on":
return true
default:
return false
}
}
func collectModuleResources(p *project.Project, moduleHakOrder []string) ([]erf.Resource, error) {
var moduleResources []erf.Resource