Remove validation errors for missing .nss files
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
||||
"path/filepath"
|
||||
"slices"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"gitea.westgate.pw/ShadowsOverWestgate/sow-tools/internal/erf"
|
||||
"gitea.westgate.pw/ShadowsOverWestgate/sow-tools/internal/gff"
|
||||
@@ -29,10 +30,6 @@ type resourceExpectation struct {
|
||||
|
||||
func Compare(p *project.Project) (CompareResult, error) {
|
||||
modulePath := filepath.Join(p.BuildDir(), p.Config.Module.ResRef+".mod")
|
||||
moduleArchive, err := readArchive(modulePath)
|
||||
if err != nil {
|
||||
return CompareResult{}, err
|
||||
}
|
||||
|
||||
var hakPaths []string
|
||||
if len(p.Inventory.AssetFiles) > 0 {
|
||||
@@ -42,6 +39,14 @@ func Compare(p *project.Project) (CompareResult, error) {
|
||||
return CompareResult{}, err
|
||||
}
|
||||
}
|
||||
if err := ensureBuildIsCurrent(p, modulePath, hakPaths); err != nil {
|
||||
return CompareResult{ModulePath: modulePath, HAKPaths: hakPaths}, err
|
||||
}
|
||||
|
||||
moduleArchive, err := readArchive(modulePath)
|
||||
if err != nil {
|
||||
return CompareResult{}, err
|
||||
}
|
||||
|
||||
expected, err := expectedResources(p)
|
||||
if err != nil {
|
||||
@@ -142,7 +147,7 @@ func expectedResources(p *project.Project) (map[string]resourceExpectation, erro
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("read %s: %w", abs, err)
|
||||
}
|
||||
name := strings.TrimSuffix(filepath.Base(abs), filepath.Ext(abs))
|
||||
name := strings.ToLower(strings.TrimSuffix(filepath.Base(abs), filepath.Ext(abs)))
|
||||
extension := strings.TrimPrefix(strings.ToLower(filepath.Ext(abs)), ".")
|
||||
out[resourceKey(name, extension)] = resourceExpectation{
|
||||
Key: resourceKey(name, extension),
|
||||
@@ -157,7 +162,7 @@ func expectedResources(p *project.Project) (map[string]resourceExpectation, erro
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("read %s: %w", abs, err)
|
||||
}
|
||||
name := strings.TrimSuffix(filepath.Base(abs), filepath.Ext(abs))
|
||||
name := strings.ToLower(strings.TrimSuffix(filepath.Base(abs), filepath.Ext(abs)))
|
||||
extension := strings.TrimPrefix(strings.ToLower(filepath.Ext(abs)), ".")
|
||||
out[resourceKey(name, extension)] = resourceExpectation{
|
||||
Key: resourceKey(name, extension),
|
||||
@@ -169,6 +174,52 @@ func expectedResources(p *project.Project) (map[string]resourceExpectation, erro
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func ensureBuildIsCurrent(p *project.Project, modulePath string, hakPaths []string) error {
|
||||
archivePaths := make([]string, 0, 1+len(hakPaths))
|
||||
archivePaths = append(archivePaths, modulePath)
|
||||
archivePaths = append(archivePaths, hakPaths...)
|
||||
|
||||
oldestArchive := time.Time{}
|
||||
for _, path := range archivePaths {
|
||||
info, err := os.Stat(path)
|
||||
if err != nil {
|
||||
return fmt.Errorf("stat archive %s: %w", path, err)
|
||||
}
|
||||
if oldestArchive.IsZero() || info.ModTime().Before(oldestArchive) {
|
||||
oldestArchive = info.ModTime()
|
||||
}
|
||||
}
|
||||
|
||||
sourcePaths := make([]string, 0, len(p.Inventory.SourceFiles)+len(p.Inventory.ScriptFiles)+len(p.Inventory.AssetFiles))
|
||||
for _, rel := range p.Inventory.SourceFiles {
|
||||
sourcePaths = append(sourcePaths, filepath.Join(p.SourceDir(), filepath.FromSlash(rel)))
|
||||
}
|
||||
for _, rel := range p.Inventory.ScriptFiles {
|
||||
sourcePaths = append(sourcePaths, filepath.Join(p.SourceDir(), filepath.FromSlash(rel)))
|
||||
}
|
||||
for _, rel := range p.Inventory.AssetFiles {
|
||||
sourcePaths = append(sourcePaths, filepath.Join(p.AssetsDir(), filepath.FromSlash(rel)))
|
||||
}
|
||||
|
||||
newestSource := time.Time{}
|
||||
newestPath := ""
|
||||
for _, path := range sourcePaths {
|
||||
info, err := os.Stat(path)
|
||||
if err != nil {
|
||||
return fmt.Errorf("stat source %s: %w", path, err)
|
||||
}
|
||||
if newestSource.IsZero() || info.ModTime().After(newestSource) {
|
||||
newestSource = info.ModTime()
|
||||
newestPath = path
|
||||
}
|
||||
}
|
||||
|
||||
if !newestSource.IsZero() && newestSource.After(oldestArchive) {
|
||||
return fmt.Errorf("built archives are older than source file %s; run build-module or build-haks before compare", newestPath)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func readArchive(path string) (erf.Archive, error) {
|
||||
input, err := os.Open(path)
|
||||
if err != nil {
|
||||
@@ -191,7 +242,7 @@ func archiveIndex(archive erf.Archive) map[string]erf.Resource {
|
||||
continue
|
||||
}
|
||||
|
||||
key := resourceKey(resource.Name, extension)
|
||||
key := resourceKey(strings.ToLower(resource.Name), extension)
|
||||
switch extension {
|
||||
case "utc", "utd", "ute", "uti", "utm", "utp", "uts", "utt", "utw",
|
||||
"are", "dlg", "fac", "gic", "git", "ifo", "itp", "jrl":
|
||||
@@ -214,7 +265,7 @@ func archiveIndex(archive erf.Archive) map[string]erf.Resource {
|
||||
}
|
||||
|
||||
func resourceKey(name, extension string) string {
|
||||
return name + "." + strings.TrimPrefix(strings.ToLower(extension), ".")
|
||||
return strings.ToLower(name) + "." + strings.TrimPrefix(strings.ToLower(extension), ".")
|
||||
}
|
||||
|
||||
func manifestHAKPaths(buildDir string) ([]string, error) {
|
||||
|
||||
Reference in New Issue
Block a user