Skip to content

Commit

Permalink
cmd/cue/cmd: fix build breakage
Browse files Browse the repository at this point in the history
Need relative path.

Change-Id: Idd7db15ddc9e5034c9aa2730f25240a9d60de215
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/6143
Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>
  • Loading branch information
mpvl committed May 19, 2020
1 parent dbf1c00 commit c114dbb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
15 changes: 13 additions & 2 deletions cmd/cue/cmd/fixall.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ package cmd
import (
"fmt"
"hash/fnv"
"os"
"path/filepath"
"strings"

"cuelang.org/go/cue"
Expand All @@ -30,9 +32,12 @@ import (
)

func fixAll(a []*build.Instance) errors.Error {
cwd, _ := os.Getwd()

// Collect all
p := processor{
instances: a,
cwd: cwd,

done: map[ast.Node]bool{},
rename: map[*ast.Ident]string{},
Expand All @@ -52,6 +57,7 @@ func fixAll(a []*build.Instance) errors.Error {

type processor struct {
instances []*build.Instance
cwd string

done map[ast.Node]bool
// Evidence for rewrites. Rewrite in a later pass.
Expand Down Expand Up @@ -246,8 +252,13 @@ func (p *processor) renameFields(f *ast.File) {

b := &strings.Builder{}
fmt.Fprintln(b, "Possible references to this location:")
for _, p := range refs {
fmt.Fprintf(b, "\t%s\n", p)
for _, r := range refs {
s, err := filepath.Rel(p.cwd, r.String())
if err != nil {
s = r.String()
}
s = filepath.ToSlash(s)
fmt.Fprintf(b, "\t%s\n", s)
}

cg := internal.NewComment(true, b.String())
Expand Down
4 changes: 2 additions & 2 deletions cmd/cue/cmd/testdata/fix/unsupported.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ b: "\(Def.b)": int
package foo

// Possible references to this location:
// /Users/mpvl/Cloud/dev/cue/cmd/cue/cmd/testdata/fix/foo/foo.cue:8:4
// /Users/mpvl/Cloud/dev/cue/cmd/cue/cmd/testdata/fix/foo/foo.cue:9:7
// testdata/fix/foo/foo.cue:8:4
// testdata/fix/foo/foo.cue:9:7
#Def: {
a: int
b: "foo"
Expand Down

0 comments on commit c114dbb

Please sign in to comment.