Compile pipeline fix
This commit is contained in:
@@ -550,6 +550,10 @@ func collectModuleResources(p *project.Project, moduleHakOrder []string) ([]erf.
|
|||||||
}
|
}
|
||||||
|
|
||||||
func compileReferencedScripts(p *project.Project) ([]erf.Resource, error) {
|
func compileReferencedScripts(p *project.Project) ([]erf.Resource, error) {
|
||||||
|
if skipNSSCompilation() {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
referenced, err := referencedScriptResrefs(p)
|
referenced, err := referencedScriptResrefs(p)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -609,6 +613,15 @@ func compileReferencedScripts(p *project.Project) ([]erf.Resource, error) {
|
|||||||
return resources, nil
|
return resources, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func skipNSSCompilation() bool {
|
||||||
|
switch strings.ToLower(strings.TrimSpace(os.Getenv("SOW_MODULE_SKIP_NSS_COMPILATION"))) {
|
||||||
|
case "1", "true", "yes", "on":
|
||||||
|
return true
|
||||||
|
default:
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func compiledScriptCacheDir(p *project.Project) string {
|
func compiledScriptCacheDir(p *project.Project) string {
|
||||||
return p.ScriptCacheDir()
|
return p.ScriptCacheDir()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1286,6 +1286,118 @@ 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) {
|
func TestBuildModuleDoesNotCompileTopData(t *testing.T) {
|
||||||
root := t.TempDir()
|
root := t.TempDir()
|
||||||
mustMkdir(t, filepath.Join(root, "src", "module"))
|
mustMkdir(t, filepath.Join(root, "src", "module"))
|
||||||
|
|||||||
Reference in New Issue
Block a user