1 // Copyright (c) 2018 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.
25 "github.com/sirupsen/logrus"
27 "git.fd.io/govpp.git/binapigen"
28 "git.fd.io/govpp.git/binapigen/vppapi"
29 "git.fd.io/govpp.git/internal/version"
34 fmt.Fprintf(os.Stderr, "Usage: %s [OPTION] API_FILES\n", os.Args[0])
35 fmt.Fprintln(os.Stderr, "Provide API_FILES by file name, or with full path including extension.")
36 fmt.Fprintln(os.Stderr, "Parse API_FILES and generate Go bindings based on the options given:")
43 theApiDir = flag.String("input-dir", vppapi.DefaultDir, "Input directory containing API files.")
44 theInputFile = flag.String("input-file", "", "DEPRECATED: Use program arguments to define files to generate.")
45 theOutputDir = flag.String("output-dir", "binapi", "Output directory where code will be generated.")
46 importPrefix = flag.String("import-prefix", "", "Define import path prefix to be used to import types.")
47 generatorPlugins = flag.String("gen", "rpc", "List of generator plugins to run for files.")
49 printVersion = flag.Bool("version", false, "Prints version and exits.")
50 debugLog = flag.Bool("debug", false, "Enable verbose logging.")
51 noVersionInfo = flag.Bool("no-version-info", false, "Disable version info in generated files.")
52 noSourcePathInfo = flag.Bool("no-source-path-info", false, "Disable source path info in generated files.")
57 fmt.Fprintln(os.Stdout, version.Info())
62 logrus.SetLevel(logrus.DebugLevel)
65 var filesToGenerate []string
66 if *theInputFile != "" {
68 fmt.Fprintln(os.Stderr, "input-file cannot be combined with files to generate in arguments")
71 filesToGenerate = append(filesToGenerate, *theInputFile)
73 filesToGenerate = append(filesToGenerate, flag.Args()...)
76 opts := binapigen.Options{
77 ImportPrefix: *importPrefix,
78 OutputDir: *theOutputDir,
79 NoVersionInfo: *noVersionInfo,
80 NoSourcePathInfo: *noSourcePathInfo,
82 if opts.OutputDir == "binapi" {
83 if wd, _ := os.Getwd(); filepath.Base(wd) == "binapi" {
88 genPlugins := strings.FieldsFunc(*generatorPlugins, func(c rune) bool {
89 return !unicode.IsLetter(c) && !unicode.IsNumber(c)
92 binapigen.Run(apiDir, filesToGenerate, opts, func(gen *binapigen.Generator) error {
93 for _, file := range gen.Files {
97 binapigen.GenerateAPI(gen, file)
98 for _, p := range genPlugins {
99 if err := binapigen.RunPlugin(p, gen, file); err != nil {