this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

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í <mvdan@mvdan.cc>
Change-Id: Ia2ae7912bb9729a18771603903f75a3ff3f1ddf5
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1201390
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
Reviewed-by: Roger Peppe <rogpeppe@gmail.com>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>

+15 -50
+15 -19
pkg/gen.go
··· 42 42 "log" 43 43 "math/big" 44 44 "os" 45 - "path" 46 45 "path/filepath" 47 46 "sort" 48 47 "strings" ··· 57 56 ) 58 57 59 58 const genFile = "pkg.go" 60 - 61 - //go:embed packages.txt 62 - var packagesStr string 63 59 64 60 type headerParams struct { 65 61 GoPkg string ··· 99 95 log.SetFlags(log.Lshortfile) 100 96 log.SetOutput(os.Stdout) 101 97 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 - 114 98 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, "./...") 116 100 if err != nil { 117 101 fmt.Fprintf(os.Stderr, "load: %v\n", err) 118 102 os.Exit(1) ··· 121 105 os.Exit(1) 122 106 } 123 107 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 + } 126 122 } 127 123 } 128 124 }
-31
pkg/packages.txt
··· 1 - regexp 2 - encoding/json 3 - encoding/base64 4 - encoding/yaml 5 - encoding/hex 6 - encoding/csv 7 - uuid 8 - time 9 - list 10 - strings 11 - path 12 - math/bits 13 - math 14 - crypto/sha256 15 - crypto/ed25519 16 - crypto/sha512 17 - crypto/md5 18 - crypto/sha1 19 - crypto/hmac 20 - tool 21 - tool/os 22 - tool/cli 23 - tool/exec 24 - tool/file 25 - tool/http 26 - struct 27 - net 28 - html 29 - strconv 30 - text/template 31 - text/tabwriter