internal: switch defaullt GenPath to be in cue.mod
Change-Id: Icc9a3a3a6f4acfeb2c06fbe1788197d2128bc735
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/5340
Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>
diff --git a/internal/internal.go b/internal/internal.go
index dd6142a..b4ecd61 100644
--- a/internal/internal.go
+++ b/internal/internal.go
@@ -175,9 +175,15 @@
// GenPath reports the directory in which to store generated files.
func GenPath(root string) string {
info, err := os.Stat(filepath.Join(root, "cue.mod"))
- if err == nil && info.IsDir() {
- // TODO(legacy): support legacy cue.mod file.
- return filepath.Join(root, "cue.mod", "gen")
+ if os.IsNotExist(err) || !info.IsDir() {
+ // Try legacy pkgDir mode
+ pkgDir := filepath.Join(root, "pkg")
+ if err == nil && !info.IsDir() {
+ return pkgDir
+ }
+ if info, err := os.Stat(pkgDir); err == nil && info.IsDir() {
+ return pkgDir
+ }
}
- return filepath.Join(root, "pkg")
+ return filepath.Join(root, "cue.mod", "gen")
}