Add topdata bridge commands and handoff
This commit is contained in:
+93
-2
@@ -11,6 +11,7 @@ import (
|
||||
|
||||
"gitea.westgate.pw/ShadowsOverWestgate/sow-tools/internal/pipeline"
|
||||
"gitea.westgate.pw/ShadowsOverWestgate/sow-tools/internal/project"
|
||||
"gitea.westgate.pw/ShadowsOverWestgate/sow-tools/internal/topdata"
|
||||
"gitea.westgate.pw/ShadowsOverWestgate/sow-tools/internal/validator"
|
||||
)
|
||||
|
||||
@@ -24,6 +25,7 @@ type context struct {
|
||||
stdout io.Writer
|
||||
stderr io.Writer
|
||||
cwd string
|
||||
args []string
|
||||
}
|
||||
|
||||
var commands = []command{
|
||||
@@ -62,6 +64,21 @@ var commands = []command{
|
||||
description: "Apply a generated HAK manifest to src/module/module.ifo.json.",
|
||||
run: runApplyHAKManifest,
|
||||
},
|
||||
{
|
||||
name: "validate-topdata",
|
||||
description: "Validate topdata source layout and canonical JSON compatibility.",
|
||||
run: runValidateTopData,
|
||||
},
|
||||
{
|
||||
name: "build-topdata",
|
||||
description: "Build topdata outputs into build/topdata using the reference builder bridge.",
|
||||
run: runBuildTopData,
|
||||
},
|
||||
{
|
||||
name: "compare-topdata",
|
||||
description: "Compare built topdata outputs against fresh reference-builder output.",
|
||||
run: runCompareTopData,
|
||||
},
|
||||
}
|
||||
|
||||
func Run(args []string) (int, error) {
|
||||
@@ -103,6 +120,7 @@ func newContext() (context, error) {
|
||||
stdout: os.Stdout,
|
||||
stderr: os.Stderr,
|
||||
cwd: cwd,
|
||||
args: os.Args[1:],
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -284,8 +302,8 @@ func runApplyHAKManifest(ctx context) error {
|
||||
}
|
||||
|
||||
manifestPath := filepath.Join(p.BuildDir(), "haks.json")
|
||||
if len(os.Args) > 2 {
|
||||
manifestPath = os.Args[2]
|
||||
if len(ctx.args) > 1 {
|
||||
manifestPath = ctx.args[1]
|
||||
if !filepath.IsAbs(manifestPath) {
|
||||
manifestPath = filepath.Join(ctx.cwd, manifestPath)
|
||||
}
|
||||
@@ -303,6 +321,79 @@ func runApplyHAKManifest(ctx context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func runValidateTopData(ctx context) error {
|
||||
p, err := loadProject(ctx.cwd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
report := topdata.ValidateProject(p)
|
||||
for _, diagnostic := range report.Diagnostics {
|
||||
if diagnostic.Severity == topdata.SeverityWarning {
|
||||
fmt.Fprintf(ctx.stderr, "warning: %s: %s\n", diagnostic.Path, diagnostic.Message)
|
||||
continue
|
||||
}
|
||||
fmt.Fprintf(ctx.stderr, "error: %s: %s\n", diagnostic.Path, diagnostic.Message)
|
||||
}
|
||||
if report.HasErrors() {
|
||||
return fmt.Errorf("topdata validation failed with %d error(s)", report.ErrorCount())
|
||||
}
|
||||
|
||||
fmt.Fprintf(ctx.stdout, "project: %s\n", p.Config.Module.Name)
|
||||
fmt.Fprintf(ctx.stdout, "topdata root: %s\n", p.TopDataSourceDir())
|
||||
fmt.Fprintf(ctx.stdout, "topdata files: %d\n", report.Files)
|
||||
fmt.Fprintf(ctx.stdout, "data files: %d\n", report.DataFiles)
|
||||
fmt.Fprintf(ctx.stdout, "tlk files: %d\n", report.TLKFiles)
|
||||
if warnings := report.WarningCount(); warnings > 0 {
|
||||
fmt.Fprintf(ctx.stdout, "warnings: %d\n", warnings)
|
||||
}
|
||||
fmt.Fprintf(ctx.stdout, "topdata validation: ok\n")
|
||||
return nil
|
||||
}
|
||||
|
||||
func runBuildTopData(ctx context) error {
|
||||
p, err := loadProject(ctx.cwd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
result, err := topdata.BuildReference(p, func(message string) {
|
||||
fmt.Fprintf(ctx.stdout, "[build-topdata] %s\n", message)
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Fprintf(ctx.stdout, "project: %s\n", p.Config.Module.Name)
|
||||
fmt.Fprintf(ctx.stdout, "mode: %s\n", result.Mode)
|
||||
fmt.Fprintf(ctx.stdout, "topdata 2da output: %s\n", result.Output2DADir)
|
||||
fmt.Fprintf(ctx.stdout, "topdata tlk output: %s\n", result.OutputTLKDir)
|
||||
fmt.Fprintf(ctx.stdout, "2da files: %d\n", result.Files2DA)
|
||||
fmt.Fprintf(ctx.stdout, "tlk files: %d\n", result.FilesTLK)
|
||||
return nil
|
||||
}
|
||||
|
||||
func runCompareTopData(ctx context) error {
|
||||
p, err := loadProject(ctx.cwd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
result, err := topdata.CompareReference(p, func(message string) {
|
||||
fmt.Fprintf(ctx.stdout, "[compare-topdata] %s\n", message)
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Fprintf(ctx.stdout, "project: %s\n", p.Config.Module.Name)
|
||||
fmt.Fprintf(ctx.stdout, "mode: %s\n", result.Mode)
|
||||
fmt.Fprintf(ctx.stdout, "checked 2da files: %d\n", result.Compared2DA)
|
||||
fmt.Fprintf(ctx.stdout, "checked tlk files: %d\n", result.ComparedTLK)
|
||||
fmt.Fprintf(ctx.stdout, "topdata compare: ok\n")
|
||||
return nil
|
||||
}
|
||||
|
||||
func loadProject(cwd string) (*project.Project, error) {
|
||||
root, err := project.FindRoot(cwd)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user