cue/ast/astutil: pick name based on import path
This at least ensures that two packages with
the same package names have different
mapped names.
Change-Id: I13b98cbcdf60f4814ec06c040110877c386e2197
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/3243
Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>
diff --git a/cue/ast/astutil/apply.go b/cue/ast/astutil/apply.go
index d805c27..924387e 100644
--- a/cue/ast/astutil/apply.go
+++ b/cue/ast/astutil/apply.go
@@ -15,7 +15,9 @@
package astutil
import (
+ "encoding/hex"
"fmt"
+ "hash/fnv"
"path"
"reflect"
"strconv"
@@ -126,7 +128,8 @@
// TODO: come up with something much better.
// For instance, hoist the uniquer form cue/export.go to
// here and make export.go use this.
- name += "530467a1"
+ hash := fnv.New32()
+ name += hex.EncodeToString(hash.Sum([]byte(importPath)))[:6]
quoted := strconv.Quote(importPath)
diff --git a/cue/ast/astutil/apply_test.go b/cue/ast/astutil/apply_test.go
index 4de20c1..79838ad 100644
--- a/cue/ast/astutil/apply_test.go
+++ b/cue/ast/astutil/apply_test.go
@@ -210,9 +210,9 @@
a: "string"
`,
out: `
-import list530467a1 "list"
+import list6c6973 "list"
-a: list530467a1
+a: list6c6973
`,
after: func(c astutil.Cursor) bool {
switch c.Node().(type) {
@@ -233,10 +233,10 @@
import (
"math"
- list530467a1 "list"
+ list6c6973 "list"
)
-a: list530467a1
+a: list6c6973
`,
after: func(c astutil.Cursor) bool {
switch x := c.Node().(type) {
@@ -259,10 +259,10 @@
import (
"list"
- list530467a1 "list"
+ list6c6973 "list"
)
-a: list530467a1
+a: list6c6973
`,
after: func(c astutil.Cursor) bool {
switch x := c.Node().(type) {