feat: remove NWScript compiler support
This commit is contained in:
@@ -1028,205 +1028,6 @@ func TestBuildSplitsConfiguredHAKs(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildModuleCompilesReferencedScripts(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
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, ".nwn-assets"))
|
||||
mustMkdir(t, filepath.Join(root, "build"))
|
||||
|
||||
mustWriteFile(t, filepath.Join(root, "nwn-tool.json"), `{
|
||||
"module": {
|
||||
"name": "Test Module",
|
||||
"resref": "testmod"
|
||||
},
|
||||
"paths": {
|
||||
"source": "src",
|
||||
"assets": ".nwn-assets",
|
||||
"build": "build"
|
||||
}
|
||||
}
|
||||
`)
|
||||
|
||||
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"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
`)
|
||||
|
||||
mustWriteFile(t, filepath.Join(root, "src", "placeables", "thing.utp.json"), `{
|
||||
"file_type": "UTP ",
|
||||
"file_version": "V3.2",
|
||||
"root": {
|
||||
"struct_type": 0,
|
||||
"fields": [
|
||||
{
|
||||
"label": "OnUsed",
|
||||
"type": "ResRef",
|
||||
"value": "use_thing"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
`)
|
||||
|
||||
mustWriteFile(t, filepath.Join(root, "src", "scripts", "use_thing.nss"), `void main() {}`)
|
||||
|
||||
compiler := filepath.Join(root, "fake-compiler.sh")
|
||||
mustWriteFile(t, compiler, `#!/bin/sh
|
||||
set -eu
|
||||
if [ "${1:-}" = "--help" ]; then
|
||||
exit 0
|
||||
fi
|
||||
out=""
|
||||
src=""
|
||||
while [ "$#" -gt 0 ]; do
|
||||
case "$1" in
|
||||
-o)
|
||||
out="$2"
|
||||
shift 2
|
||||
;;
|
||||
--dirs)
|
||||
shift 2
|
||||
;;
|
||||
*)
|
||||
src="$1"
|
||||
shift
|
||||
;;
|
||||
esac
|
||||
done
|
||||
[ -n "$out" ]
|
||||
[ -n "$src" ]
|
||||
printf 'compiled:%s\nNWN_ROOT=%s\nNWN_HOME=%s\nNWN_USER_DIRECTORY=%s\n' "$(basename "$src")" "${NWN_ROOT-}" "${NWN_HOME-}" "${NWN_USER_DIRECTORY-}" > "$out"
|
||||
`)
|
||||
if err := os.Chmod(compiler, 0o755); err != nil {
|
||||
t.Fatalf("chmod fake compiler: %v", err)
|
||||
}
|
||||
t.Setenv("SOW_NWN_SCRIPT_COMPILER", compiler)
|
||||
installRoot := filepath.Join(root, "nwn-install")
|
||||
mustMkdir(t, filepath.Join(installRoot, "data"))
|
||||
t.Setenv("SOW_NWN_ROOT", installRoot)
|
||||
userDir := filepath.Join(root, "nwn-user")
|
||||
t.Setenv("SOW_NWN_USER_DIRECTORY", userDir)
|
||||
|
||||
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 := BuildModule(p)
|
||||
if err != nil {
|
||||
t.Fatalf("build module: %v", err)
|
||||
}
|
||||
if result.Resources != 4 {
|
||||
t.Fatalf("expected 4 resources, got %d", result.Resources)
|
||||
}
|
||||
|
||||
fh, err := os.Open(result.ModulePath)
|
||||
if err != nil {
|
||||
t.Fatalf("open built module: %v", err)
|
||||
}
|
||||
defer fh.Close()
|
||||
archive, err := erf.Read(fh)
|
||||
if err != nil {
|
||||
t.Fatalf("read built module: %v", err)
|
||||
}
|
||||
|
||||
foundSource := false
|
||||
foundCompiled := false
|
||||
for _, resource := range archive.Resources {
|
||||
if resource.Name != "use_thing" {
|
||||
continue
|
||||
}
|
||||
if extension, ok := erf.ExtensionForResourceType(resource.Type); ok {
|
||||
switch extension {
|
||||
case "nss":
|
||||
foundSource = true
|
||||
case "ncs":
|
||||
foundCompiled = true
|
||||
if !strings.Contains(string(resource.Data), "compiled:use_thing.nss") {
|
||||
t.Fatalf("unexpected compiled payload: %q", string(resource.Data))
|
||||
}
|
||||
if !strings.Contains(string(resource.Data), "NWN_ROOT="+installRoot) {
|
||||
t.Fatalf("compiled payload missing NWN_ROOT: %q", string(resource.Data))
|
||||
}
|
||||
if !strings.Contains(string(resource.Data), "NWN_HOME="+userDir) {
|
||||
t.Fatalf("compiled payload missing NWN_HOME: %q", string(resource.Data))
|
||||
}
|
||||
if !strings.Contains(string(resource.Data), "NWN_USER_DIRECTORY="+userDir) {
|
||||
t.Fatalf("compiled payload missing NWN_USER_DIRECTORY: %q", string(resource.Data))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if !foundSource {
|
||||
t.Fatalf("expected source script resource in archive")
|
||||
}
|
||||
if !foundCompiled {
|
||||
t.Fatalf("expected compiled script resource in archive")
|
||||
}
|
||||
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 {
|
||||
t.Fatalf("compare: %v", err)
|
||||
}
|
||||
if compareResult.Checked != 4 {
|
||||
t.Fatalf("expected 4 compared resources, got %d", compareResult.Checked)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseSteamLibraryFolders(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
vdf := filepath.Join(root, "libraryfolders.vdf")
|
||||
mustWriteFile(t, vdf, `"libraryfolders"
|
||||
{
|
||||
"0"
|
||||
{
|
||||
"path" "/mnt/games/Steam"
|
||||
}
|
||||
"1" "D:\\SteamLibrary"
|
||||
}
|
||||
`)
|
||||
|
||||
got := parseSteamLibraryFolders(vdf)
|
||||
if len(got) != 2 {
|
||||
t.Fatalf("expected 2 library roots, got %d (%v)", len(got), got)
|
||||
}
|
||||
if got[0] != filepath.Clean("/mnt/games/Steam") {
|
||||
t.Fatalf("unexpected first library root: %q", got[0])
|
||||
}
|
||||
if got[1] != filepath.Clean(`D:\SteamLibrary`) {
|
||||
t.Fatalf("unexpected second library root: %q", got[1])
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildBuildsTopPackageAndInjectsHAKList(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
mustMkdir(t, filepath.Join(root, "src", "module"))
|
||||
@@ -1344,118 +1145,6 @@ func TestBuildBuildsTopPackageAndInjectsHAKList(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildModuleSkipsReferencedScriptCompilationWhenRequested(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
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, ".nwn-assets"))
|
||||
mustMkdir(t, filepath.Join(root, "build"))
|
||||
|
||||
mustWriteFile(t, filepath.Join(root, "nwn-tool.json"), `{
|
||||
"module": {
|
||||
"name": "Test Module",
|
||||
"resref": "testmod"
|
||||
},
|
||||
"paths": {
|
||||
"source": "src",
|
||||
"assets": ".nwn-assets",
|
||||
"build": "build"
|
||||
}
|
||||
}
|
||||
`)
|
||||
|
||||
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"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
`)
|
||||
|
||||
mustWriteFile(t, filepath.Join(root, "src", "placeables", "thing.utp.json"), `{
|
||||
"file_type": "UTP ",
|
||||
"file_version": "V3.2",
|
||||
"root": {
|
||||
"struct_type": 0,
|
||||
"fields": [
|
||||
{
|
||||
"label": "OnUsed",
|
||||
"type": "ResRef",
|
||||
"value": "use_thing"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
`)
|
||||
|
||||
mustWriteFile(t, filepath.Join(root, "src", "scripts", "use_thing.nss"), `void main() {}`)
|
||||
t.Setenv("SOW_MODULE_SKIP_NSS_COMPILATION", "1")
|
||||
|
||||
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 := BuildModule(p)
|
||||
if err != nil {
|
||||
t.Fatalf("build module: %v", err)
|
||||
}
|
||||
if result.Resources != 3 {
|
||||
t.Fatalf("expected 3 resources without compiled script, got %d", result.Resources)
|
||||
}
|
||||
|
||||
fh, err := os.Open(result.ModulePath)
|
||||
if err != nil {
|
||||
t.Fatalf("open built module: %v", err)
|
||||
}
|
||||
defer fh.Close()
|
||||
archive, err := erf.Read(fh)
|
||||
if err != nil {
|
||||
t.Fatalf("read built module: %v", err)
|
||||
}
|
||||
|
||||
foundSource := false
|
||||
foundCompiled := false
|
||||
for _, resource := range archive.Resources {
|
||||
if resource.Name != "use_thing" {
|
||||
continue
|
||||
}
|
||||
if extension, ok := erf.ExtensionForResourceType(resource.Type); ok {
|
||||
switch extension {
|
||||
case "nss":
|
||||
foundSource = true
|
||||
case "ncs":
|
||||
foundCompiled = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if !foundSource {
|
||||
t.Fatalf("expected source script resource in archive")
|
||||
}
|
||||
if foundCompiled {
|
||||
t.Fatalf("did not expect compiled script resource in archive")
|
||||
}
|
||||
if _, err := os.Stat(filepath.Join(root, ".cache", "ncs", "use_thing.ncs")); !os.IsNotExist(err) {
|
||||
t.Fatalf("expected no compiled script cache file, got err=%v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildModuleDoesNotCompileTopData(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
mustMkdir(t, filepath.Join(root, "src", "module"))
|
||||
|
||||
Reference in New Issue
Block a user