diff options
author | Ondrej Fabry <ofabry@cisco.com> | 2019-06-12 18:37:20 +0200 |
---|---|---|
committer | Ondrej Fabry <ofabry@cisco.com> | 2019-06-12 19:41:35 +0200 |
commit | 682250e328472e855a4c59e9e5f004473b6af0d3 (patch) | |
tree | 6de85c22a2d18a83ba05f2713c75c9d089c6275b | |
parent | c4522fe10317b1729a0820dc880afc78c663f64d (diff) |
Fix parsing API with removed CRC for types and unions
- method GetCrcString() was also removed from DataType interface
- fix generated comment for services
- fix permissions for created files and directories
Change-Id: If0b7a57e01f1128b5ba574fc5ee13b6a7c6aa6fd
Signed-off-by: Ondrej Fabry <ofabry@cisco.com>
-rw-r--r-- | api/binapi.go | 3 | ||||
-rw-r--r-- | cmd/binapi-generator/generate.go | 10 | ||||
-rw-r--r-- | cmd/binapi-generator/main.go | 12 | ||||
-rw-r--r-- | cmd/binapi-generator/parse.go | 20 | ||||
-rw-r--r-- | examples/binapi/acl/acl.ba.go | 2 | ||||
-rw-r--r-- | examples/binapi/af_packet/af_packet.ba.go | 2 | ||||
-rw-r--r-- | examples/binapi/interfaces/interfaces.ba.go | 2 | ||||
-rw-r--r-- | examples/binapi/ip/ip.ba.go | 2 | ||||
-rw-r--r-- | examples/binapi/memclnt/memclnt.ba.go | 2 | ||||
-rw-r--r-- | examples/binapi/memif/memif.ba.go | 2 | ||||
-rw-r--r-- | examples/binapi/vpe/vpe.ba.go | 2 |
11 files changed, 34 insertions, 25 deletions
diff --git a/api/binapi.go b/api/binapi.go index ac9f8a4..6495d0d 100644 --- a/api/binapi.go +++ b/api/binapi.go @@ -52,9 +52,6 @@ type Message interface { type DataType interface { // GetTypeName returns the original VPP name of the data type, as defined in the VPP API. GetTypeName() string - - // GetCrcString returns the string with CRC checksum of the data type definition (the string represents a hexadecimal number). - GetCrcString() string } // ChannelProvider provides the communication channel with govpp core. diff --git a/cmd/binapi-generator/generate.go b/cmd/binapi-generator/generate.go index d9555e7..1ff3e4c 100644 --- a/cmd/binapi-generator/generate.go +++ b/cmd/binapi-generator/generate.go @@ -256,7 +256,7 @@ func generateImports(ctx *context, w io.Writer) { // generateComment writes generated comment for the object into w func generateComment(ctx *context, w io.Writer, goName string, vppName string, objKind string) { if objKind == "service" { - fmt.Fprintf(w, "// %s represents VPP binary API services in %s module.\n", ctx.moduleName, goName) + fmt.Fprintf(w, "// %s represents VPP binary API services in %s module.\n", goName, ctx.moduleName) } else { fmt.Fprintf(w, "// %s represents VPP binary API %s '%s':\n", goName, objKind, vppName) } @@ -497,7 +497,9 @@ func generateUnion(ctx *context, w io.Writer, union *Union) { generateTypeNameGetter(w, name, union.Name) // generate CRC getter - generateCrcGetter(w, name, union.CRC) + if union.CRC != "" { + generateCrcGetter(w, name, union.CRC) + } // generate getters for fields for _, field := range union.Fields { @@ -589,7 +591,9 @@ func generateType(ctx *context, w io.Writer, typ *Type) { generateTypeNameGetter(w, name, typ.Name) // generate CRC getter - generateCrcGetter(w, name, typ.CRC) + if typ.CRC != "" { + generateCrcGetter(w, name, typ.CRC) + } fmt.Fprintln(w) } diff --git a/cmd/binapi-generator/main.go b/cmd/binapi-generator/main.go index 75926e1..d221317 100644 --- a/cmd/binapi-generator/main.go +++ b/cmd/binapi-generator/main.go @@ -62,9 +62,17 @@ func main() { } } else { // process all files in specified directory + dir, err := filepath.Abs(*inputDir) + if err != nil { + fmt.Fprintf(os.Stderr, "ERROR: invalid input directory: %v\n", err) + os.Exit(1) + } files, err := getInputFiles(*inputDir) if err != nil { - fmt.Fprintf(os.Stderr, "ERROR: code generation failed: %v\n", err) + fmt.Fprintf(os.Stderr, "ERROR: problem getting files from input directory: %v\n", err) + os.Exit(1) + } else if len(files) == 0 { + fmt.Fprintf(os.Stderr, "ERROR: no input files found in input directory: %v\n", dir) os.Exit(1) } for _, file := range files { @@ -134,7 +142,7 @@ func generateFromFile(inputFile, outputDir string) error { // create output directory packageDir := filepath.Dir(ctx.outputFile) - if err := os.MkdirAll(packageDir, 06); err != nil { + if err := os.MkdirAll(packageDir, 0775); err != nil { return fmt.Errorf("creating output dir %s failed: %v", packageDir, err) } // write generated code to output file diff --git a/cmd/binapi-generator/parse.go b/cmd/binapi-generator/parse.go index 562abab..602b17f 100644 --- a/cmd/binapi-generator/parse.go +++ b/cmd/binapi-generator/parse.go @@ -274,9 +274,9 @@ func parseUnion(ctx *context, unionNode *jsongo.JSONNode) (*Union, error) { if !ok { return nil, fmt.Errorf("union name is %T, not a string", unionNode.At(0).Get()) } - unionCRC, ok := unionNode.At(unionNode.Len() - 1).At(crcField).Get().(string) - if !ok { - return nil, fmt.Errorf("union crc invalid or missing") + var unionCRC string + if unionNode.At(unionNode.Len()-1).GetType() == jsongo.TypeMap { + unionCRC = unionNode.At(unionNode.Len() - 1).At(crcField).Get().(string) } union := Union{ @@ -284,8 +284,8 @@ func parseUnion(ctx *context, unionNode *jsongo.JSONNode) (*Union, error) { CRC: unionCRC, } - // loop through union fields, skip first (name) and last (crc) - for j := 1; j < unionNode.Len()-1; j++ { + // loop through union fields, skip first (name) + for j := 1; j < unionNode.Len(); j++ { if unionNode.At(j).GetType() == jsongo.TypeArray { fieldNode := unionNode.At(j) @@ -311,9 +311,9 @@ func parseType(ctx *context, typeNode *jsongo.JSONNode) (*Type, error) { if !ok { return nil, fmt.Errorf("type name is %T, not a string", typeNode.At(0).Get()) } - typeCRC, ok := typeNode.At(typeNode.Len() - 1).At(crcField).Get().(string) - if !ok { - return nil, fmt.Errorf("type crc invalid or missing") + var typeCRC string + if lastField := typeNode.At(typeNode.Len() - 1); lastField.GetType() == jsongo.TypeMap { + typeCRC = lastField.At(crcField).Get().(string) } typ := Type{ @@ -321,8 +321,8 @@ func parseType(ctx *context, typeNode *jsongo.JSONNode) (*Type, error) { CRC: typeCRC, } - // loop through type fields, skip first (name) and last (crc) - for j := 1; j < typeNode.Len()-1; j++ { + // loop through type fields, skip first (name) + for j := 1; j < typeNode.Len(); j++ { if typeNode.At(j).GetType() == jsongo.TypeArray { fieldNode := typeNode.At(j) diff --git a/examples/binapi/acl/acl.ba.go b/examples/binapi/acl/acl.ba.go index a00918e..6708e74 100644 --- a/examples/binapi/acl/acl.ba.go +++ b/examples/binapi/acl/acl.ba.go @@ -737,7 +737,7 @@ func AllMessages() []api.Message { } } -// Service represents services in VPP binary API. +// Service represents VPP binary API services in acl module. type Service interface { DumpACL(ctx context.Context, in *ACLDump) ([]*ACLDetails, error) DumpACLInterfaceEtypeWhitelist(ctx context.Context, in *ACLInterfaceEtypeWhitelistDump) ([]*ACLInterfaceEtypeWhitelistDetails, error) diff --git a/examples/binapi/af_packet/af_packet.ba.go b/examples/binapi/af_packet/af_packet.ba.go index 96fd02a..f4e47d0 100644 --- a/examples/binapi/af_packet/af_packet.ba.go +++ b/examples/binapi/af_packet/af_packet.ba.go @@ -188,7 +188,7 @@ func AllMessages() []api.Message { } } -// Service represents services in VPP binary API. +// Service represents VPP binary API services in af_packet module. type Service interface { DumpAfPacket(ctx context.Context, in *AfPacketDump) ([]*AfPacketDetails, error) AfPacketCreate(ctx context.Context, in *AfPacketCreate) (*AfPacketCreateReply, error) diff --git a/examples/binapi/interfaces/interfaces.ba.go b/examples/binapi/interfaces/interfaces.ba.go index 1f369de..e4ad5f5 100644 --- a/examples/binapi/interfaces/interfaces.ba.go +++ b/examples/binapi/interfaces/interfaces.ba.go @@ -1006,7 +1006,7 @@ func AllMessages() []api.Message { } } -// Service represents services in VPP binary API. +// Service represents VPP binary API services in interface module. type Service interface { DumpSwInterface(ctx context.Context, in *SwInterfaceDump) ([]*SwInterfaceDetails, error) DumpSwInterfaceRxPlacement(ctx context.Context, in *SwInterfaceRxPlacementDump) ([]*SwInterfaceRxPlacementDetails, error) diff --git a/examples/binapi/ip/ip.ba.go b/examples/binapi/ip/ip.ba.go index 71a6476..58a9aaa 100644 --- a/examples/binapi/ip/ip.ba.go +++ b/examples/binapi/ip/ip.ba.go @@ -2073,7 +2073,7 @@ func AllMessages() []api.Message { } } -// Service represents services in VPP binary API. +// Service represents VPP binary API services in ip module. type Service interface { DumpIP6Fib(ctx context.Context, in *IP6FibDump) ([]*IP6FibDetails, error) DumpIP6Mfib(ctx context.Context, in *IP6MfibDump) ([]*IP6MfibDetails, error) diff --git a/examples/binapi/memclnt/memclnt.ba.go b/examples/binapi/memclnt/memclnt.ba.go index e7395c7..0fa28dd 100644 --- a/examples/binapi/memclnt/memclnt.ba.go +++ b/examples/binapi/memclnt/memclnt.ba.go @@ -474,7 +474,7 @@ func AllMessages() []api.Message { } } -// Service represents services in VPP binary API. +// Service represents VPP binary API services in memclnt module. type Service interface { APIVersions(ctx context.Context, in *APIVersions) (*APIVersionsReply, error) GetFirstMsgID(ctx context.Context, in *GetFirstMsgID) (*GetFirstMsgIDReply, error) diff --git a/examples/binapi/memif/memif.ba.go b/examples/binapi/memif/memif.ba.go index 1ac0b0a..4123ad8 100644 --- a/examples/binapi/memif/memif.ba.go +++ b/examples/binapi/memif/memif.ba.go @@ -238,7 +238,7 @@ func AllMessages() []api.Message { } } -// Service represents services in VPP binary API. +// Service represents VPP binary API services in memif module. type Service interface { DumpMemif(ctx context.Context, in *MemifDump) ([]*MemifDetails, error) DumpMemifSocketFilename(ctx context.Context, in *MemifSocketFilenameDump) ([]*MemifSocketFilenameDetails, error) diff --git a/examples/binapi/vpe/vpe.ba.go b/examples/binapi/vpe/vpe.ba.go index 25707fc..c475a70 100644 --- a/examples/binapi/vpe/vpe.ba.go +++ b/examples/binapi/vpe/vpe.ba.go @@ -390,7 +390,7 @@ func AllMessages() []api.Message { } } -// Service represents services in VPP binary API. +// Service represents VPP binary API services in vpe module. type Service interface { AddNodeNext(ctx context.Context, in *AddNodeNext) (*AddNodeNextReply, error) Cli(ctx context.Context, in *Cli) (*CliReply, error) |