From 5e900d00b59f854fbd846a76975a4ac441766f1e Mon Sep 17 00:00:00 2001 From: vickydotbat Date: Sat, 18 Apr 2026 10:34:18 +0200 Subject: [PATCH] Flatten Cache Folder --- internal/app/app.go | 4 ++-- internal/project/project.go | 2 +- internal/topdata/parts_manifest.go | 2 +- internal/topdata/top_package.go | 16 +++++++++++++++- internal/topdata/topdata_test.go | 8 ++++---- internal/topdata/wiki_native_test.go | 16 ++++++++-------- 6 files changed, 31 insertions(+), 17 deletions(-) diff --git a/internal/app/app.go b/internal/app/app.go index 0ca8844..3a4d841 100644 --- a/internal/app/app.go +++ b/internal/app/app.go @@ -70,12 +70,12 @@ var commands = []command{ }, { name: "build-topdata", - description: "Build canonical topdata outputs into .cache/topdata, then package sow_top.hak and sow_tlk.tlk.", + description: "Build canonical topdata outputs into .cache/2da and .cache/wiki, then refresh build/sow_top.hak and build/sow_tlk.tlk.", run: runBuildTopData, }, { name: "build-top-package", - description: "Build sow_top.hak and sow_tlk.tlk from cached native topdata output and authored topdata/assets.", + description: "Build build/sow_top.hak and build/sow_tlk.tlk from cached native topdata output and authored topdata/assets.", run: runBuildTopPackage, }, { diff --git a/internal/project/project.go b/internal/project/project.go index 2e157ef..f966c69 100644 --- a/internal/project/project.go +++ b/internal/project/project.go @@ -349,7 +349,7 @@ func defaultConfig() Config { Build: "build", }, TopData: TopDataConfig{ - Build: ".cache/topdata", + Build: ".cache", }, } } diff --git a/internal/topdata/parts_manifest.go b/internal/topdata/parts_manifest.go index c3bac44..2297f66 100644 --- a/internal/topdata/parts_manifest.go +++ b/internal/topdata/parts_manifest.go @@ -45,7 +45,7 @@ func resolveReleasedPartsManifest(p *project.Project, progress func(string)) (ma if progress == nil { progress = func(string) {} } - cachePath := filepath.Join(p.Root, ".cache", "topdata", partsManifestCacheFileName) + cachePath := filepath.Join(p.Root, ".cache", partsManifestCacheFileName) if strings.TrimSpace(os.Getenv("SOW_PARTS_MANIFEST_REFRESH")) == "" { manifest, fresh, err := readFreshPartsManifestCache(cachePath, partsManifestCacheMaxAge) if err != nil { diff --git a/internal/topdata/top_package.go b/internal/topdata/top_package.go index 71d8fc3..de54653 100644 --- a/internal/topdata/top_package.go +++ b/internal/topdata/top_package.go @@ -25,8 +25,19 @@ func compiled2DAOutputDir(p *project.Project) string { return filepath.Join(p.TopDataBuildDir(), "2da") } +func defaultTopDataCacheDir(p *project.Project) string { + return filepath.Join(p.Root, ".cache") +} + +func topDataBuildUsesRepoCache(p *project.Project) bool { + return samePath(p.TopDataBuildDir(), defaultTopDataCacheDir(p)) +} + func compiledTLKOutputPath(p *project.Project) string { - return filepath.Join(p.TopDataBuildDir(), "tlk", defaultTLKName) + if topDataBuildUsesRepoCache(p) { + return filepath.Join(p.BuildDir(), defaultTLKName) + } + return filepath.Join(p.TopDataBuildDir(), defaultTLKName) } func compiledTLKOutputDir(p *project.Project) string { @@ -34,6 +45,9 @@ func compiledTLKOutputDir(p *project.Project) string { } func wikiOutputRootDir(p *project.Project) string { + if topDataBuildUsesRepoCache(p) { + return filepath.Join(defaultTopDataCacheDir(p), wikiRootDirName) + } return filepath.Join(p.TopDataBuildDir(), wikiRootDirName) } diff --git a/internal/topdata/topdata_test.go b/internal/topdata/topdata_test.go index 073c8b3..699fca6 100644 --- a/internal/topdata/topdata_test.go +++ b/internal/topdata/topdata_test.go @@ -4030,7 +4030,7 @@ func TestBuildNativeRemovesStaleTopdataOutputs(t *testing.T) { if err != nil { t.Fatalf("BuildNative failed: %v", err) } - if got, want := result.Output2DADir, filepath.Join(root, ".cache", "topdata", "2da"); got != want { + if got, want := result.Output2DADir, filepath.Join(root, ".cache", "2da"); got != want { t.Fatalf("unexpected cached 2da output dir: got %q want %q", got, want) } if _, err := os.Stat(filepath.Join(result.Output2DADir, "stale.2da")); !os.IsNotExist(err) { @@ -4056,10 +4056,10 @@ func TestBuildNativeWritesCompiledOutputsToCache(t *testing.T) { if err != nil { t.Fatalf("BuildNative failed: %v", err) } - if got, want := result.Output2DADir, filepath.Join(root, ".cache", "topdata", "2da"); got != want { + if got, want := result.Output2DADir, filepath.Join(root, ".cache", "2da"); got != want { t.Fatalf("unexpected 2da output dir: got %q want %q", got, want) } - if got, want := result.OutputTLKDir, filepath.Join(root, ".cache", "topdata", "tlk"); got != want { + if got, want := result.OutputTLKDir, filepath.Join(root, "build"); got != want { t.Fatalf("unexpected tlk output dir: got %q want %q", got, want) } if _, err := os.Stat(filepath.Join(result.Output2DADir, "repadjust.2da")); err != nil { @@ -9525,7 +9525,7 @@ func testProject(root string) *project.Project { Paths: project.PathConfig{Source: "src", Assets: "assets", Build: "build"}, TopData: project.TopDataConfig{ Source: "topdata", - Build: ".cache/topdata", + Build: ".cache", ReferenceBuilder: "reference", Assets: ".", }, diff --git a/internal/topdata/wiki_native_test.go b/internal/topdata/wiki_native_test.go index b5d5e74..5f67962 100644 --- a/internal/topdata/wiki_native_test.go +++ b/internal/topdata/wiki_native_test.go @@ -42,7 +42,7 @@ func TestBuildNativeGeneratesAndSkipsWikiPages(t *testing.T) { if result.WikiPages != 1 { t.Fatalf("expected one generated entity page, got %d", result.WikiPages) } - pagePath := filepath.Join(root, ".cache", "topdata", "wiki", "pages", "skills", "athletics.txt") + pagePath := filepath.Join(root, ".cache", "wiki", "pages", "skills", "athletics.txt") got, err := os.ReadFile(pagePath) if err != nil { t.Fatalf("read generated page: %v", err) @@ -54,7 +54,7 @@ func TestBuildNativeGeneratesAndSkipsWikiPages(t *testing.T) { if !strings.Contains(text, "Ability: Strength.") || !strings.Contains(text, " * Climb") { t.Fatalf("expected description to be rendered into wiki page:\n%s", text) } - statusPath := filepath.Join(root, ".cache", "topdata", "wiki", "pages", "meta", "wikistatus.txt") + statusPath := filepath.Join(root, ".cache", "wiki", "pages", "meta", "wikistatus.txt") statusRaw, err := os.ReadFile(statusPath) if err != nil { t.Fatalf("read status page: %v", err) @@ -62,10 +62,10 @@ func TestBuildNativeGeneratesAndSkipsWikiPages(t *testing.T) { if !strings.Contains(string(statusRaw), "**Vanilla:** 1\\\\") { t.Fatalf("expected wiki status summary to count vanilla page:\n%s", string(statusRaw)) } - if _, err := os.Stat(filepath.Join(root, ".cache", "topdata", "wiki", "state.json")); err != nil { + if _, err := os.Stat(filepath.Join(root, ".cache", "wiki", "state.json")); err != nil { t.Fatalf("expected state file after first build: %v", err) } - stateBefore, err := loadWikiState(filepath.Join(root, ".cache", "topdata", "wiki", "state.json")) + stateBefore, err := loadWikiState(filepath.Join(root, ".cache", "wiki", "state.json")) if err != nil { t.Fatalf("read state before second build: %v", err) } @@ -120,7 +120,7 @@ func TestBuildAndPackageBuildsWikiOnlyWhenRequested(t *testing.T) { if result.WikiOutputDir != "" || result.WikiPages != 0 { t.Fatalf("expected wiki generation to be skipped by default, got dir=%q pages=%d", result.WikiOutputDir, result.WikiPages) } - if _, err := os.Stat(filepath.Join(root, ".cache", "topdata", "wiki", "state.json")); !os.IsNotExist(err) { + if _, err := os.Stat(filepath.Join(root, ".cache", "wiki", "state.json")); !os.IsNotExist(err) { t.Fatalf("expected no wiki state without explicit wiki build, got %v", err) } @@ -131,7 +131,7 @@ func TestBuildAndPackageBuildsWikiOnlyWhenRequested(t *testing.T) { if result.WikiPages != 1 { t.Fatalf("expected one generated wiki page when requested, got %d", result.WikiPages) } - if _, err := os.Stat(filepath.Join(root, ".cache", "topdata", "wiki", "state.json")); err != nil { + if _, err := os.Stat(filepath.Join(root, ".cache", "wiki", "state.json")); err != nil { t.Fatalf("expected wiki state after explicit wiki build: %v", err) } } @@ -189,7 +189,7 @@ func TestBuildNativeRegeneratesWikiWhenTLKTextChanges(t *testing.T) { if _, err := BuildNative(proj, nil); err != nil { t.Fatalf("BuildNative after text change failed: %v", err) } - pagePath := filepath.Join(root, ".cache", "topdata", "wiki", "pages", "skills", "athletics.txt") + pagePath := filepath.Join(root, ".cache", "wiki", "pages", "skills", "athletics.txt") got, err := os.ReadFile(pagePath) if err != nil { t.Fatalf("read regenerated page: %v", err) @@ -230,7 +230,7 @@ func TestBuildPackageIgnoresWikiSourcesForFreshness(t *testing.T) { t.Fatalf("BuildNative failed: %v", err) } - pagePath := filepath.Join(root, ".cache", "topdata", "wiki", "pages", "skills", "athletics.txt") + pagePath := filepath.Join(root, ".cache", "wiki", "pages", "skills", "athletics.txt") newTime := time.Now().Add(2 * time.Second) if err := os.Chtimes(pagePath, newTime, newTime); err != nil { t.Fatalf("touch wiki page: %v", err)