Skip to content

Commit

Permalink
Fixing import paths so generated headers work
Browse files Browse the repository at this point in the history
The protobuf compiler uses the concept of a "canonical" path when
generating source files. This is the base point where it searches for
import files. It _expects_ that path will match the base path for
searching for headers, too. The end result is that

    import "v1/ustatus.proto"

will generate a C++ header that contains

    #include "v1/ustatus.pb.h"

while we have been explicitly asked to use includes starting with
`uprotocol` in up-cpp:

    #include "uprotocol/v1/ustatus.pb.h"

We were able to work around this with some tricks when the import paths
were file names only (e.g. `import ustatus.proto`). However, the proto
files have moved under the `v1/` directory as of #141.

Based on my reading of the protoc documentation and several stack
overflow postings, it seems the intended way for .proto files to be
written in this scenario is to import the full canonical path as
intended for the output files:

    import "uprotocol/v1/ustatus.proto"

so that protoc can generate the correct paths in output sources in the
first place.
  • Loading branch information
gregmedd committed May 23, 2024
1 parent 05fdd5d commit b9d142e
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 15 deletions.
6 changes: 3 additions & 3 deletions up-core-api/uprotocol/core/udiscovery/v3/udiscovery.proto
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ syntax = "proto3";

package uprotocol.core.udiscovery.v3;
import "google/protobuf/timestamp.proto";
import "uoptions.proto";
import "v1/uri.proto";
import "v1/ustatus.proto";
import "uprotocol/uoptions.proto";
import "uprotocol/v1/uri.proto";
import "uprotocol/v1/ustatus.proto";

option java_package = "org.eclipse.uprotocol.core.udiscovery.v3";
option java_outer_classname = "UDiscoveryProto";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ package uprotocol.core.usubscription.v3;

import "google/protobuf/any.proto";
import "google/protobuf/timestamp.proto";
import "v1/ustatus.proto";
import "v1/uri.proto";
import "uoptions.proto";
import "uprotocol/v1/ustatus.proto";
import "uprotocol/v1/uri.proto";
import "uprotocol/uoptions.proto";

option java_package = "org.eclipse.uprotocol.core.usubscription.v3";
option java_outer_classname = "USubscriptionProto";
Expand Down
8 changes: 4 additions & 4 deletions up-core-api/uprotocol/core/utwin/v2/utwin.proto
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ syntax = "proto3";

package uprotocol.core.utwin.v2;

import "uoptions.proto";
import "v1/ustatus.proto";
import "v1/uri.proto";
import "v1/umessage.proto";
import "uprotocol/uoptions.proto";
import "uprotocol/v1/ustatus.proto";
import "uprotocol/v1/uri.proto";
import "uprotocol/v1/umessage.proto";

option java_package = "org.eclipse.uprotocol.core.utwin.v2";
option java_outer_classname = "UTwinProto";
Expand Down
8 changes: 4 additions & 4 deletions up-core-api/uprotocol/v1/uattributes.proto
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ syntax = "proto3";

package uprotocol.v1;

import "v1/uri.proto";
import "v1/uuid.proto";
import "v1/ustatus.proto";
import "uoptions.proto";
import "uprotocol/v1/uri.proto";
import "uprotocol/v1/uuid.proto";
import "uprotocol/v1/ustatus.proto";
import "uprotocol/uoptions.proto";

option java_package = "org.eclipse.uprotocol.v1";
option java_outer_classname = "UAttributesProto";
Expand Down
2 changes: 1 addition & 1 deletion up-core-api/uprotocol/v1/umessage.proto
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ syntax = "proto3";

package uprotocol.v1;

import "v1/uattributes.proto";
import "uprotocol/v1/uattributes.proto";

option java_package = "org.eclipse.uprotocol.v1";
option java_outer_classname = "UMessageProto";
Expand Down

1 comment on commit b9d142e

@matthewd0123
Copy link

Choose a reason for hiding this comment

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

woo :) had opened an issue for this but then closed it since I had a workaround. Now I don't need the workaround, thanks!

Please sign in to comment.