Permalink
Browse files

really get gogo protobuf working

  • Loading branch information...
peter-edge committed Dec 3, 2015
1 parent 46acd00 commit 44345ef192158d428b21c69ee9f14d5b868c30c0
Showing with 348 additions and 71 deletions.
  1. +17 −5 Makefile
  2. +1 −1 circle.yml
  3. +203 −36 cmd/protoeasy/main.go
  4. +84 −29 plugins.go
  5. +29 −0 protoeasy.go
  6. +3 −0 server_compiler.go
  7. +1 −0 util.go
  8. +10 −0 var.go
View
@@ -28,7 +28,7 @@ PLUGINS := \
export GO15VENDOREXPERIMENT=1
all: build docker-build docker-launch install installplugins proto example-complete
all: integration docker-integration
deps:
GO15VENDOREXPERIMENT=0 go get -d -v $(PKGS)
@@ -68,7 +68,7 @@ proto:
protoeasy --go --grpc --go-import-path go.pedge.io/protoeasy --exclude vendor --exclude example .
find . -name *\.pb\*\.go | grep -v vendor | xargs strip-package-comments
example-complete: install
example-complete:
rm -rf _example-out/complete
protoeasy \
--out=_example-out/complete \
@@ -82,18 +82,22 @@ example-complete: install
--grpc-gateway \
example/complete
go build ./_example-out/complete/go/...
go build ./_example-out/complete/gogo/...
example-proto2: install
example-proto2:
rm -rf _example-out/proto2
protoeasy \
--out=_example-out/proto2 \
--cpp --cpp-rel-out=cpp \
--python --python-rel-out=python \
--go --go-rel-out=go --go-import-path=go.pedge.io/protoeasy/_example-out/proto2/go \
--go-protoc-plugin=gogo \
--gogo --gogo-rel-out=gogo --gogo-import-path=go.pedge.io/protoeasy/_example-out/proto2/gogo \
--grpc \
example/proto2
go build ./_example-out/proto2/go/...
go build ./_example-out/proto2/gogo/...
examples: install installplugins example-complete example-proto2
lint:
go get -v github.com/golang/lint/golint
@@ -149,6 +153,11 @@ docker-launch-proto2:
docker rm -f protoeasy-proto2 || true
docker run -d -p 6789:6789 --name=protoeasy-proto2 quay.io/pedge/protoeasy-proto2
integration: build docker-build docker-launch proto examples
docker-integration: build docker-build
docker run quay.io/pedge/protoeasy make proto examples
.PHONY: \
all \
deps \
@@ -164,6 +173,7 @@ docker-launch-proto2:
proto \
example-complete \
example-proto2 \
examples \
lint \
vet \
errcheck \
@@ -178,4 +188,6 @@ docker-launch-proto2:
docker-build-proto2 \
docker-push-proto2 \
docker-pull-proto2 \
docker-launch-proto2
docker-launch-proto2 \
integration \
docker-integration
View
@@ -6,7 +6,7 @@ dependencies:
- docker build -t quay.io/pedge/protoeasy .
test:
override:
- docker run quay.io/pedge/protoeasy make example-complete example-proto2
- docker run quay.io/pedge/protoeasy make proto examples
deployment:
hub:
branch: master
View
@@ -21,9 +21,11 @@ type appEnv struct {
}
type options struct {
GoModifiers []string
GoPluginType string
OutDirPath string
GoModifiers []string
GoPluginType string
GogoModifiers []string
GogoPluginType string
OutDirPath string
}
func main() {
@@ -55,67 +57,232 @@ func do(appEnvObj interface{}) error {
}
func bindCompileOptions(flagSet *pflag.FlagSet, compileOptions *protoeasy.CompileOptions) {
flagSet.BoolVar(&compileOptions.Grpc, "grpc", false, "Output grpc files.")
flagSet.BoolVar(&compileOptions.GrpcGateway, "grpc-gateway", false, "Output grpc-gateway .gw.go files.")
flagSet.BoolVar(&compileOptions.NoDefaultIncludes, "no-default-includes", false, "Do not import the default include directories, implies --go-no-default-modifiers.")
flagSet.StringSliceVar(&compileOptions.ExcludePattern, "exclude", []string{}, "Exclude file patterns.")
flagSet.StringVar(&compileOptions.RelContext, "context", "", "The directory we are within, must be relative. This directory will be the base of the include path.")
flagSet.BoolVar(
&compileOptions.Grpc,
"grpc",
false,
"Output grpc files.",
)
flagSet.BoolVar(
&compileOptions.GrpcGateway,
"grpc-gateway",
false,
"Output grpc-gateway files.",
)
flagSet.BoolVar(
&compileOptions.NoDefaultIncludes,
"no-default-includes",
false,
"Do not import the default include directories, implies --go-no-default-modifiers,--gogo-no-default-modifiers.",
)
flagSet.StringSliceVar(
&compileOptions.ExcludePattern,
"exclude",
[]string{},
"Exclude file patterns.",
)
flagSet.StringVar(
&compileOptions.RelContext,
"context",
"",
"The directory we are within, must be relative. This directory will be the base of the include path.",
)
flagSet.BoolVar(&compileOptions.Cpp, "cpp", false, "Output cpp files.")
flagSet.StringVar(&compileOptions.CppRelOut, "cpp-rel-out", "", "The directory, relative to the output directory, to output cpp files.")
flagSet.BoolVar(
&compileOptions.Cpp,
"cpp",
false,
"Output cpp files.",
)
flagSet.StringVar(
&compileOptions.CppRelOut,
"cpp-rel-out",
"",
"The directory, relative to the output directory, to output cpp files.",
)
flagSet.BoolVar(&compileOptions.Csharp, "csharp", false, "Output csharp files.")
flagSet.StringVar(&compileOptions.CsharpRelOut, "csharp-rel-out", "", "The directory, relative to the output directory, to output csharp files.")
flagSet.BoolVar(
&compileOptions.Csharp,
"csharp",
false,
"Output csharp files.",
)
flagSet.StringVar(
&compileOptions.CsharpRelOut,
"csharp-rel-out",
"",
"The directory, relative to the output directory, to output csharp files.",
)
flagSet.BoolVar(&compileOptions.Go, "go", false, "Output go files.")
flagSet.StringVar(&compileOptions.GoRelOut, "go-rel-out", "", "The directory, relative to the output directory, to output go files.")
flagSet.StringVar(&compileOptions.GoImportPath, "go-import-path", "", "Go package.")
flagSet.BoolVar(&compileOptions.GoNoDefaultModifiers, "go-no-default-modifiers", false, "Do not set the default Mfile=package modifiers for --go_out.")
flagSet.BoolVar(
&compileOptions.Go,
"go",
false,
"Output go files.",
)
flagSet.StringVar(
&compileOptions.GoRelOut,
"go-rel-out",
"",
"The directory, relative to the output directory, to output go files.",
)
flagSet.StringVar(
&compileOptions.GoImportPath,
"go-import-path",
"",
"Go package.",
)
flagSet.BoolVar(
&compileOptions.GoNoDefaultModifiers,
"go-no-default-modifiers",
false,
"Do not set the default Mfile=package modifiers for --go_out.",
)
flagSet.BoolVar(&compileOptions.Objc, "objc", false, "Output objc files.")
flagSet.StringVar(&compileOptions.ObjcRelOut, "objc-rel-out", "", "The directory, relative to the output directory, to output objc files.")
flagSet.BoolVar(
&compileOptions.Gogo,
"gogo",
false,
"Output gogo files.",
)
flagSet.StringVar(
&compileOptions.GogoRelOut,
"gogo-rel-out",
"",
"The directory, relative to the output directory, to output gogo files.",
)
flagSet.StringVar(
&compileOptions.GogoImportPath,
"gogo-import-path",
"",
"Gogo package.",
)
flagSet.BoolVar(
&compileOptions.GogoNoDefaultModifiers,
"gogo-no-default-modifiers",
false,
"Do not set the default Mfile=package modifiers for --gogo_out.",
)
flagSet.BoolVar(&compileOptions.Python, "python", false, "Output python files.")
flagSet.StringVar(&compileOptions.PythonRelOut, "python-rel-out", "", "The directory, relative to the output directory, to output python files.")
flagSet.BoolVar(
&compileOptions.Objc,
"objc",
false,
"Output objc files.",
)
flagSet.StringVar(
&compileOptions.ObjcRelOut,
"objc-rel-out",
"",
"The directory, relative to the output directory, to output objc files.",
)
flagSet.BoolVar(&compileOptions.Ruby, "ruby", false, "Output ruby files.")
flagSet.StringVar(&compileOptions.RubyRelOut, "ruby-rel-out", "", "The directory, relative to the output directory, to output ruby files.")
flagSet.BoolVar(
&compileOptions.Python,
"python",
false,
"Output python files.",
)
flagSet.StringVar(
&compileOptions.PythonRelOut,
"python-rel-out",
"",
"The directory, relative to the output directory, to output python files.",
)
flagSet.BoolVar(
&compileOptions.Ruby,
"ruby",
false,
"Output ruby files.",
)
flagSet.StringVar(
&compileOptions.RubyRelOut,
"ruby-rel-out",
"",
"The directory, relative to the output directory, to output ruby files.",
)
}
func bindOptions(flagSet *pflag.FlagSet, options *options) {
flagSet.StringSliceVar(&options.GoModifiers, "go-modifier", []string{}, "Extra Mfile=package modifiers for --go_out, specify just as file=package to this flag.")
flagSet.StringVar(&options.GoPluginType, "go-protoc-plugin", "go", fmt.Sprintf("The go protoc plugin to use, allowed values are %s, if not go, --go-no-default-modifiers is implied.", strings.Join(protoeasy.AllGoPluginTypeSimpleStrings(), ",")))
flagSet.StringVar(&options.OutDirPath, "out", "", "Customize out directory path.")
flagSet.StringSliceVar(
&options.GoModifiers,
"go-modifier",
[]string{},
"Extra Mfile=package modifiers for --go_out, specify just as file=package to this flag.",
)
flagSet.StringVar(
&options.GoPluginType,
"go-plugin",
"go",
fmt.Sprintf("The go protoc plugin to use, allowed values are %s.", strings.Join(protoeasy.AllGoPluginTypeSimpleStrings(), ",")),
)
flagSet.StringSliceVar(
&options.GogoModifiers,
"gogo-modifier",
[]string{},
"Extra Mfile=package modifiers for --gogo_out, specify just as file=package to this flag.",
)
flagSet.StringVar(
&options.GogoPluginType,
"gogo-plugin",
"gogofast",
fmt.Sprintf("The gogo protoc plugin to use, allowed values are %s.", strings.Join(protoeasy.AllGogoPluginTypeSimpleStrings(), ",")),
)
flagSet.StringVar(
&options.OutDirPath,
"out",
"",
"Customize out directory path.",
)
}
func optionsToCompileOptions(options *options, compileOptions *protoeasy.CompileOptions) error {
if strings.ToLower(options.GoPluginType) == "none" {
return fmt.Errorf("invalid value for --go-protoc-plugin: %s", options.GoPluginType)
return fmt.Errorf("invalid value for --go-plugin: %s", options.GoPluginType)
}
goPluginType, err := protoeasy.GoPluginTypeSimpleValueOf(options.GoPluginType)
if err != nil {
return err
}
compileOptions.GoPluginType = goPluginType
goModifiers, err := getModifiers(options.GoModifiers)
if err != nil {
return err
}
compileOptions.GoModifiers = goModifiers
if strings.ToLower(options.GogoPluginType) == "none" {
return fmt.Errorf("invalid value for --gogo-plugin: %s", options.GogoPluginType)
}
gogoPluginType, err := protoeasy.GogoPluginTypeSimpleValueOf(options.GogoPluginType)
if err != nil {
return err
}
compileOptions.GogoPluginType = gogoPluginType
gogoModifiers, err := getModifiers(options.GogoModifiers)
if err != nil {
return err
}
compileOptions.GogoModifiers = gogoModifiers
// TODO(pedge): this should not be in this function
// TODO(pedge): duplicated logic in goPlugin struct
if goPluginType != protoeasy.GoPluginType_GO_PLUGIN_TYPE_GO {
if compileOptions.NoDefaultIncludes {
compileOptions.GoNoDefaultModifiers = true
compileOptions.GogoNoDefaultModifiers = true
}
return nil
}
func getModifiers(modifierStrings []string) (map[string]string, error) {
modifiers := make(map[string]string)
for _, modifierString := range options.GoModifiers {
for _, modifierString := range modifierStrings {
split := strings.SplitN(modifierString, "=", 2)
if len(split) != 2 {
return fmt.Errorf("invalid valid for --go-modifier: %s", modifierString)
return nil, fmt.Errorf("invalid go modifier value: %s", modifierString)
}
modifiers[split[0]] = split[1]
}
compileOptions.GoModifiers = modifiers
// TODO(pedge): this should not be in this function
// TODO(pedge): duplicated logic in goPlugin struct
if compileOptions.NoDefaultIncludes {
compileOptions.GoNoDefaultModifiers = true
}
return nil
return modifiers, nil
}
func run(appEnv *appEnv, options *options, compileOptions *protoeasy.CompileOptions, dirPath string) error {
Oops, something went wrong.

0 comments on commit 44345ef

Please sign in to comment.