Skip to content

Commit

Permalink
pkg: drop packages.txt from gen.go
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
mvdan committed Sep 18, 2024
1 parent 6ba366c commit 1e19a97
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 50 deletions.
34 changes: 15 additions & 19 deletions pkg/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ import (
"log"
"math/big"
"os"
"path"
"path/filepath"
"sort"
"strings"
Expand All @@ -58,9 +57,6 @@ import (

const genFile = "pkg.go"

//go:embed packages.txt
var packagesStr string

type headerParams struct {
GoPkg string
CUEPkg string
Expand Down Expand Up @@ -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)
Expand All @@ -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)
}
}
}
}
Expand Down
31 changes: 0 additions & 31 deletions pkg/packages.txt

This file was deleted.

0 comments on commit 1e19a97

Please sign in to comment.