Skip to content

Commit

Permalink
*: update to use full package name for option go_package in protos
Browse files Browse the repository at this point in the history
Everywhere in the entire tree we use `option go_package` statements like
the following:

```
option go_package = "build";
```

We do this *instead of* using the entire fully-qualified package name,
like:

```
option go_package = "github.com/cockroachdb/cockroach/pkg/build";
```

This is apparently just an error. All the documentation I have seen
(https://github.com/cockroachdb/gogoproto/blob/master/README) suggests
that the fully-qualified package name should be used here. Further, this
caused the `make` build to break after a refactor as the code generator
doesn't know how to import a package like `"roachpb"` (since it should
instead be importing `"github.com/cockroachdb/cockroach/pkg/roachpb"`).

Correct this problem *everywhere* and update the `Makefile` to set
`paths=source_relative` to tell `protoc` that output files should be
placed next to input files.

Epic: none
Release note: None
  • Loading branch information
rickystewart committed Feb 21, 2023
1 parent 4806560 commit d8baef9
Show file tree
Hide file tree
Showing 144 changed files with 152 additions and 154 deletions.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -1359,15 +1359,15 @@ $(ERRORS_PROTO): bin/.submodules-initialized
bin/.go_protobuf_sources: $(GO_PROTOS) $(GOGOPROTO_PROTO) $(ERRORS_PROTO) bin/.bootstrap bin/protoc-gen-gogoroach c-deps/proto-rebuild vendor/modules.txt
$(FIND_RELEVANT) -type f -name '*.pb.go' -exec rm {} +
set -e; for dir in $(sort $(dir $(GO_PROTOS))); do \
buf protoc -Ipkg -I$(GOGO_PROTOBUF_PATH) -I$(COREOS_PATH) -I$(PROMETHEUS_PATH) -I$(GRPC_GATEWAY_GOOGLEAPIS_PATH) -I$(ERRORS_PATH) --gogoroach_out=$(PROTO_MAPPINGS)plugins=grpc,import_prefix=github.com/cockroachdb/cockroach/pkg/:./pkg $$dir/*.proto; \
buf protoc -Ipkg -I$(GOGO_PROTOBUF_PATH) -I$(COREOS_PATH) -I$(PROMETHEUS_PATH) -I$(GRPC_GATEWAY_GOOGLEAPIS_PATH) -I$(ERRORS_PATH) --gogoroach_out=$(PROTO_MAPPINGS)plugins=grpc,import_prefix=github.com/cockroachdb/cockroach/pkg/,paths=source_relative:./pkg $$dir/*.proto; \
done
gofmt -s -w $(GO_SOURCES)
touch $@

bin/.gw_protobuf_sources: $(GW_SERVER_PROTOS) $(GW_TS_PROTOS) $(GO_PROTOS) $(GOGOPROTO_PROTO) $(ERRORS_PROTO) bin/.bootstrap c-deps/proto-rebuild vendor/modules.txt
$(FIND_RELEVANT) -type f -name '*.pb.gw.go' -exec rm {} +
buf protoc -Ipkg -I$(GOGO_PROTOBUF_PATH) -I$(ERRORS_PATH) -I$(COREOS_PATH) -I$(PROMETHEUS_PATH) -I$(GRPC_GATEWAY_GOOGLEAPIS_PATH) --grpc-gateway_out=logtostderr=true,request_context=true:./pkg $(GW_SERVER_PROTOS)
buf protoc -Ipkg -I$(GOGO_PROTOBUF_PATH) -I$(ERRORS_PATH) -I$(COREOS_PATH) -I$(PROMETHEUS_PATH) -I$(GRPC_GATEWAY_GOOGLEAPIS_PATH) --grpc-gateway_out=logtostderr=true,request_context=true:./pkg $(GW_TS_PROTOS)
buf protoc -Ipkg -I$(GOGO_PROTOBUF_PATH) -I$(ERRORS_PATH) -I$(COREOS_PATH) -I$(PROMETHEUS_PATH) -I$(GRPC_GATEWAY_GOOGLEAPIS_PATH) --grpc-gateway_out=logtostderr=true,request_context=true,paths=source_relative:./pkg $(GW_SERVER_PROTOS)
buf protoc -Ipkg -I$(GOGO_PROTOBUF_PATH) -I$(ERRORS_PATH) -I$(COREOS_PATH) -I$(PROMETHEUS_PATH) -I$(GRPC_GATEWAY_GOOGLEAPIS_PATH) --grpc-gateway_out=logtostderr=true,request_context=true,paths=source_relative:./pkg $(GW_TS_PROTOS)
gofmt -s -w $(GW_SOURCES)
@# TODO(jordan,benesch) This can be removed along with the above TODO.
goimports -w $(GW_SOURCES)
Expand Down
2 changes: 1 addition & 1 deletion pkg/acceptance/cluster/testconfig.proto
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

syntax = "proto2";
package cockroach.acceptance.cluster;
option go_package = "cluster";
option go_package = "github.com/cockroachdb/cockroach/pkg/acceptance/cluster";

import "gogoproto/gogo.proto";

Expand Down
2 changes: 1 addition & 1 deletion pkg/blobs/blobspb/blobs.proto
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

syntax = "proto3";
package cockroach.blobs;
option go_package = "blobspb";
option go_package = "github.com/cockroachdb/cockroach/pkg/blobs/blobspb";

// GetRequest is used to read a file from a remote node.
// It's path is specified by `filename`, which can either
Expand Down
2 changes: 1 addition & 1 deletion pkg/build/info.proto
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

syntax = "proto2";
package cockroach.build;
option go_package = "build";
option go_package = "github.com/cockroachdb/cockroach/pkg/build";

import "gogoproto/gogo.proto";

Expand Down
2 changes: 1 addition & 1 deletion pkg/ccl/backupccl/backuppb/backup.proto
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

syntax = "proto3";
package cockroach.ccl.backupccl;
option go_package = "backuppb";
option go_package = "github.com/cockroachdb/cockroach/pkg/ccl/backupccl/backuppb";

import "build/info.proto";
import "cloud/cloudpb/external_storage.proto";
Expand Down
2 changes: 1 addition & 1 deletion pkg/ccl/baseccl/encryption_options.proto
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

syntax = "proto3";
package cockroach.ccl.baseccl;
option go_package = "baseccl";
option go_package = "github.com/cockroachdb/cockroach/pkg/ccl/baseccl";

enum EncryptionKeySource {
// Plain key files.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

syntax = "proto3";
package cockroach.ccl.changefeedccl;
option go_package = "changefeedpb";
option go_package = "github.com/cockroachdb/cockroach/pkg/ccl/changefeedccl/changefeedpb";

// ScheduledExportExecutionArgs is the arguments to the scheduled backup executor.
message ScheduledChangefeedExecutionArgs {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

syntax = "proto3";
package cockroach.ccl.storageccl.engineccl.enginepbccl;
option go_package = "enginepbccl";
option go_package = "github.com/cockroachdb/cockroach/pkg/ccl/storageccl/engineccl/enginepbccl";

enum EncryptionType {
// No encryption.
Expand Down
2 changes: 1 addition & 1 deletion pkg/ccl/storageccl/engineccl/enginepbccl/stats.proto
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

syntax = "proto3";
package cockroach.ccl.storageccl.engineccl.enginepbccl;
option go_package = "enginepbccl";
option go_package = "github.com/cockroachdb/cockroach/pkg/ccl/storageccl/engineccl/enginepbccl";

import "ccl/storageccl/engineccl/enginepbccl/key_registry.proto";

Expand Down
2 changes: 1 addition & 1 deletion pkg/ccl/utilccl/licenseccl/license.proto
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

syntax = "proto3";
package cockroach.ccl.utilccl.licenseccl;
option go_package = "licenseccl";
option go_package = "github.com/cockroachdb/cockroach/pkg/ccl/utilccl/licenseccl";

import "gogoproto/gogo.proto";

Expand Down
2 changes: 1 addition & 1 deletion pkg/cloud/cloudpb/external_storage.proto
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

syntax = "proto3";
package cockroach.cloud.cloudpb;
option go_package = "cloudpb";
option go_package = "github.com/cockroachdb/cockroach/pkg/cloud/cloudpb";

import "gogoproto/gogo.proto";

Expand Down
2 changes: 1 addition & 1 deletion pkg/cloud/externalconn/connectionpb/connection.proto
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

syntax = "proto3";
package cockroach.cloud.externalconn.connectionpb;
option go_package = "connectionpb";
option go_package = "github.com/cockroachdb/cockroach/pkg/cloud/externalconn/connectionpb";

import "gogoproto/gogo.proto";

Expand Down
2 changes: 1 addition & 1 deletion pkg/clusterversion/cluster_version.proto
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

syntax = "proto3";
package cockroach.clusterversion;
option go_package = "clusterversion";
option go_package = "github.com/cockroachdb/cockroach/pkg/clusterversion";

import "roachpb/metadata.proto";
import "gogoproto/gogo.proto";
Expand Down
2 changes: 1 addition & 1 deletion pkg/config/system.proto
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

syntax = "proto2";
package cockroach.config;
option go_package = "config";
option go_package = "github.com/cockroachdb/cockroach/pkg/config";

import "gogoproto/gogo.proto";
import "roachpb/data.proto";
Expand Down
2 changes: 1 addition & 1 deletion pkg/config/zonepb/zone.proto
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

syntax = "proto2";
package cockroach.config.zonepb;
option go_package = "zonepb";
option go_package = "github.com/cockroachdb/cockroach/pkg/config/zonepb";

import "gogoproto/gogo.proto";

Expand Down
14 changes: 5 additions & 9 deletions pkg/gen/gen.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ load(":bnf.bzl", "BNF_SRCS")
_GeneratedFileInfo = provider(
"Info needed to hoist generated files",
fields = {
"generated_files": "dictionary from prefix to list of files",
"generated_files": "dictionary from prefix (destination directory) to list of files",
"cleanup_tasks": "list of bash commands to run",
},
)
Expand All @@ -74,12 +74,7 @@ def _go_proto_srcs_impl(ctx):
generated_files = {}
for s in ctx.attr._srcs:
srcs = s[GoSource]
lbl = srcs.library.label
imp = srcs.library.importpath
imp = imp[:imp.find(lbl.package)]
prefix = "{}/{}_/{}".format(lbl.package, lbl.name, imp)
generated_files[prefix] = [f for f in srcs.srcs]

generated_files[srcs.library.label.package] = [f for f in srcs.srcs]
return [
_GeneratedFileInfo(
generated_files = generated_files,
Expand Down Expand Up @@ -146,8 +141,9 @@ def _hoist_files_impl(ctx):
if prefix not in generated_files:
generated_files[prefix] = []
for file in files:
dst = '"${{BUILD_WORKSPACE_DIRECTORY}}/{}"'.format(
file.short_path[len(prefix):],
dst = '"${{BUILD_WORKSPACE_DIRECTORY}}/{}/{}"'.format(
prefix,
file.basename,
)
src_dst_pairs.append((file.short_path, dst))
generated_files[prefix].append(file)
Expand Down
2 changes: 1 addition & 1 deletion pkg/geo/geoindex/config.proto
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

syntax = "proto3";
package cockroach.geo.geoindex;
option go_package = "geoindex";
option go_package = "github.com/cockroachdb/cockroach/pkg/geo/geoindex";

import "gogoproto/gogo.proto";

Expand Down
2 changes: 1 addition & 1 deletion pkg/geo/geopb/geopb.proto
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

syntax = "proto3";
package cockroach.geopb;
option go_package = "geopb";
option go_package = "github.com/cockroachdb/cockroach/pkg/geo/geopb";

import "gogoproto/gogo.proto";

Expand Down
2 changes: 1 addition & 1 deletion pkg/gossip/gossip.proto
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

syntax = "proto3";
package cockroach.gossip;
option go_package = "gossip";
option go_package = "github.com/cockroachdb/cockroach/pkg/gossip";

import "roachpb/data.proto";
import "util/hlc/timestamp.proto";
Expand Down
2 changes: 1 addition & 1 deletion pkg/jobs/jobspb/jobs.proto
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

syntax = "proto3";
package cockroach.sql.jobs.jobspb;
option go_package = "jobspb";
option go_package = "github.com/cockroachdb/cockroach/pkg/jobs/jobspb";

import "errorspb/errors.proto";
import "gogoproto/gogo.proto";
Expand Down
2 changes: 1 addition & 1 deletion pkg/jobs/jobspb/schedule.proto
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

syntax = "proto3";
package cockroach.jobs.jobspb;
option go_package = "jobspb";
option go_package = "github.com/cockroachdb/cockroach/pkg/jobs/jobspb";

import "google/protobuf/any.proto";

Expand Down
2 changes: 1 addition & 1 deletion pkg/keyvisualizer/keyvispb/key_visualizer.proto
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

syntax = "proto3";
package cockroach.keyvisualizer.keyvispb;
option go_package = "keyvispb";
option go_package = "github.com/cockroachdb/cockroach/pkg/keyvisualizer/keyvispb";

import "roachpb/data.proto";
import "gogoproto/gogo.proto";
Expand Down
2 changes: 1 addition & 1 deletion pkg/kv/bulk/bulkpb/bulkpb.proto
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

syntax = "proto3";
package cockroach.kv.bulk.bulkpb;
option go_package = "bulkpb";
option go_package = "github.com/cockroachdb/cockroach/pkg/kv/bulk/bulkpb";

import "gogoproto/gogo.proto";
import "util/hlc/timestamp.proto";
Expand Down
2 changes: 1 addition & 1 deletion pkg/kv/kvnemesis/operations.proto
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

syntax = "proto3";
package cockroach.kv.kvnemesis;
option go_package = "kvnemesis";
option go_package = "github.com/cockroachdb/cockroach/pkg/kv/kvnemesis";

import "errorspb/errors.proto";
import "gogoproto/gogo.proto";
Expand Down
2 changes: 1 addition & 1 deletion pkg/kv/kvpb/api.proto
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

syntax = "proto3";
package cockroach.roachpb;
option go_package = "kvpb";
option go_package = "github.com/cockroachdb/cockroach/pkg/kv/kvpb";

import "errorspb/errors.proto";
import "kv/kvserver/concurrency/lock/locking.proto";
Expand Down
2 changes: 1 addition & 1 deletion pkg/kv/kvpb/errors.proto
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ syntax = "proto2";
// correct name, the files can be moved into a newly created `kvpb` package
// at leisure.
package cockroach.kv.kvpb;
option go_package = "kvpb";
option go_package = "github.com/cockroachdb/cockroach/pkg/kv/kvpb";

import "errorspb/errors.proto";
import "roachpb/data.proto";
Expand Down
2 changes: 1 addition & 1 deletion pkg/kv/kvserver/api.proto
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

syntax = "proto3";
package cockroach.kv.kvserver;
option go_package = "kvserver";
option go_package = "github.com/cockroachdb/cockroach/pkg/kv/kvserver";

import "roachpb/data.proto";
import "storage/enginepb/mvcc.proto";
Expand Down
2 changes: 1 addition & 1 deletion pkg/kv/kvserver/closedts/ctpb/service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

syntax = "proto3";
package cockroach.kv.kvserver.ctupdate;
option go_package = "ctpb";
option go_package = "github.com/cockroachdb/cockroach/pkg/kv/kvserver/closedts/ctpb";

import "roachpb/data.proto";
import "util/hlc/timestamp.proto";
Expand Down
2 changes: 1 addition & 1 deletion pkg/kv/kvserver/concurrency/lock/lock_waiter.proto
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

syntax = "proto3";
package cockroach.kv.kvserver.concurrency.lock;
option go_package = "lock";
option go_package = "github.com/cockroachdb/cockroach/pkg/kv/kvserver/concurrency/lock";

import "kv/kvserver/concurrency/lock/locking.proto";
import "storage/enginepb/mvcc3.proto";
Expand Down
2 changes: 1 addition & 1 deletion pkg/kv/kvserver/concurrency/lock/locking.proto
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

syntax = "proto3";
package cockroach.kv.kvserver.concurrency.lock;
option go_package = "lock";
option go_package = "github.com/cockroachdb/cockroach/pkg/kv/kvserver/concurrency/lock";

import "gogoproto/gogo.proto";
import "util/hlc/timestamp.proto";
Expand Down
2 changes: 1 addition & 1 deletion pkg/kv/kvserver/concurrency/poison/error.proto
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

syntax = "proto3";
package cockroach.kv.kvserver.concurrency.poison;
option go_package = "poison";
option go_package = "github.com/cockroachdb/cockroach/pkg/kv/kvserver/concurrency/poison";

import "util/hlc/timestamp.proto";
import "roachpb/data.proto";
Expand Down
2 changes: 1 addition & 1 deletion pkg/kv/kvserver/concurrency/poison/policy.proto
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

syntax = "proto3";
package cockroach.kv.kvserver.concurrency.poison;
option go_package = "poison";
option go_package = "github.com/cockroachdb/cockroach/pkg/kv/kvserver/concurrency/poison";

// Policy determines how a request will react to encountering a poisoned
// latch. A poisoned latch is a latch for which the holder is unable to make
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

syntax = "proto3";
package cockroach.kv.kvserver.kvflowcontrol.kvflowcontrolpb;
option go_package = "kvflowcontrolpb";
option go_package = "github.com/cockroachdb/cockroach/pkg/kv/kvserver/kvflowcontrol/kvflowcontrolpb";

import "gogoproto/gogo.proto";

Expand Down
2 changes: 1 addition & 1 deletion pkg/kv/kvserver/kvserverpb/lease_status.proto
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

syntax = "proto3";
package cockroach.kv.kvserver.storagepb;
option go_package = "kvserverpb";
option go_package = "github.com/cockroachdb/cockroach/pkg/kv/kvserver/kvserverpb";

import "roachpb/data.proto";
import "kv/kvserver/liveness/livenesspb/liveness.proto";
Expand Down
2 changes: 1 addition & 1 deletion pkg/kv/kvserver/kvserverpb/proposer_kv.proto
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

syntax = "proto3";
package cockroach.kv.kvserver.storagepb;
option go_package = "kvserverpb";
option go_package = "github.com/cockroachdb/cockroach/pkg/kv/kvserver/kvserverpb";

import "kv/kvpb/api.proto";
import "roachpb/data.proto";
Expand Down
2 changes: 1 addition & 1 deletion pkg/kv/kvserver/kvserverpb/raft.proto
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

syntax = "proto3";
package cockroach.kv.kvserver.kvserverpb;
option go_package = "kvserverpb";
option go_package = "github.com/cockroachdb/cockroach/pkg/kv/kvserver/kvserverpb";

import "errorspb/errors.proto";
import "kv/kvpb/errors.proto";
Expand Down
2 changes: 1 addition & 1 deletion pkg/kv/kvserver/kvserverpb/range_log.proto
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

syntax = "proto3";
package cockroach.kv.kvserver.storagepb;
option go_package = "kvserverpb";
option go_package = "github.com/cockroachdb/cockroach/pkg/kv/kvserver/kvserverpb";

import "roachpb/metadata.proto";
import "gogoproto/gogo.proto";
Expand Down
2 changes: 1 addition & 1 deletion pkg/kv/kvserver/kvserverpb/state.proto
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

syntax = "proto3";
package cockroach.kv.kvserver.storagepb;
option go_package = "kvserverpb";
option go_package = "github.com/cockroachdb/cockroach/pkg/kv/kvserver/kvserverpb";

import "storage/enginepb/mvcc.proto";
import "roachpb/internal_raft.proto";
Expand Down
2 changes: 1 addition & 1 deletion pkg/kv/kvserver/liveness/livenesspb/liveness.proto
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

syntax = "proto3";
package cockroach.kv.kvserver.liveness.livenesspb;
option go_package = "livenesspb";
option go_package = "github.com/cockroachdb/cockroach/pkg/kv/kvserver/liveness/livenesspb";

import "util/hlc/legacy_timestamp.proto";
import "gogoproto/gogo.proto";
Expand Down
2 changes: 1 addition & 1 deletion pkg/kv/kvserver/loqrecovery/loqrecoverypb/recovery.proto
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

syntax = "proto3";
package cockroach.kv.kvserver.loqrecovery.loqrecoverypb;
option go_package = "loqrecoverypb";
option go_package = "github.com/cockroachdb/cockroach/pkg/kv/kvserver/loqrecovery/loqrecoverypb";

import "roachpb/data.proto";
import "roachpb/metadata.proto";
Expand Down
Loading

0 comments on commit d8baef9

Please sign in to comment.