Skip to content
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

Fixing import paths so generated headers work #161

Merged
merged 4 commits into from
May 24, 2024

Conversation

gregmedd
Copy link
Contributor

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 gregmedd added the bug Something isn't working label May 23, 2024
@gregmedd gregmedd self-assigned this May 23, 2024
stevenhartley pushed a commit that referenced this pull request May 23, 2024
The generated code needs to be in the `uprotocol` namespace folder structure for clarity however the protos root was the uprotocol folder so generated code was missing the uprotocol folder. This change fixes the protos and cleans up the build to still work and validate the build/changes.

#161
gregmedd pushed a commit to gregmedd/up-spec that referenced this pull request May 23, 2024
The generated code needs to be in the `uprotocol` namespace folder structure for clarity however the protos root was the uprotocol folder so generated code was missing the uprotocol folder. This change fixes the protos and cleans up the build to still work and validate the build/changes.

eclipse-uprotocol#161
@gregmedd
Copy link
Contributor Author

I've combined #162 into this PR.

gregmedd pushed a commit to gregmedd/up-spec that referenced this pull request May 23, 2024
The generated code needs to be in the `uprotocol` namespace folder structure for clarity however the protos root was the uprotocol folder so generated code was missing the uprotocol folder. This change fixes the protos and cleans up the build to still work and validate the build/changes.

eclipse-uprotocol#161
gregmedd and others added 2 commits May 23, 2024 15:05
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 eclipse-uprotocol#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.
The generated code needs to be in the `uprotocol` namespace folder structure for clarity however the protos root was the uprotocol folder so generated code was missing the uprotocol folder. This change fixes the protos and cleans up the build to still work and validate the build/changes.
Copy link
Contributor

@stevenhartley stevenhartley left a comment

Choose a reason for hiding this comment

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

Needs a fix

.github/workflows/build-github-package.yml Outdated Show resolved Hide resolved
.github/workflows/build_and_test.yml Outdated Show resolved Hide resolved
.github/workflows/build_deploy.yml Outdated Show resolved Hide resolved
.github/workflows/release.yml Outdated Show resolved Hide resolved
.github/workflows/release.yml Outdated Show resolved Hide resolved
pom.xml Outdated Show resolved Hide resolved
gregmedd and others added 2 commits May 24, 2024 09:56
Applying suggestions from review.

This parameter should not be needed when pom.xml is in the current directory.

Co-authored-by: Steven Hartley <steven@orangepeel.ca>
The --file flag is not needed since pom.xml is in the repo root now.

The proto source root was also pointing to the wrong place now that the
xml file has been moved up a directory.

Also fixing the URLs for the project/repository since they were pointing
to the old core API archive.
Copy link
Contributor

@stevenhartley stevenhartley left a comment

Choose a reason for hiding this comment

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

LGTM!

@gregmedd gregmedd merged commit aef810b into eclipse-uprotocol:main May 24, 2024
2 checks passed
@gregmedd gregmedd deleted the bugfix/proto-import-paths branch May 24, 2024 17:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants