eclipse-uprotocol / up-spec

uProtocol Specifications
Apache License 2.0
31 stars 25 forks source link

Fixing import paths so generated headers work #161

Closed gregmedd closed 3 months ago

gregmedd commented 3 months ago

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.

gregmedd commented 3 months ago

I've combined #162 into this PR.