Drvi / ProtocolBuffers.jl

4 stars 0 forks source link

Add a `always_use_modules` option to `protojl` #2

Closed Drvi closed 2 years ago

Drvi commented 2 years ago

Until now, when a proto file didn't have a package specifier, we created a simple julia script out of it, without wrapping the generated contents in a module. This PR changes that -- by default, we'll wrap these in a module which takes the same name as the generated julia file. E.g. if we translate test.proto, we get a test_pb.jl file containing a test_pb module. This will make including such files a bit safer, as they won't immediately pollute the enclosing namespace. Setting always_use_modules = false recovers the original behavior (no package specifier => no module).

For context, this is how we treat proto files that do contain package specifier. E.g. if a file test.proto contains package = foo.bar the following structure will be generated:

root  # `output_directory` arg from from `protojl`
└── foo
    ├── Foo_PB.jl  # contains module `Foo_PB`, imports `Bar_PB`
    └── bar
        └── test_pb.jl # no module, contains messages and enums...
        └── Bar_PB.jl  # contains module `Bar_PB`, includes `test_pb.jl`
codecov-commenter commented 2 years ago

Codecov Report

Merging #2 (19dbc3c) into master (c504c5d) will increase coverage by 0.45%. The diff coverage is 95.45%.

@@            Coverage Diff             @@
##           master       #2      +/-   ##
==========================================
+ Coverage   87.56%   88.01%   +0.45%     
==========================================
  Files          21       21              
  Lines        2332     2337       +5     
==========================================
+ Hits         2042     2057      +15     
+ Misses        290      280      -10     
Impacted Files Coverage Δ
src/ProtocolBuffers.jl 66.66% <ø> (ø)
src/codec/Codecs.jl 88.88% <ø> (ø)
src/codec/vbyte.jl 98.78% <ø> (-0.02%) :arrow_down:
src/codegen/names.jl 100.00% <ø> (ø)
src/codegen/types.jl 89.58% <ø> (ø)
src/lexing/Lexers.jl 90.28% <ø> (+0.31%) :arrow_up:
src/codegen/toplevel_definitions.jl 96.22% <92.30%> (+6.12%) :arrow_up:
src/codegen/modules.jl 83.33% <100.00%> (+0.63%) :arrow_up:
src/parsing/Parsers.jl 67.46% <100.00%> (+0.80%) :arrow_up:
... and 2 more

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update c504c5d...19dbc3c. Read the comment docs.