From ab0dd09aa10e2952b28e12ecd35681b20463ebab Mon Sep 17 00:00:00 2001 From: Tim Burks Date: Thu, 15 Aug 2019 14:21:28 -0700 Subject: [PATCH] Update build configurations to use Go modules. (#142) * Update build configurations to use Go modules. * Remove unneeded proto compilation options. * Full go get (./...) for all nested projects. --- COMPILE-PROTOS.sh | 29 +++--------- Makefile | 10 +--- README.md | 21 +++++---- extensions/COMPILE-EXTENSION.sh | 5 -- extensions/extension.pb.go | 64 +++++++++++++------------- extensions/sample/Makefile | 10 ++-- generate-gnostic/generate-extension.go | 8 +++- go.mod | 9 ++++ go.sum | 7 +++ 9 files changed, 78 insertions(+), 85 deletions(-) delete mode 100755 extensions/COMPILE-EXTENSION.sh create mode 100644 go.mod create mode 100644 go.sum diff --git a/COMPILE-PROTOS.sh b/COMPILE-PROTOS.sh index c8964f60..5653fdcd 100755 --- a/COMPILE-PROTOS.sh +++ b/COMPILE-PROTOS.sh @@ -17,26 +17,9 @@ go get github.com/golang/protobuf/protoc-gen-go -protoc \ ---go_out=Mgoogle/protobuf/any.proto=github.com/golang/protobuf/ptypes/any:. \ -OpenAPIv2/OpenAPIv2.proto - -protoc \ ---go_out=Mgoogle/protobuf/any.proto=github.com/golang/protobuf/ptypes/any:. \ -OpenAPIv3/OpenAPIv3.proto - -protoc \ ---go_out=Mgoogle/protobuf/any.proto=github.com/golang/protobuf/ptypes/any:. \ -discovery/discovery.proto - -protoc \ ---go_out=Mgoogle/protobuf/any.proto=github.com/golang/protobuf/ptypes/any:. \ -plugins/plugin.proto - -protoc \ ---go_out=Mgoogle/protobuf/any.proto=github.com/golang/protobuf/ptypes/any:. \ -extensions/extension.proto - -protoc \ ---go_out=Mgoogle/protobuf/any.proto=github.com/golang/protobuf/ptypes/any:. \ -surface/surface.proto +protoc --go_out=. OpenAPIv2/OpenAPIv2.proto +protoc --go_out=. OpenAPIv3/OpenAPIv3.proto +protoc --go_out=. discovery/discovery.proto +protoc --go_out=. plugins/plugin.proto +protoc --go_out=. extensions/extension.proto +protoc --go_out=. surface/surface.proto diff --git a/Makefile b/Makefile index 1702d6d2..06fa030d 100644 --- a/Makefile +++ b/Makefile @@ -1,13 +1,7 @@ build: ./COMPILE-PROTOS.sh - go get - go install - cd generate-gnostic; go get; go install - cd apps/disco; go get; go install - cd apps/report; go get; go install - cd apps/petstore-builder; go get; go install - cd plugins/gnostic-summary; go get; go install - cd plugins/gnostic-analyze; go get; go install + go get ./... + go install ./... cd extensions/sample; make diff --git a/README.md b/README.md index 9ddcac45..f2bcc0a9 100644 --- a/README.md +++ b/README.md @@ -44,9 +44,14 @@ and the [Google Protocol Buffer Compiler](https://github.com/google/protobuf). ## Installation -1. Get this package by downloading it with `go get`. +The following instructions are for installing gnostic using +[Go modules](https://blog.golang.org/using-go-modules), +supported by Go 1.11 and later. - go get github.com/googleapis/gnostic +1. Get this package by downloading it with `git clone`. + + git clone https://github.com/googleapis/gnostic + cd gnostic 2. [Optional] Build and run the gnostic compiler generator. This uses JSON schemas to generate Protocol Buffer language files @@ -57,9 +62,7 @@ the generated protocol buffer models. Pre-generated versions of these files are checked into the directories named OpenAPIv2, OpenAPIv3, and discovery. - cd $GOPATH/src/github.com/googleapis/gnostic/generate-gnostic - go install - cd .. + go install ./generate-gnostic generate-gnostic --v2 generate-gnostic --v3 generate-gnostic --discovery @@ -70,15 +73,15 @@ and the Go protoc plugin. You can get protoc [here](https://github.com/google/protobuf). You can install the plugin with this command: - go get -u github.com/golang/protobuf/protoc-gen-go + go get github.com/golang/protobuf/protoc-gen-go -Then use the following to compile the Gnostic Protocol Buffer models: +Then use the following to compile the gnostic Protocol Buffer models: ./COMPILE-PROTOS.sh 4. Build **gnostic**. - go install github.com/googleapis/gnostic + go install . 5. Run **gnostic**. This sample invocation creates a file in the current directory named "petstore.pb" that contains a binary Protocol Buffer description of a sample API. @@ -93,7 +96,7 @@ Protocol Buffer description. This is mainly for use in testing and debugging. 7. For a sample application, see apps/report. - go install github.com/googleapis/gnostic/apps/report + go install ./apps/report report petstore.pb 8. **gnostic** supports plugins. Some are already implemented in the `plugins` directory. diff --git a/extensions/COMPILE-EXTENSION.sh b/extensions/COMPILE-EXTENSION.sh deleted file mode 100755 index 68d02a02..00000000 --- a/extensions/COMPILE-EXTENSION.sh +++ /dev/null @@ -1,5 +0,0 @@ -go get github.com/golang/protobuf/protoc-gen-go - -protoc \ ---go_out=Mgoogle/protobuf/any.proto=github.com/golang/protobuf/ptypes/any:. *.proto - diff --git a/extensions/extension.pb.go b/extensions/extension.pb.go index 6f4b97f4..432dc06e 100644 --- a/extensions/extension.pb.go +++ b/extensions/extension.pb.go @@ -1,5 +1,5 @@ // Code generated by protoc-gen-go. DO NOT EDIT. -// source: extension.proto +// source: extensions/extension.proto package openapiextension_v1 @@ -38,7 +38,7 @@ func (m *Version) Reset() { *m = Version{} } func (m *Version) String() string { return proto.CompactTextString(m) } func (*Version) ProtoMessage() {} func (*Version) Descriptor() ([]byte, []int) { - return fileDescriptor_2d065b70573ae483, []int{0} + return fileDescriptor_661e47e790f76671, []int{0} } func (m *Version) XXX_Unmarshal(b []byte) error { @@ -103,7 +103,7 @@ func (m *ExtensionHandlerRequest) Reset() { *m = ExtensionHandlerRequest func (m *ExtensionHandlerRequest) String() string { return proto.CompactTextString(m) } func (*ExtensionHandlerRequest) ProtoMessage() {} func (*ExtensionHandlerRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_2d065b70573ae483, []int{1} + return fileDescriptor_661e47e790f76671, []int{1} } func (m *ExtensionHandlerRequest) XXX_Unmarshal(b []byte) error { @@ -163,7 +163,7 @@ func (m *ExtensionHandlerResponse) Reset() { *m = ExtensionHandlerRespon func (m *ExtensionHandlerResponse) String() string { return proto.CompactTextString(m) } func (*ExtensionHandlerResponse) ProtoMessage() {} func (*ExtensionHandlerResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_2d065b70573ae483, []int{2} + return fileDescriptor_661e47e790f76671, []int{2} } func (m *ExtensionHandlerResponse) XXX_Unmarshal(b []byte) error { @@ -221,7 +221,7 @@ func (m *Wrapper) Reset() { *m = Wrapper{} } func (m *Wrapper) String() string { return proto.CompactTextString(m) } func (*Wrapper) ProtoMessage() {} func (*Wrapper) Descriptor() ([]byte, []int) { - return fileDescriptor_2d065b70573ae483, []int{3} + return fileDescriptor_661e47e790f76671, []int{3} } func (m *Wrapper) XXX_Unmarshal(b []byte) error { @@ -270,31 +270,31 @@ func init() { proto.RegisterType((*Wrapper)(nil), "openapiextension.v1.Wrapper") } -func init() { proto.RegisterFile("extension.proto", fileDescriptor_2d065b70573ae483) } - -var fileDescriptor_2d065b70573ae483 = []byte{ - // 357 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x91, 0x4d, 0x4b, 0xc3, 0x40, - 0x18, 0x84, 0x49, 0xbf, 0x62, 0x56, 0x6c, 0x65, 0x2d, 0x1a, 0xc5, 0x43, 0x09, 0x08, 0x45, 0x64, - 0x4b, 0x15, 0xbc, 0xb7, 0x50, 0xd4, 0x8b, 0x2d, 0x7b, 0xa8, 0x37, 0xcb, 0x36, 0x7d, 0x9b, 0x46, - 0x92, 0xdd, 0x75, 0xf3, 0x61, 0xfb, 0x57, 0x3c, 0xfa, 0x4b, 0x25, 0xbb, 0x49, 0x3d, 0xa8, 0xb7, - 0xcc, 0xc3, 0x24, 0xef, 0xcc, 0x04, 0x75, 0x60, 0x9b, 0x02, 0x4f, 0x42, 0xc1, 0x89, 0x54, 0x22, - 0x15, 0xf8, 0x44, 0x48, 0xe0, 0x4c, 0x86, 0x3f, 0x3c, 0x1f, 0x5e, 0x9c, 0x07, 0x42, 0x04, 0x11, - 0x0c, 0xb4, 0x65, 0x99, 0xad, 0x07, 0x8c, 0xef, 0x8c, 0xdf, 0xf3, 0x91, 0x3d, 0x07, 0x55, 0x18, - 0x71, 0x17, 0x35, 0x63, 0xf6, 0x26, 0x94, 0x6b, 0xf5, 0xac, 0x7e, 0x93, 0x1a,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fd, 0x3c, 0xbe, 0x41, 0x6d, 0xa1, 0x02, 0x12, 0x70, 0x91, 0xa4, 0xa1, 0x4f, 0xf2, - 0xe1, 0x18, 0x4f, 0x25, 0xf0, 0xd1, 0xec, 0x69, 0x5f, 0x77, 0x3e, 0x9c, 0x59, 0x5f, 0xb5, 0xfa, - 0x74, 0x34, 0x59, 0xb6, 0x74, 0xc4, 0xbb, 0xef, 0x00, 0x00, 0x00, 0xff, 0xff, 0x84, 0x5c, 0x6b, - 0x80, 0x51, 0x02, 0x00, 0x00, +func init() { proto.RegisterFile("extensions/extension.proto", fileDescriptor_661e47e790f76671) } + +var fileDescriptor_661e47e790f76671 = []byte{ + // 362 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x91, 0x4d, 0x4b, 0xeb, 0x40, + 0x18, 0x85, 0x49, 0xbf, 0x72, 0x33, 0x97, 0xdb, 0x2b, 0x63, 0xd1, 0x58, 0x5c, 0x94, 0x80, 0x50, + 0x44, 0xa6, 0x54, 0xc1, 0x7d, 0x0b, 0x45, 0xdd, 0xd8, 0x32, 0x8b, 0xba, 0xb3, 0x4c, 0xd3, 0xb7, + 0x69, 0x24, 0x99, 0x19, 0x27, 0x1f, 0xb6, 0x7f, 0xc5, 0xa5, 0xbf, 0x54, 0x32, 0x93, 0xc4, 0x85, + 0xba, 0x9b, 0xf3, 0x70, 0xda, 0xf7, 0x9c, 0x13, 0xd4, 0x87, 0x7d, 0x0a, 0x3c, 0x09, 0x05, 0x4f, + 0x46, 0xf5, 0x93, 0x48, 0x25, 0x52, 0x81, 0x8f, 0x85, 0x04, 0xce, 0x64, 0xf8, 0xc5, 0xf3, 0x71, + 0xff, 0x2c, 0x10, 0x22, 0x88, 0x60, 0xa4, 0x2d, 0xeb, 0x6c, 0x3b, 0x62, 0xfc, 0x60, 0xfc, 0x9e, + 0x8f, 0xec, 0x25, 0xa8, 0xc2, 0x88, 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1f, 0x59, 0x0c, 0x18, + 0xa3, 0xd6, 0x81, 0xc5, 0x91, 0x3e, 0xeb, 0x50, 0xfd, 0x9e, 0x5e, 0xa1, 0xae, 0x50, 0x01, 0x09, + 0xb8, 0x48, 0xd2, 0xd0, 0x27, 0xf9, 0x78, 0x8a, 0xe7, 0x12, 0xf8, 0x64, 0xf1, 0x50, 0xd7, 0x5d, + 0x8e, 0x17, 0xd6, 0x47, 0xa3, 0x39, 0x9f, 0xcc, 0xd6, 0x1d, 0x1d, 0xf1, 0xe6, 0x33, 0x00, 0x00, + 0xff, 0xff, 0xeb, 0xf3, 0xfa, 0x65, 0x5c, 0x02, 0x00, 0x00, } diff --git a/extensions/sample/Makefile b/extensions/sample/Makefile index bf8b1cd8..b45f3795 100755 --- a/extensions/sample/Makefile +++ b/extensions/sample/Makefile @@ -1,10 +1,8 @@ build: - go get github.com/golang/protobuf/protoc-gen-go - cd ..; ./COMPILE-EXTENSION.sh - generate-gnostic --extension x-sampleone.json --out_dir=$(GOPATH)/src/github.com/googleapis/gnostic/extensions/sample/generated - cd generated/gnostic-x-sampleone/proto; protoc --go_out=Mgoogle/protobuf/any.proto=github.com/golang/protobuf/ptypes/any:. *.proto + generate-gnostic --extension x-sampleone.json --out_dir=generated + cd generated/gnostic-x-sampleone/proto; protoc --go_out=. *.proto cd generated/gnostic-x-sampleone; go get; go install - generate-gnostic --extension x-sampletwo.json --out_dir=$(GOPATH)/src/github.com/googleapis/gnostic/extensions/sample/generated - cd generated/gnostic-x-sampletwo/proto; protoc --go_out=Mgoogle/protobuf/any.proto=github.com/golang/protobuf/ptypes/any:. *.proto + generate-gnostic --extension x-sampletwo.json --out_dir=generated + cd generated/gnostic-x-sampletwo/proto; protoc --go_out=. *.proto cd generated/gnostic-x-sampletwo; go get; go install diff --git a/generate-gnostic/generate-extension.go b/generate-gnostic/generate-extension.go index 87cfa462..8050d017 100644 --- a/generate-gnostic/generate-extension.go +++ b/generate-gnostic/generate-extension.go @@ -273,7 +273,11 @@ func GenerateExtension(schemaFile string, outDir string) error { err = exec.Command(runtime.GOROOT()+"/bin/gofmt", "-w", goFilename).Run() // generate the main file. - outDirRelativeToGoPathSrc := strings.Replace(outDir, path.Join(os.Getenv("GOPATH"), "src")+"/", "", 1) + + // TODO: This path is currently fixed to the location of the samples. + // Can we make it relative, perhaps with an option or by generating + // a go.mod file for the generated extension handler? + outDirRelativeToPackageRoot := "github.com/googleapis/gnostic/extensions/sample/" + outDir var extensionNameKeys []string for k := range extensionNameToMessageName { @@ -298,7 +302,7 @@ func GenerateExtension(schemaFile string, outDir string) error { "github.com/googleapis/gnostic/extensions", "github.com/googleapis/gnostic/compiler", "gopkg.in/yaml.v2", - outDirRelativeToGoPathSrc + "/" + "proto", + outDirRelativeToPackageRoot + "/" + "proto", } if wrapperTypeIncluded { imports = append(imports, "github.com/golang/protobuf/ptypes/wrappers") diff --git a/go.mod b/go.mod new file mode 100644 index 00000000..b9be1e3f --- /dev/null +++ b/go.mod @@ -0,0 +1,9 @@ +module github.com/googleapis/gnostic + +go 1.12 + +require ( + github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815 + github.com/golang/protobuf v1.3.2 + gopkg.in/yaml.v2 v2.2.2 +) diff --git a/go.sum b/go.sum new file mode 100644 index 00000000..a28e6da3 --- /dev/null +++ b/go.sum @@ -0,0 +1,7 @@ +github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815 h1:bWDMxwH3px2JBh6AyO7hdCn/PkvCZXii8TGj7sbtEbQ= +github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815/go.mod h1:WwZ+bS3ebgob9U8Nd0kOddGdZWjyMGR8Wziv+TBNwSE= +github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs= +github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=