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

fix duplicate include statements #256

Closed
wants to merge 3 commits into from

Conversation

arnemohr
Copy link

@arnemohr arnemohr commented Nov 14, 2024

The issue occurs when protobuf.jl generates multiple includes for the same base proto file that's imported by several other proto files.

protos/Example
  /v1/
    base.proto      # gets imported by multiple other protos  
    feature1.proto  # imports base.proto
    feature2.proto  # also imports base.proto 
syntax = "proto3";

package Example.v1;

message Base {
  string id = 1;
  string name = 2;
}
syntax = "proto3";

package Example.v1;
import "Example/v1/base.proto";

message Feature1 {
  string id = 1;
  Example.v1.Base base = 2;
}
syntax = "proto3";

package Example.v1;
import "Example/v1/base.proto";

message Feature2 {
  string id = 1;
  Example.v1.Base base = 2;
}

After generating the sources the file v1_pb.jl contains multiple include statements

module v1

include("base_pb.jl")
include("base_pb.jl")
include("feature2_pb.jl")
include("feature1_pb.jl")

end # module v1

Copy link

codecov bot commented Nov 14, 2024

Codecov Report

Attention: Patch coverage is 96.96970% with 1 line in your changes missing coverage. Please review.

Project coverage is 92.29%. Comparing base (2e80936) to head (961a8f1).

Files with missing lines Patch % Lines
src/codegen/toplevel_definitions.jl 93.33% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #256      +/-   ##
==========================================
- Coverage   92.99%   92.29%   -0.70%     
==========================================
  Files          25       25              
  Lines        2812     2817       +5     
==========================================
- Hits         2615     2600      -15     
- Misses        197      217      +20     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.


🚨 Try these New Features:

@arnemohr arnemohr changed the title fix duplicate include statements when importing same protofiles in di… fix duplicate include statements Nov 14, 2024
@Drvi
Copy link
Member

Drvi commented Nov 18, 2024

Hi! I tried the reproducer, and maybe I'm missing something, but when I generate the Julia bindings:

protojl(
    [
        "Example/v1/base.proto",
        "Example/v1/feature1.proto",
        "Example/v1/feature2.proto",
    ],
    "protos", # protos root
    "repro",  # output dir
)

I don't see any duplicate includes:

shell> cat repro/Example/Example.jl
module Example

include("v1/v1.jl")

end # module Example

shell> cat repro/Example/v1/v1.jl
module v1

include("base_pb.jl")
include("feature1_pb.jl")
include("feature2_pb.jl")

end # module v1

Can you please share how you generated the bindings?

@arnemohr
Copy link
Author

@Drvi We went through the invocation and found the reason for the duplicates.
The search path was set to [".","./protos"] which then leads to duplicate includes. Adjusting the search path removed this issue. Nevertheless we were still able to produce the faulty behavior by using the wrong input. Maybe I will look into this someday. Will close the PR. Thx for the reply

@arnemohr arnemohr closed this Nov 19, 2024
@arnemohr arnemohr deleted the fix-duplicate-imports branch November 19, 2024 12:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants