Packaging Fix
This commit is contained in:
@@ -165,6 +165,7 @@ func packageBuiltTopData(p *project.Project, nativeResult BuildResult, progress
|
||||
|
||||
func collectTopPackageResources(p *project.Project, compiled2DADir string) ([]erf.Resource, int, error) {
|
||||
resourceByKey := map[string]erf.Resource{}
|
||||
resourceSourceByKey := map[string]string{}
|
||||
|
||||
entries, err := os.ReadDir(compiled2DADir)
|
||||
if err != nil {
|
||||
@@ -179,7 +180,9 @@ func collectTopPackageResources(p *project.Project, compiled2DADir string) ([]er
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
resourceByKey[topPackageResourceKey(resource)] = resource
|
||||
key := topPackageResourceKey(resource)
|
||||
resourceByKey[key] = resource
|
||||
resourceSourceByKey[key] = path
|
||||
}
|
||||
|
||||
assetFiles := 0
|
||||
@@ -210,10 +213,11 @@ func collectTopPackageResources(p *project.Project, compiled2DADir string) ([]er
|
||||
return err
|
||||
}
|
||||
key := topPackageResourceKey(resource)
|
||||
if _, ok := resourceByKey[key]; ok {
|
||||
return fmt.Errorf("topdata asset %s collides with generated top package resource %s", path, key)
|
||||
if existing, ok := resourceSourceByKey[key]; ok {
|
||||
return fmt.Errorf("topdata asset %s collides with %s for top package resource %s", path, existing, key)
|
||||
}
|
||||
resourceByKey[key] = resource
|
||||
resourceSourceByKey[key] = path
|
||||
assetFiles++
|
||||
return nil
|
||||
})
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package topdata
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
@@ -9670,7 +9671,8 @@ func TestBuildAndPackageIncludesCompiled2DAAndTopAssets(t *testing.T) {
|
||||
"columns": ["Label"],
|
||||
"rows": [{"id": 0, "Label": "TEST_LABEL"}]
|
||||
}`+"\n")
|
||||
writeFile(t, filepath.Join(root, "topdata", "assets", "gui", "testicon.png"), "icon-data")
|
||||
pngPayload := bytes.Repeat([]byte("png-payload-"), 4096)
|
||||
writeBytes(t, filepath.Join(root, "topdata", "assets", "gui", "testicon.png"), pngPayload)
|
||||
|
||||
proj := testProject(root)
|
||||
proj.Config.TopData.ReferenceBuilder = ""
|
||||
@@ -9708,6 +9710,9 @@ func TestBuildAndPackageIncludesCompiled2DAAndTopAssets(t *testing.T) {
|
||||
found2DA = true
|
||||
}
|
||||
if key == "testicon.png" {
|
||||
if !bytes.Equal(resource.Data, pngPayload) {
|
||||
t.Fatalf("expected testicon.png payload to be preserved, got %d bytes", len(resource.Data))
|
||||
}
|
||||
foundAsset = true
|
||||
}
|
||||
if ext == "tlk" {
|
||||
@@ -9728,6 +9733,22 @@ func TestBuildAndPackageIncludesCompiled2DAAndTopAssets(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestCollectTopPackageResourcesRejectsDuplicateTopAssetKeys(t *testing.T) {
|
||||
root := testProjectRoot(t)
|
||||
mkdirAll(t, filepath.Join(root, ".cache", "2da"))
|
||||
mkdirAll(t, filepath.Join(root, "topdata", "assets", "gui", "icons"))
|
||||
mkdirAll(t, filepath.Join(root, "topdata", "assets", "gui", "portraits"))
|
||||
writeFile(t, filepath.Join(root, "topdata", "base_dialog.json"), "{}\n")
|
||||
writeFile(t, filepath.Join(root, ".cache", "2da", "repadjust.2da"), "2DA V2.0\n\n Label\n0 TEST_LABEL\n")
|
||||
writeFile(t, filepath.Join(root, "topdata", "assets", "gui", "icons", "duplicate.png"), "icon-a")
|
||||
writeFile(t, filepath.Join(root, "topdata", "assets", "gui", "portraits", "duplicate.png"), "icon-b")
|
||||
|
||||
proj := testProject(root)
|
||||
if _, _, err := collectTopPackageResources(proj, filepath.Join(root, ".cache", "2da")); err == nil || !strings.Contains(err.Error(), "collides with") {
|
||||
t.Fatalf("expected duplicate topdata asset collision, got %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildAndPackageHonorsConfiguredTopPackageOutputNames(t *testing.T) {
|
||||
root := testProjectRoot(t)
|
||||
mkdirAll(t, filepath.Join(root, "topdata", "data", "repadjust"))
|
||||
@@ -10214,3 +10235,10 @@ func writeFile(t *testing.T, path, content string) {
|
||||
t.Fatalf("write %s: %v", path, err)
|
||||
}
|
||||
}
|
||||
|
||||
func writeBytes(t *testing.T, path string, content []byte) {
|
||||
t.Helper()
|
||||
if err := os.WriteFile(path, content, 0o755); err != nil {
|
||||
t.Fatalf("write %s: %v", path, err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user