Build in /tmp and immediately discard

This commit is contained in:
2026-04-14 09:49:36 +02:00
parent b766ff1348
commit bf7c844f2e
3 changed files with 158 additions and 6 deletions
+82 -1
View File
@@ -3,6 +3,7 @@ package pipeline
import (
"bytes"
"encoding/json"
"errors"
"os"
"os/exec"
"path/filepath"
@@ -935,7 +936,6 @@ func TestBuildSplitsMultipleHAKGroupsDeterministically(t *testing.T) {
}
]
}
`)
mustWriteFile(t, filepath.Join(root, "src", "module", "module.ifo.json"), `{
"file_type": "IFO ",
@@ -1039,6 +1039,87 @@ func TestBuildSplitsMultipleHAKGroupsDeterministically(t *testing.T) {
}
}
func TestBuildHAKsWithOptionsBuildsSingleArchiveByName(t *testing.T) {
root := t.TempDir()
mustMkdir(t, filepath.Join(root, "src"))
mustMkdir(t, filepath.Join(root, "src", "module"))
mustMkdir(t, filepath.Join(root, "assets", "core"))
mustMkdir(t, filepath.Join(root, "build"))
mustWriteFile(t, filepath.Join(root, "nwn-tool.json"), `{
"module": {
"name": "Test Module",
"resref": "testmod"
},
"paths": {
"source": "src",
"assets": "assets",
"build": "build"
},
"haks": [
{
"name": "core",
"priority": 1,
"max_bytes": 310,
"split": true,
"include": ["core/**"]
}
]
}
`)
mustWriteFile(t, filepath.Join(root, "src", "module", "module.ifo.json"), `{
"file_type": "IFO ",
"file_version": "V3.2",
"root": {
"struct_type": 0,
"fields": [
{
"label": "Mod_Name",
"type": "CExoString",
"value": "Test Module"
},
{
"label": "Mod_HakList",
"type": "List",
"value": []
}
]
}
}
`)
mustWriteFile(t, filepath.Join(root, "assets", "core", "a.tga"), strings.Repeat("a", 80))
mustWriteFile(t, filepath.Join(root, "assets", "core", "b.tga"), strings.Repeat("b", 80))
mustWriteFile(t, filepath.Join(root, "assets", "core", "c.tga"), strings.Repeat("c", 80))
p, err := project.Load(root)
if err != nil {
t.Fatalf("load project: %v", err)
}
if err := p.ValidateLayout(); err != nil {
t.Fatalf("validate layout: %v", err)
}
if err := p.Scan(); err != nil {
t.Fatalf("scan: %v", err)
}
result, err := BuildHAKsWithOptions(p, BuildHAKOptions{ArchiveNames: []string{"core_02"}})
if err != nil {
t.Fatalf("build filtered haks: %v", err)
}
if len(result.HAKPaths) != 1 {
t.Fatalf("expected 1 hak output, got %d", len(result.HAKPaths))
}
if got := filepath.Base(result.HAKPaths[0]); got != "core_02.hak" {
t.Fatalf("unexpected hak output %q", got)
}
if _, err := os.Stat(filepath.Join(root, "build", "core_01.hak")); !errors.Is(err, os.ErrNotExist) {
t.Fatalf("expected core_01.hak to be absent, got err=%v", err)
}
if _, err := os.Stat(filepath.Join(root, "build", "core.hak")); !errors.Is(err, os.ErrNotExist) {
t.Fatalf("expected unsplit core.hak to be absent, got err=%v", err)
}
}
func TestBuildExcludesOptionalHAKsFromModuleOrder(t *testing.T) {
root := t.TempDir()
mustMkdir(t, filepath.Join(root, "src"))