this repo has no description
0
fork

Configure Feed

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

pkg: generate register.go automatically as well

Resolves a TODO, and avoids us having to maintain the file manually.

Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
Change-Id: I79d852f1822fedb89a63b810115b5dd8fbee4c78
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1201391
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Reviewed-by: Roger Peppe <rogpeppe@gmail.com>
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>

+18 -23
+17 -10
pkg/gen.go
··· 28 28 // Be sure to also update an entry in pkg/pkg.go, if so desired. 29 29 package main 30 30 31 - // TODO generate ../register.go too. 32 - 33 31 import ( 34 32 "bytes" 35 33 _ "embed" ··· 54 52 "cuelang.org/go/cue/parser" 55 53 "cuelang.org/go/internal" 56 54 ) 57 - 58 - const genFile = "pkg.go" 59 55 60 56 type headerParams struct { 61 57 GoPkg string ··· 104 100 if packages.PrintErrors(pkgs) > 0 { 105 101 os.Exit(1) 106 102 } 103 + regBuf := new(bytes.Buffer) 104 + fmt.Fprintf(regBuf, "// Code generated by cuelang.org/go/pkg/gen. DO NOT EDIT.\n\n") 105 + fmt.Fprintf(regBuf, "package pkg\n\n") 106 + fmt.Fprintf(regBuf, "import (\n") 107 107 for _, pkg := range pkgs { 108 108 switch { 109 109 case pkg.PkgPath == pkgParent: 110 110 // The pkg package itself should not be generated. 111 111 case strings.Contains(pkg.PkgPath, "/internal"): 112 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 113 default: 114 + fmt.Fprintf(regBuf, "\t_ %q\n", pkg.PkgPath) 115 + if pkg.PkgPath == "cuelang.org/go/pkg/path" { 116 + // TODO remove this special case. Currently the path 117 + // pkg.go file cannot be generated automatically but that 118 + // will be possible when we can attach arbitrary signatures 119 + // to builtin functions. 120 + break 121 + } 119 122 if err := generate(pkg); err != nil { 120 123 log.Fatalf("%s: %v", pkg, err) 121 124 } 122 125 } 126 + } 127 + fmt.Fprintf(regBuf, ")\n") 128 + if err := os.WriteFile("register.go", regBuf.Bytes(), 0o666); err != nil { 129 + log.Fatal(err) 123 130 } 124 131 } 125 132 ··· 190 197 b = g.w.Bytes() // write the unformatted source 191 198 } 192 199 193 - filename := filepath.Join(pkgDir, genFile) 200 + filename := filepath.Join(pkgDir, "pkg.go") 194 201 195 202 if err := os.WriteFile(filename, b, 0666); err != nil { 196 203 return err
+1 -13
pkg/register.go
··· 1 - // Copyright 2020 CUE Authors 2 - // 3 - // Licensed under the Apache License, Version 2.0 (the "License"); 4 - // you may not use this file except in compliance with the License. 5 - // You may obtain a copy of the License at 6 - // 7 - // http://www.apache.org/licenses/LICENSE-2.0 8 - // 9 - // Unless required by applicable law or agreed to in writing, software 10 - // distributed under the License is distributed on an "AS IS" BASIS, 11 - // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 - // See the License for the specific language governing permissions and 13 - // limitations under the License. 1 + // Code generated by cuelang.org/go/pkg/gen. DO NOT EDIT. 14 2 15 3 package pkg 16 4