Skip to content

Compile protos from multiple packages #42

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions protoc-gen-go/testdata/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,15 @@ golden:
nuke: clean

testbuild: regenerate
go test
go test ./...

regenerate:
# Invoke protoc once to generate three independent .pb.go files in the same package.
protoc --go_out=. multi/multi{1,2,3}.proto
protoc --go_out=. multifile/multi{1,2,3}.proto
# Invoke protoc multiple times to build packages that are interdependent.
for dir in $(sort $(dir $(shell find multipkg -name '*.proto'))); do \
protoc --go_out=. $$dir/*.proto; \
done

#extension_test: extension_test.$O
# $(LD) -L. -o $@ $<
Expand Down
2 changes: 1 addition & 1 deletion protoc-gen-go/testdata/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ package testdata
import (
"testing"

multipb "./multi"
multipb "./multifile"
mytestpb "./my_test"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@

syntax = "proto2";

import "multi/multi2.proto";
import "multi/multi3.proto";
import "multifile/multi2.proto";
import "multifile/multi3.proto";

package multitest;

Expand Down
40 changes: 40 additions & 0 deletions protoc-gen-go/testdata/multipkg/bar/bar.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Go support for Protocol Buffers - Google's data interchange format
//
// Copyright 2010 The Go Authors. All rights reserved.
// https://github.com/golang/protobuf
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

syntax = "proto2";

import "multipkg/foo/foo.proto";

package bar;

message Bar {
optional foo.Foo foo = 1;
}
36 changes: 36 additions & 0 deletions protoc-gen-go/testdata/multipkg/foo/foo.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Go support for Protocol Buffers - Google's data interchange format
//
// Copyright 2010 The Go Authors. All rights reserved.
// https://github.com/golang/protobuf
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

syntax = "proto2";

package foo;

message Foo {}
2 changes: 1 addition & 1 deletion protoc-gen-go/testdata/my_test/test.pb.go

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

2 changes: 1 addition & 1 deletion protoc-gen-go/testdata/my_test/test.pb.go.golden
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import proto "github.com/golang/protobuf/proto"
import fmt "fmt"
import math "math"

// discarding unused import multitest2 "multi"
// discarding unused import multitest2 "multifile"

// Reference imports to suppress errors if they are not otherwise used.
var _ = proto.Marshal
Expand Down
2 changes: 1 addition & 1 deletion protoc-gen-go/testdata/my_test/test.proto
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ syntax = "proto2";
package my.test; // dotted package name

//import "imp.proto";
import "multi/multi1.proto"; // unused import
import "multifile/multi1.proto"; // unused import

enum HatType {
// deliberately skipping 0
Expand Down