Move Generation Destinations

This commit is contained in:
2026-04-18 10:24:34 +02:00
parent 897776f432
commit 6f6bf7080a
10 changed files with 166 additions and 91 deletions
+11 -5
View File
@@ -467,11 +467,13 @@ func compileReferencedScripts(p *project.Project) ([]erf.Resource, error) {
return nil, err
}
tmpDir, err := os.MkdirTemp("", "sow-script-compile-*")
if err != nil {
return nil, fmt.Errorf("create script compiler temp dir: %w", err)
cacheDir := compiledScriptCacheDir(p)
if err := os.RemoveAll(cacheDir); err != nil {
return nil, fmt.Errorf("clear script compiler cache dir: %w", err)
}
if err := os.MkdirAll(cacheDir, 0o755); err != nil {
return nil, fmt.Errorf("create script compiler cache dir: %w", err)
}
defer os.RemoveAll(tmpDir)
resources := make([]erf.Resource, 0, len(referenced))
scriptsDir := filepath.Join(p.SourceDir(), "scripts")
@@ -480,7 +482,7 @@ func compileReferencedScripts(p *project.Project) ([]erf.Resource, error) {
if !ok {
continue
}
outputPath := filepath.Join(tmpDir, resref+".ncs")
outputPath := filepath.Join(cacheDir, resref+".ncs")
cmd := exec.Command(compiler, "--dirs", scriptsDir, "-o", outputPath, sourcePath)
cmd.Env = compilerEnv
output, err := cmd.CombinedOutput()
@@ -501,6 +503,10 @@ func compileReferencedScripts(p *project.Project) ([]erf.Resource, error) {
return resources, nil
}
func compiledScriptCacheDir(p *project.Project) string {
return filepath.Join(p.Root, ".cache", "ncs")
}
func referencedScriptResrefs(p *project.Project) ([]string, error) {
referenced := map[string]struct{}{}
for _, rel := range p.Inventory.SourceFiles {
+8 -2
View File
@@ -289,7 +289,7 @@ func TestBuildModuleCompilesReferencedScripts(t *testing.T) {
mustMkdir(t, filepath.Join(root, "src", "module"))
mustMkdir(t, filepath.Join(root, "src", "placeables"))
mustMkdir(t, filepath.Join(root, "src", "scripts"))
mustMkdir(t, filepath.Join(root, "assets"))
mustMkdir(t, filepath.Join(root, ".nwn-assets"))
mustMkdir(t, filepath.Join(root, "build"))
mustWriteFile(t, filepath.Join(root, "nwn-tool.json"), `{
@@ -299,7 +299,7 @@ func TestBuildModuleCompilesReferencedScripts(t *testing.T) {
},
"paths": {
"source": "src",
"assets": "assets",
"assets": ".nwn-assets",
"build": "build"
}
}
@@ -439,6 +439,12 @@ printf 'compiled:%s\nNWN_ROOT=%s\nNWN_HOME=%s\nNWN_USER_DIRECTORY=%s\n' "$(basen
if _, err := os.Stat(userDir); err != nil {
t.Fatalf("expected build to prepare NWN user directory: %v", err)
}
if _, err := os.Stat(filepath.Join(root, ".cache", "ncs", "use_thing.ncs")); err != nil {
t.Fatalf("expected compiled script in .cache/ncs: %v", err)
}
if _, err := os.Stat(filepath.Join(root, ".nwn-assets", "ncs", "use_thing.ncs")); !os.IsNotExist(err) {
t.Fatalf("expected no compiled script in .nwn-assets/ncs, got err=%v", err)
}
compareResult, err := Compare(p)
if err != nil {