1 // Copyright (c) 2020 Cisco and/or its affiliates.
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:
7 // http://www.apache.org/licenses/LICENSE-2.0
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.
22 "github.com/sirupsen/logrus"
24 "git.fd.io/govpp.git/binapigen/vppapi"
29 func logf(f string, v ...interface{}) {
31 logrus.Debugf(f, v...)
35 func GenerateBinapiFile(gen *Generator, file *File, outputDir string) *GenFile {
36 packageDir := filepath.Join(outputDir, file.PackageName)
37 filename := filepath.Join(packageDir, file.PackageName+outputFileExt)
39 g := gen.NewGenFile(filename)
41 g.packageDir = filepath.Join(outputDir, file.PackageName)
43 generatePackage(g, &g.buf)
48 func GenerateRPC(gen *Generator, file *File, outputDir string) *GenFile {
49 packageDir := filepath.Join(outputDir, file.PackageName)
50 filename := filepath.Join(packageDir, file.PackageName+rpcFileSuffix+outputFileExt)
52 g := gen.NewGenFile(filename)
54 g.packageDir = filepath.Join(outputDir, file.PackageName)
56 generatePackageRPC(g, &g.buf)
61 func Run(apiDir string, opts Options, f func(*Generator) error) {
62 if err := run(apiDir, opts, f); err != nil {
63 fmt.Fprintf(os.Stderr, "%s: %v\n", filepath.Base(os.Args[0]), err)
68 func run(apiDir string, opts Options, f func(*Generator) error) error {
70 apifiles, err := vppapi.ParseDir(apiDir)
75 g, err := New(opts, apifiles)
80 if err := f(g); err != nil {
84 if err = g.Generate(); err != nil {