User-Friendliness
This commit is contained in:
+39
-9
@@ -6,6 +6,7 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"slices"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"gitea.westgate.pw/ShadowsOverWestgate/sow-tools/internal/pipeline"
|
"gitea.westgate.pw/ShadowsOverWestgate/sow-tools/internal/pipeline"
|
||||||
@@ -133,7 +134,9 @@ func runBuildModule(ctx context) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
result, err := pipeline.BuildModule(p)
|
result, err := pipeline.BuildModuleWithProgress(p, func(message string) {
|
||||||
|
fmt.Fprintf(ctx.stdout, "[build-module] %s\n", message)
|
||||||
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -150,7 +153,9 @@ func runBuildHAKs(ctx context) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
result, err := pipeline.BuildHAKs(p)
|
result, err := pipeline.BuildHAKsWithProgress(p, func(message string) {
|
||||||
|
fmt.Fprintf(ctx.stdout, "[build-haks] %s\n", message)
|
||||||
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -195,10 +200,9 @@ func runValidate(ctx context) error {
|
|||||||
|
|
||||||
validationReport := validator.ValidateProject(p)
|
validationReport := validator.ValidateProject(p)
|
||||||
if validationReport.HasErrors() {
|
if validationReport.HasErrors() {
|
||||||
|
emitValidationWarnings(ctx.stderr, validationReport.Diagnostics)
|
||||||
for _, diagnostic := range validationReport.Diagnostics {
|
for _, diagnostic := range validationReport.Diagnostics {
|
||||||
if diagnostic.Severity == validator.SeverityWarning {
|
if diagnostic.Severity == validator.SeverityWarning {
|
||||||
fprintfTarget := ctx.stderr
|
|
||||||
fmt.Fprintf(fprintfTarget, "warning: %s: %s\n", diagnostic.Path, diagnostic.Message)
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
fmt.Fprintf(ctx.stderr, "error: %s: %s\n", diagnostic.Path, diagnostic.Message)
|
fmt.Fprintf(ctx.stderr, "error: %s: %s\n", diagnostic.Path, diagnostic.Message)
|
||||||
@@ -206,11 +210,7 @@ func runValidate(ctx context) error {
|
|||||||
return fmt.Errorf("validation failed with %d error(s)", validationReport.ErrorCount())
|
return fmt.Errorf("validation failed with %d error(s)", validationReport.ErrorCount())
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, diagnostic := range validationReport.Diagnostics {
|
emitValidationWarnings(ctx.stderr, validationReport.Diagnostics)
|
||||||
if diagnostic.Severity == validator.SeverityWarning {
|
|
||||||
fmt.Fprintf(ctx.stderr, "warning: %s: %s\n", diagnostic.Path, diagnostic.Message)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
inventoryReport := p.Inventory.Report()
|
inventoryReport := p.Inventory.Report()
|
||||||
fmt.Fprintf(ctx.stdout, "project: %s\n", p.Config.Module.Name)
|
fmt.Fprintf(ctx.stdout, "project: %s\n", p.Config.Module.Name)
|
||||||
@@ -226,6 +226,36 @@ func runValidate(ctx context) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func emitValidationWarnings(w io.Writer, diagnostics []validator.Diagnostic) {
|
||||||
|
const lowercaseWarning = "resource filenames should be lowercase"
|
||||||
|
|
||||||
|
lowercasePaths := make([]string, 0)
|
||||||
|
for _, diagnostic := range diagnostics {
|
||||||
|
if diagnostic.Severity != validator.SeverityWarning {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if diagnostic.Message == lowercaseWarning {
|
||||||
|
lowercasePaths = append(lowercasePaths, diagnostic.Path)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
fmt.Fprintf(w, "warning: %s: %s\n", diagnostic.Path, diagnostic.Message)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(lowercasePaths) == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
slices.Sort(lowercasePaths)
|
||||||
|
examples := lowercasePaths
|
||||||
|
if len(examples) > 5 {
|
||||||
|
examples = examples[:5]
|
||||||
|
}
|
||||||
|
message := strings.Join(examples, ", ")
|
||||||
|
if len(lowercasePaths) > len(examples) {
|
||||||
|
message += fmt.Sprintf(", and %d more", len(lowercasePaths)-len(examples))
|
||||||
|
}
|
||||||
|
fmt.Fprintf(w, "warning: %d resource filenames are not lowercase: %s\n", len(lowercasePaths), message)
|
||||||
|
}
|
||||||
|
|
||||||
func runCompare(ctx context) error {
|
func runCompare(ctx context) error {
|
||||||
p, err := loadProject(ctx.cwd)
|
p, err := loadProject(ctx.cwd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -52,6 +52,8 @@ type hakChunk struct {
|
|||||||
Size int64
|
Size int64
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ProgressFunc func(string)
|
||||||
|
|
||||||
func Build(p *project.Project) (BuildResult, error) {
|
func Build(p *project.Project) (BuildResult, error) {
|
||||||
moduleResult, err := BuildModule(p)
|
moduleResult, err := BuildModule(p)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -68,15 +70,26 @@ func Build(p *project.Project) (BuildResult, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func BuildModule(p *project.Project) (BuildResult, error) {
|
func BuildModule(p *project.Project) (BuildResult, error) {
|
||||||
|
return buildModule(p, nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BuildModuleWithProgress(p *project.Project, progress ProgressFunc) (BuildResult, error) {
|
||||||
|
return buildModule(p, progress)
|
||||||
|
}
|
||||||
|
|
||||||
|
func buildModule(p *project.Project, progress ProgressFunc) (BuildResult, error) {
|
||||||
|
progressf(progress, "Validating project...")
|
||||||
if err := validateForBuild(p); err != nil {
|
if err := validateForBuild(p); err != nil {
|
||||||
return BuildResult{}, err
|
return BuildResult{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
progressf(progress, "Collecting module resources...")
|
||||||
moduleResources, err := collectModuleResources(p, nil)
|
moduleResources, err := collectModuleResources(p, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return BuildResult{}, err
|
return BuildResult{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
progressf(progress, "Writing module archive...")
|
||||||
outputPath := filepath.Join(p.BuildDir(), p.Config.Module.ResRef+".mod")
|
outputPath := filepath.Join(p.BuildDir(), p.Config.Module.ResRef+".mod")
|
||||||
output, err := os.Create(outputPath)
|
output, err := os.Create(outputPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -95,14 +108,25 @@ func BuildModule(p *project.Project) (BuildResult, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func BuildHAKs(p *project.Project) (BuildResult, error) {
|
func BuildHAKs(p *project.Project) (BuildResult, error) {
|
||||||
|
return buildHAKs(p, nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BuildHAKsWithProgress(p *project.Project, progress ProgressFunc) (BuildResult, error) {
|
||||||
|
return buildHAKs(p, progress)
|
||||||
|
}
|
||||||
|
|
||||||
|
func buildHAKs(p *project.Project, progress ProgressFunc) (BuildResult, error) {
|
||||||
|
progressf(progress, "Validating project...")
|
||||||
if err := validateForBuild(p); err != nil {
|
if err := validateForBuild(p); err != nil {
|
||||||
return BuildResult{}, err
|
return BuildResult{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
progressf(progress, "Collecting asset resources...")
|
||||||
assetResources, err := collectAssetResources(p)
|
assetResources, err := collectAssetResources(p)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return BuildResult{}, err
|
return BuildResult{}, err
|
||||||
}
|
}
|
||||||
|
progressf(progress, "Cleaning previous generated HAKs...")
|
||||||
if err := cleanupGeneratedHAKs(p.BuildDir(), p.Config.Module.ResRef); err != nil {
|
if err := cleanupGeneratedHAKs(p.BuildDir(), p.Config.Module.ResRef); err != nil {
|
||||||
return BuildResult{}, err
|
return BuildResult{}, err
|
||||||
}
|
}
|
||||||
@@ -112,10 +136,12 @@ func BuildHAKs(p *project.Project) (BuildResult, error) {
|
|||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
progressf(progress, "Planning HAK chunks...")
|
||||||
chunks, err := planHAKChunks(p, assetResources)
|
chunks, err := planHAKChunks(p, assetResources)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return BuildResult{}, err
|
return BuildResult{}, err
|
||||||
}
|
}
|
||||||
|
progressf(progress, "Resolving module HAK order...")
|
||||||
moduleHakOrder, err := resolveModuleHAKOrder(p, chunks)
|
moduleHakOrder, err := resolveModuleHAKOrder(p, chunks)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return BuildResult{}, err
|
return BuildResult{}, err
|
||||||
@@ -125,7 +151,8 @@ func BuildHAKs(p *project.Project) (BuildResult, error) {
|
|||||||
ModuleHAKs: moduleHakOrder,
|
ModuleHAKs: moduleHakOrder,
|
||||||
HAKs: make([]BuildManifestHAK, 0, len(chunks)),
|
HAKs: make([]BuildManifestHAK, 0, len(chunks)),
|
||||||
}
|
}
|
||||||
for _, chunk := range chunks {
|
for index, chunk := range chunks {
|
||||||
|
progressf(progress, fmt.Sprintf("Writing HAK %d/%d: %s (%d assets)", index+1, len(chunks), chunk.Name, len(chunk.Assets)))
|
||||||
hakPath := filepath.Join(p.BuildDir(), chunk.Name+".hak")
|
hakPath := filepath.Join(p.BuildDir(), chunk.Name+".hak")
|
||||||
hakOutput, err := os.Create(hakPath)
|
hakOutput, err := os.Create(hakPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -154,6 +181,7 @@ func BuildHAKs(p *project.Project) (BuildResult, error) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
progressf(progress, "Writing HAK manifest...")
|
||||||
manifestPath := filepath.Join(p.BuildDir(), "haks.json")
|
manifestPath := filepath.Join(p.BuildDir(), "haks.json")
|
||||||
manifestBytes, err := json.MarshalIndent(manifest, "", " ")
|
manifestBytes, err := json.MarshalIndent(manifest, "", " ")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -167,6 +195,12 @@ func BuildHAKs(p *project.Project) (BuildResult, error) {
|
|||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func progressf(progress ProgressFunc, message string) {
|
||||||
|
if progress != nil {
|
||||||
|
progress(message)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func collectModuleResources(p *project.Project, moduleHakOrder []string) ([]erf.Resource, error) {
|
func collectModuleResources(p *project.Project, moduleHakOrder []string) ([]erf.Resource, error) {
|
||||||
var moduleResources []erf.Resource
|
var moduleResources []erf.Resource
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user