Skip to content
This repository has been archived by the owner on Jan 26, 2018. It is now read-only.

Only build common protos with --grpc option for LRO. #109

Merged
merged 5 commits into from
Sep 12, 2016
Merged
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
2 changes: 1 addition & 1 deletion config/common_protos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ packages:
version: ''

# semver is the semantic version of the common protos package.
semver: 1.3.2
semver: 1.3.4
2 changes: 1 addition & 1 deletion config/dependencies.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ protobuf:

googleapis_common_protos:
python:
version: '1.3.2'
version: '1.3.4'
ruby:
version: '1.2.0'

Expand Down
16 changes: 11 additions & 5 deletions lib/api_repo.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ var DEFAULT_PROTO_COMPILER = 'protoc';
// Python builds using grpcio-tools.
var NO_PROTOC_PLUGIN = ['nodejs', 'java', 'python'];

// common protos for which we build gRPC service methods
var COMMON_GRPC_PROTOS = ['operations.proto', 'bytestream.proto'];

// the default include path, where install the protobuf runtime installs its
// protos.
var DEFAULT_INCLUDE_PATH = Object.freeze(['/usr/local/include']);
Expand Down Expand Up @@ -1018,11 +1021,14 @@ ApiRepo.prototype._makeProtocFunc = function _makeProtocFunc(opts, language) {
pluginOption = '--plugin=';
} else {
args.push('--' + language + '_out=' + outDir);
if (language === 'python') {
// required per https://github.com/grpc/grpc/issues/7857
args.push('--grpc_python_out=' + outDir);
} else {
args.push('--grpc_out=' + outDir);
if (!opts.buildCommonProtos ||
_.includes(COMMON_GRPC_PROTOS, protoPath)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't this the path from the proto's rootdir (i.e. 'google/longrunning/operations.proto')?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it's just the last element. pkg has the path.

if (language === 'python') {
// required per https://github.com/grpc/grpc/issues/7857
args.push('--grpc_python_out=' + outDir);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought we decided not to do this in order to support GAE?

My understanding was that this required a more complex change to generate both gRPC and gRPC-less modules.

Copy link
Contributor

@geigerj geigerj Sep 12, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After offline discussion, I understand that this is actually an improvement over the current state of master, where every common proto is being built with the gRPC plugin (and hence is potentially GAE-incompatible).

} else {
args.push('--grpc_out=' + outDir);
}
}
}
if (!_.includes(NO_PROTOC_PLUGIN, language)) {
Expand Down
31 changes: 21 additions & 10 deletions test/api_repo.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,17 +133,17 @@ describe('ApiRepo', function() {
});
});
describe('configured for python', function() {
beforeEach(function() {
var testBins = ['protoc', 'grpc_python_plugin'];
fakes = addFakeBinsToPath.apply(null, testBins);
repo = new ApiRepo({
env: {PATH: fakes.path},
languages: ['python'],
templateRoot: path.join(__dirname, '..', 'templates')
});
getsGoodZipFrom(repo.zipUrl);
});
describe('method `buildGaxPackages`', function() {
beforeEach(function() {
var testBins = ['protoc', 'grpc_python_plugin'];
fakes = addFakeBinsToPath.apply(null, testBins);
repo = new ApiRepo({
env: {PATH: fakes.path},
languages: ['python'],
templateRoot: path.join(__dirname, '..', 'templates')
});
getsGoodZipFrom(repo.zipUrl);
});
it('should succeed with unrecognized apis', function(done) {
repo.on('error', function(err) {
expect(err).to.not.be.null();
Expand All @@ -164,6 +164,17 @@ describe('ApiRepo', function() {
});
});
describe('method `buildCommonProtoPkgs`', function() {
beforeEach(function() {
var testBins = ['protoc', 'grpc_python_plugin'];
fakes = addFakeBinsToPath.apply(null, testBins);
repo = new ApiRepo({
buildCommonProtos: true,
env: {PATH: fakes.path},
languages: ['python'],
templateRoot: path.join(__dirname, '..', 'templates')
});
getsGoodZipFrom(repo.zipUrl);
});
it('should pass', function(done) {
repo.on('error', function() {
throw new Error('should not be reached');
Expand Down
4 changes: 2 additions & 2 deletions test/fixtures/fake_protoc
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ main() {
local proto_path=${!#}
local out_dir=$(echo "$@" | sed 's/.*--grpc_out=\([^ ]*\).*/\1/')
# fix out_dir in case protoc was run for the go plugin
local out_dir=$(echo "$out_dir" | sed 's/.*--go_out=plugins=grpc:\([^ ]*\).*/\1/')
out_dir=$(echo "$out_dir" | sed 's/.*--go_out=plugins=grpc:\([^ ]*\).*/\1/')
# fix out_dir in case protoc was run for the python plugin
local out_dir=$(echo "$out_dir" | sed 's/.*--grpc_python_out=\([^ ]*\).*/\1/')
out_dir=$(echo "$out_dir" | sed 's/.*--python_out=\([^ ]*\).*/\1/')
echo "out_dir is $out_dir" 1>&2;
local out_proto_path=${out_dir}/$proto_path
local out_parent=$(dirname $out_proto_path)
Expand Down