Refactor build and topdata path resolution through project config
This commit is contained in:
+17
-18
@@ -133,7 +133,7 @@ func buildModule(p *project.Project, progress ProgressFunc) (BuildResult, error)
|
||||
}
|
||||
|
||||
progressf(progress, "Writing module archive...")
|
||||
outputPath := filepath.Join(p.BuildDir(), p.Config.Module.ResRef+".mod")
|
||||
outputPath := p.ModuleArchivePath()
|
||||
output, err := os.Create(outputPath)
|
||||
if err != nil {
|
||||
return BuildResult{}, fmt.Errorf("create module archive: %w", err)
|
||||
@@ -197,7 +197,7 @@ func planOrBuildHAKs(p *project.Project, progress ProgressFunc, writeArchives bo
|
||||
}
|
||||
var previousManifest *BuildManifest
|
||||
if sourceManifest == nil || writeArchives {
|
||||
previousManifest, err = loadPreviousBuildManifest(p.BuildDir())
|
||||
previousManifest, err = loadPreviousBuildManifest(p.HAKManifestPath())
|
||||
if err != nil {
|
||||
return BuildResult{}, err
|
||||
}
|
||||
@@ -206,7 +206,7 @@ func planOrBuildHAKs(p *project.Project, progress ProgressFunc, writeArchives bo
|
||||
result := BuildResult{HAKAssets: len(assetResources)}
|
||||
if len(assetResources) == 0 {
|
||||
progressf(progress, "Cleaning previous generated HAKs...")
|
||||
if err := cleanupGeneratedHAKs(p.BuildDir(), p.Config.Module.ResRef); err != nil {
|
||||
if err := cleanupGeneratedHAKs(p); err != nil {
|
||||
return BuildResult{}, err
|
||||
}
|
||||
return result, nil
|
||||
@@ -254,7 +254,7 @@ func planOrBuildHAKs(p *project.Project, progress ProgressFunc, writeArchives bo
|
||||
manifest.HAKs = append(manifest.HAKs, manifestEntry)
|
||||
}
|
||||
|
||||
manifestPath := filepath.Join(p.BuildDir(), "haks.json")
|
||||
manifestPath := p.HAKManifestPath()
|
||||
manifestBytes, err := json.MarshalIndent(manifest, "", " ")
|
||||
if err != nil {
|
||||
return BuildResult{}, fmt.Errorf("marshal hak manifest: %w", err)
|
||||
@@ -263,7 +263,7 @@ func planOrBuildHAKs(p *project.Project, progress ProgressFunc, writeArchives bo
|
||||
|
||||
if !writeArchives {
|
||||
progressf(progress, "Cleaning previous generated HAKs...")
|
||||
if err := cleanupGeneratedHAKs(p.BuildDir(), p.Config.Module.ResRef); err != nil {
|
||||
if err := cleanupGeneratedHAKs(p); err != nil {
|
||||
return BuildResult{}, err
|
||||
}
|
||||
progressf(progress, "Writing HAK manifest...")
|
||||
@@ -278,7 +278,7 @@ func planOrBuildHAKs(p *project.Project, progress ProgressFunc, writeArchives bo
|
||||
|
||||
result.HAKPaths = make([]string, 0, len(chunks))
|
||||
for index, chunk := range chunks {
|
||||
hakPath := filepath.Join(p.BuildDir(), chunk.Name+".hak")
|
||||
hakPath := p.HAKArchivePath(chunk.Name)
|
||||
manifestEntry := manifest.HAKs[index]
|
||||
reused, err := reuseExistingHAK(previousManifest, manifestEntry, hakPath)
|
||||
if err != nil {
|
||||
@@ -305,7 +305,7 @@ func planOrBuildHAKs(p *project.Project, progress ProgressFunc, writeArchives bo
|
||||
}
|
||||
progressf(progress, "Cleaning stale generated HAKs...")
|
||||
if !preserveExistingHAKs {
|
||||
if err := cleanupStaleGeneratedHAKs(p.BuildDir(), p.Config.Module.ResRef, currentNames); err != nil {
|
||||
if err := cleanupStaleGeneratedHAKs(p, currentNames); err != nil {
|
||||
return BuildResult{}, err
|
||||
}
|
||||
}
|
||||
@@ -1427,8 +1427,7 @@ func chunkContentHash(chunk hakChunk) string {
|
||||
return fmt.Sprintf("%x", sum.Sum(nil))
|
||||
}
|
||||
|
||||
func loadPreviousBuildManifest(buildDir string) (*BuildManifest, error) {
|
||||
manifestPath := filepath.Join(buildDir, "haks.json")
|
||||
func loadPreviousBuildManifest(manifestPath string) (*BuildManifest, error) {
|
||||
raw, err := os.ReadFile(manifestPath)
|
||||
if err != nil {
|
||||
if errors.Is(err, os.ErrNotExist) {
|
||||
@@ -1475,8 +1474,8 @@ func reuseExistingHAK(previousManifest *BuildManifest, current BuildManifestHAK,
|
||||
return true, nil
|
||||
}
|
||||
|
||||
func cleanupStaleGeneratedHAKs(buildDir, moduleResRef string, keepNames map[string]struct{}) error {
|
||||
paths, err := manifestHAKPaths(buildDir)
|
||||
func cleanupStaleGeneratedHAKs(p *project.Project, keepNames map[string]struct{}) error {
|
||||
paths, err := manifestHAKPaths(p)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -1490,8 +1489,8 @@ func cleanupStaleGeneratedHAKs(buildDir, moduleResRef string, keepNames map[stri
|
||||
}
|
||||
}
|
||||
|
||||
legacy := filepath.Join(buildDir, moduleResRef+".hak")
|
||||
if _, keep := keepNames[moduleResRef]; !keep {
|
||||
legacy := p.HAKArchivePath(p.Config.Module.ResRef)
|
||||
if _, keep := keepNames[p.Config.Module.ResRef]; !keep {
|
||||
if err := os.Remove(legacy); err != nil && !errors.Is(err, os.ErrNotExist) {
|
||||
return fmt.Errorf("remove legacy generated hak %s: %w", legacy, err)
|
||||
}
|
||||
@@ -1514,8 +1513,8 @@ func matchPathPattern(path, pattern string) bool {
|
||||
return matchSegments(pathSegs, patternSegs)
|
||||
}
|
||||
|
||||
func cleanupGeneratedHAKs(buildDir, moduleResRef string) error {
|
||||
paths, err := manifestHAKPaths(buildDir)
|
||||
func cleanupGeneratedHAKs(p *project.Project) error {
|
||||
paths, err := manifestHAKPaths(p)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -1525,12 +1524,12 @@ func cleanupGeneratedHAKs(buildDir, moduleResRef string) error {
|
||||
}
|
||||
}
|
||||
|
||||
legacy := filepath.Join(buildDir, moduleResRef+".hak")
|
||||
legacy := p.HAKArchivePath(p.Config.Module.ResRef)
|
||||
if err := os.Remove(legacy); err != nil && !errors.Is(err, os.ErrNotExist) {
|
||||
return fmt.Errorf("remove legacy generated hak %s: %w", legacy, err)
|
||||
}
|
||||
|
||||
manifest := filepath.Join(buildDir, "haks.json")
|
||||
manifest := p.HAKManifestPath()
|
||||
if err := os.Remove(manifest); err != nil && !errors.Is(err, os.ErrNotExist) {
|
||||
return fmt.Errorf("remove previous hak manifest: %w", err)
|
||||
}
|
||||
@@ -1538,7 +1537,7 @@ func cleanupGeneratedHAKs(buildDir, moduleResRef string) error {
|
||||
}
|
||||
|
||||
func plannedModuleHAKOrder(p *project.Project) ([]string, error) {
|
||||
manifest, err := loadPreviousBuildManifest(p.BuildDir())
|
||||
manifest, err := loadPreviousBuildManifest(p.HAKManifestPath())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user