Skip to content

Commit

Permalink
Update build configurations to use Go modules. (#142)
Browse files Browse the repository at this point in the history
* Update build configurations to use Go modules.

* Remove unneeded proto compilation options.

* Full go get (./...) for all nested projects.
  • Loading branch information
timburks committed Aug 15, 2019
1 parent 2cd1770 commit ab0dd09
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 85 deletions.
29 changes: 6 additions & 23 deletions COMPILE-PROTOS.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 2 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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

21 changes: 12 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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.
Expand All @@ -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.
Expand Down
5 changes: 0 additions & 5 deletions extensions/COMPILE-EXTENSION.sh

This file was deleted.

64 changes: 32 additions & 32 deletions extensions/extension.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 4 additions & 6 deletions extensions/sample/Makefile
Original file line number Diff line number Diff line change
@@ -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
8 changes: 6 additions & 2 deletions generate-gnostic/generate-extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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")
Expand Down
9 changes: 9 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -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
)
7 changes: 7 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -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=

0 comments on commit ab0dd09

Please sign in to comment.