From 1e19a972e2f4a037364a5a7a315201af49ff60e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Tue, 17 Sep 2024 16:36:36 +0100 Subject: [PATCH] pkg: drop packages.txt from gen.go MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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í Change-Id: Ia2ae7912bb9729a18771603903f75a3ff3f1ddf5 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1201390 Unity-Result: CUE porcuepine Reviewed-by: Roger Peppe TryBot-Result: CUEcueckoo --- pkg/gen.go | 34 +++++++++++++++------------------- pkg/packages.txt | 31 ------------------------------- 2 files changed, 15 insertions(+), 50 deletions(-) delete mode 100644 pkg/packages.txt diff --git a/pkg/gen.go b/pkg/gen.go index 766ad8894b1..35cb57c551d 100644 --- a/pkg/gen.go +++ b/pkg/gen.go @@ -42,7 +42,6 @@ import ( "log" "math/big" "os" - "path" "path/filepath" "sort" "strings" @@ -58,9 +57,6 @@ import ( const genFile = "pkg.go" -//go:embed packages.txt -var packagesStr string - type headerParams struct { GoPkg string CUEPkg string @@ -99,20 +95,8 @@ func main() { log.SetFlags(log.Lshortfile) log.SetOutput(os.Stdout) - var packagesList []string - for _, pkg := range strings.Fields(packagesStr) { - if pkg == "path" { - // TODO remove this special case. Currently the path - // pkg.go file cannot be generated automatically but that - // will be possible when we can attach arbitrary signatures - // to builtin functions. - continue - } - packagesList = append(packagesList, path.Join(pkgParent, pkg)) - } - cfg := &packages.Config{Mode: packages.NeedName | packages.NeedFiles | packages.NeedTypes | packages.NeedSyntax} - pkgs, err := packages.Load(cfg, packagesList...) + pkgs, err := packages.Load(cfg, "./...") if err != nil { fmt.Fprintf(os.Stderr, "load: %v\n", err) os.Exit(1) @@ -121,8 +105,20 @@ func main() { os.Exit(1) } for _, pkg := range pkgs { - if err := generate(pkg); err != nil { - log.Fatalf("%s: %v", pkg, err) + switch { + case pkg.PkgPath == pkgParent: + // The pkg package itself should not be generated. + case strings.Contains(pkg.PkgPath, "/internal"): + // Internal packages are not for public use. + case pkg.PkgPath == "cuelang.org/go/pkg/path": + // TODO remove this special case. Currently the path + // pkg.go file cannot be generated automatically but that + // will be possible when we can attach arbitrary signatures + // to builtin functions. + default: + if err := generate(pkg); err != nil { + log.Fatalf("%s: %v", pkg, err) + } } } } diff --git a/pkg/packages.txt b/pkg/packages.txt deleted file mode 100644 index e46a4404e7b..00000000000 --- a/pkg/packages.txt +++ /dev/null @@ -1,31 +0,0 @@ -regexp -encoding/json -encoding/base64 -encoding/yaml -encoding/hex -encoding/csv -uuid -time -list -strings -path -math/bits -math -crypto/sha256 -crypto/ed25519 -crypto/sha512 -crypto/md5 -crypto/sha1 -crypto/hmac -tool -tool/os -tool/cli -tool/exec -tool/file -tool/http -struct -net -html -strconv -text/template -text/tabwriter