Skip to content

Commit 1e19a97

Browse files
committed
pkg: drop packages.txt from gen.go
It lists all non-internal subpackages from ./pkg/..., which is something we can do rather easily via go/packages. Not only does this save us some code, it also saves having to manually keep packages.txt up to date, which is error prone. Signed-off-by: Daniel Martí <[email protected]> Change-Id: Ia2ae7912bb9729a18771603903f75a3ff3f1ddf5 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1201390 Unity-Result: CUE porcuepine <[email protected]> Reviewed-by: Roger Peppe <[email protected]> TryBot-Result: CUEcueckoo <[email protected]>
1 parent 6ba366c commit 1e19a97

File tree

2 files changed

+15
-50
lines changed

2 files changed

+15
-50
lines changed

pkg/gen.go

+15-19
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ import (
4242
"log"
4343
"math/big"
4444
"os"
45-
"path"
4645
"path/filepath"
4746
"sort"
4847
"strings"
@@ -58,9 +57,6 @@ import (
5857

5958
const genFile = "pkg.go"
6059

61-
//go:embed packages.txt
62-
var packagesStr string
63-
6460
type headerParams struct {
6561
GoPkg string
6662
CUEPkg string
@@ -99,20 +95,8 @@ func main() {
9995
log.SetFlags(log.Lshortfile)
10096
log.SetOutput(os.Stdout)
10197

102-
var packagesList []string
103-
for _, pkg := range strings.Fields(packagesStr) {
104-
if pkg == "path" {
105-
// TODO remove this special case. Currently the path
106-
// pkg.go file cannot be generated automatically but that
107-
// will be possible when we can attach arbitrary signatures
108-
// to builtin functions.
109-
continue
110-
}
111-
packagesList = append(packagesList, path.Join(pkgParent, pkg))
112-
}
113-
11498
cfg := &packages.Config{Mode: packages.NeedName | packages.NeedFiles | packages.NeedTypes | packages.NeedSyntax}
115-
pkgs, err := packages.Load(cfg, packagesList...)
99+
pkgs, err := packages.Load(cfg, "./...")
116100
if err != nil {
117101
fmt.Fprintf(os.Stderr, "load: %v\n", err)
118102
os.Exit(1)
@@ -121,8 +105,20 @@ func main() {
121105
os.Exit(1)
122106
}
123107
for _, pkg := range pkgs {
124-
if err := generate(pkg); err != nil {
125-
log.Fatalf("%s: %v", pkg, err)
108+
switch {
109+
case pkg.PkgPath == pkgParent:
110+
// The pkg package itself should not be generated.
111+
case strings.Contains(pkg.PkgPath, "/internal"):
112+
// Internal packages are not for public use.
113+
case pkg.PkgPath == "cuelang.org/go/pkg/path":
114+
// TODO remove this special case. Currently the path
115+
// pkg.go file cannot be generated automatically but that
116+
// will be possible when we can attach arbitrary signatures
117+
// to builtin functions.
118+
default:
119+
if err := generate(pkg); err != nil {
120+
log.Fatalf("%s: %v", pkg, err)
121+
}
126122
}
127123
}
128124
}

pkg/packages.txt

-31
This file was deleted.

0 commit comments

Comments
 (0)